From b556e000b25fc8d5405cba77f3eebb4152dc1497 Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Thu, 22 Feb 2024 11:22:07 +0000 Subject: [PATCH] fix(bridge-ui): fix wrong balance updates on network switch (#15980) Co-authored-by: Korbinian --- .../src/components/TokenDropdown/TokenDropdown.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte b/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte index 6bfe56424a3..b2f23933788 100644 --- a/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte +++ b/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte @@ -23,7 +23,7 @@ import { getTokenAddresses } from '$libs/token/getTokenAddresses'; import { getLogger } from '$libs/util/logger'; import { uid } from '$libs/util/uid'; - import { account } from '$stores/account'; + import { type Account, account } from '$stores/account'; import { connectedSourceChain } from '$stores/network'; import DialogView from './DialogView.svelte'; @@ -174,10 +174,11 @@ if (srcChain && destChain) updateBalance($account?.address, srcChain.id, destChain.id); }; - const onAccountChange = () => { + const onAccountChange = (newAccount: Account, prevAccount?: Account) => { const srcChain = $connectedSourceChain; const destChain = $destNetwork; - if (srcChain && destChain) updateBalance($account?.address, srcChain.id, destChain.id); + if (destChain && srcChain && (newAccount?.chainId === prevAccount?.chainId || !newAccount || !prevAccount)) + updateBalance($account?.address, srcChain.id, destChain.id); }; $: textClass = disabled ? 'text-secondary-content' : 'font-bold ';