diff --git a/package-lock.json b/package-lock.json index 0c3e88b5..5c99a8dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11354,7 +11354,7 @@ }, "packages/create-invoice-form": { "name": "@requestnetwork/create-invoice-form", - "version": "0.11.15", + "version": "0.11.16", "license": "MIT", "dependencies": { "@requestnetwork/data-format": "0.19.5", @@ -11374,7 +11374,7 @@ }, "packages/invoice-dashboard": { "name": "@requestnetwork/invoice-dashboard", - "version": "0.11.14", + "version": "0.11.15", "license": "MIT", "dependencies": { "@requestnetwork/payment-detection": "0.49.0", diff --git a/packages/create-invoice-form/package.json b/packages/create-invoice-form/package.json index 009eabda..ed5be910 100644 --- a/packages/create-invoice-form/package.json +++ b/packages/create-invoice-form/package.json @@ -1,6 +1,6 @@ { "name": "@requestnetwork/create-invoice-form", - "version": "0.11.15", + "version": "0.11.16", "main": "./dist/web-component.umd.cjs", "scripts": { "dev": "vite dev", diff --git a/packages/create-invoice-form/src/lib/create-invoice-form.svelte b/packages/create-invoice-form/src/lib/create-invoice-form.svelte index 59693696..7107659d 100644 --- a/packages/create-invoice-form/src/lib/create-invoice-form.svelte +++ b/packages/create-invoice-form/src/lib/create-invoice-form.svelte @@ -152,8 +152,11 @@ cipherProvider?.disconnectWallet(); }; - const handleWalletChange = (data: any) => { - if (data?.address) { + const handleWalletChange = (account: GetAccountReturnType, previousAccount: GetAccountReturnType) => { + if (account?.address !== previousAccount?.address) { + handleWalletDisconnection(); + handleWalletConnection(); + } else if (account?.address) { handleWalletConnection(); } else { handleWalletDisconnection(); @@ -162,10 +165,9 @@ onMount(() => { unwatchAccount = watchAccount(wagmiConfig, { - onChange(data) { + onChange(account: GetAccountReturnType, previousAccount: GetAccountReturnType) { tick().then(() => { - console.log("Wallet changed"); - handleWalletChange(data); + handleWalletChange(account, previousAccount); }); }, }); diff --git a/packages/invoice-dashboard/package.json b/packages/invoice-dashboard/package.json index e56046d5..b970e96c 100644 --- a/packages/invoice-dashboard/package.json +++ b/packages/invoice-dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@requestnetwork/invoice-dashboard", - "version": "0.11.14", + "version": "0.11.15", "main": "./dist/web-component.umd.cjs", "scripts": { "dev": "vite dev", diff --git a/packages/invoice-dashboard/src/lib/view-requests.svelte b/packages/invoice-dashboard/src/lib/view-requests.svelte index 1eb9aeb3..5c5742fe 100644 --- a/packages/invoice-dashboard/src/lib/view-requests.svelte +++ b/packages/invoice-dashboard/src/lib/view-requests.svelte @@ -119,8 +119,11 @@ cipherProvider = undefined; }; - const handleWalletChange = (data: any) => { - if (data?.address) { + const handleWalletChange = (account: GetAccountReturnType, previousAccount: GetAccountReturnType) => { + if (account?.address !== previousAccount?.address) { + handleWalletDisconnection(); + handleWalletConnection(); + } else if (account?.address) { handleWalletConnection(); } else { handleWalletDisconnection(); @@ -129,9 +132,9 @@ onMount(() => { unwatchAccount = watchAccount(wagmiConfig, { - onChange(data) { + onChange(account: GetAccountReturnType, previousAccount: GetAccountReturnType) { tick().then(() => { - handleWalletChange(data); + handleWalletChange(account, previousAccount); }); }, }); @@ -160,7 +163,7 @@ requestNetwork: RequestNetwork | undefined | null ) => { if (!account?.address || !requestNetwork) return; - + loading = true; try { const requestsData = await requestNetwork?.fromIdentity({ type: Types.Identity.TYPE.ETHEREUM_ADDRESS, @@ -171,6 +174,8 @@ .sort((a, b) => b.timestamp - a.timestamp); } catch (error) { console.error("Failed to fetch requests:", error); + } finally { + loading = false; } };