Skip to content

Commit

Permalink
fix(bridge-ui): balance visually not updating correctly when switchin…
Browse files Browse the repository at this point in the history
…g chains (#17832)
  • Loading branch information
KorbinianK committed Jul 23, 2024
1 parent 8d95c83 commit f495e40
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import { debounce } from '$libs/util/debounce';
import { getLogger } from '$libs/util/logger';
import { truncateDecimal } from '$libs/util/truncateDecimal';
import { account } from '$stores/account';
import { type Account, account } from '$stores/account';
import { ethBalance } from '$stores/balance';
import { connectedSourceChain } from '$stores/network';
import type { TokenInfo } from '$stores/tokenInfo';
Expand Down Expand Up @@ -126,11 +126,13 @@
if ($account && $account.address && $account?.isConnected && $selectedToken) {
validateAmount($selectedToken);
refreshUserBalance();
log('fetching on chain', $connectedSourceChain?.name);
$tokenBalance = await fetchBalance({
userAddress: $account.address,
token: $selectedToken,
srcChainId: $connectedSourceChain?.id,
});
log('tokenBalance', $tokenBalance);
previousSelectedToken = $selectedToken;
} else {
balance = '0.00';
Expand Down Expand Up @@ -259,6 +261,21 @@
const token = $selectedToken;
if (!user || !token) return;
});
const onAccountChange = async (newAccount: Account, oldAccount?: Account) => {
log('onAccountChange', newAccount, oldAccount);
if (newAccount?.isConnected && newAccount.address && newAccount.address !== oldAccount?.address) {
log('resetting input');
reset();
} else if (newAccount.address && newAccount?.isConnected && $selectedToken) {
log('refreshing user balance', $connectedSourceChain?.name);
$tokenBalance = await fetchBalance({
userAddress: newAccount.address,
token: $selectedToken,
srcChainId: newAccount.chainId,
});
}
};
</script>

<div class="TokenInput space-y-[8px]">
Expand Down Expand Up @@ -325,7 +342,7 @@
</div>
</div>

<OnAccount change={reset} />
<OnAccount change={onAccountChange} />

<style>
.max-button {
Expand Down

0 comments on commit f495e40

Please sign in to comment.