From e5dd659f3368ba83cb2a5e178adf5151ab151a9c Mon Sep 17 00:00:00 2001 From: dafuga Date: Thu, 23 Nov 2023 17:45:10 -0800 Subject: [PATCH] fix: handling the case where chain swapping happens right after transfer --- src/components/layout/account/sidebar.svelte | 4 +++- src/pages/transfer/form.svelte | 18 ++++++++++++------ src/pages/transfer/success.svelte | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/layout/account/sidebar.svelte b/src/components/layout/account/sidebar.svelte index aa2a47ed..a0357624 100644 --- a/src/components/layout/account/sidebar.svelte +++ b/src/components/layout/account/sidebar.svelte @@ -12,7 +12,9 @@ function onSelect(session: SessionLike) { activate(session).then(() => { - fetchBalances($activeSession!) + setTimeout(() => { + fetchBalances($activeSession!, true) + }, 1000) }) open = false } diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte index 8f5a2eea..1903fe8b 100644 --- a/src/pages/transfer/form.svelte +++ b/src/pages/transfer/form.svelte @@ -72,6 +72,8 @@ fromOptions = [] + const fromOptionsBeingSet: Token[] = [] + await Promise.all( Object.values(transferManagers).map(async (transferManagerData) => { const TransferManagerClass = transferManagerData.transferClass @@ -98,10 +100,12 @@ return } - fromOptions.push(token) + fromOptionsBeingSet.push(token) }) ) + fromOptions = [...fromOptionsBeingSet] + generatingOptions = false } @@ -116,11 +120,13 @@ } $: { - const fromInOptions = fromOptions.find( - (token) => from?.symbol.equals(token.symbol) && token.name !== from?.name - ) - if (!fromInOptions) { - toOptions = [] + if (from) { + const fromInOptions = fromOptions.find( + (token) => from?.symbol.equals(token.symbol) && token.name !== from?.name + ) + if (!fromInOptions) { + toOptions = [] + } } } diff --git a/src/pages/transfer/success.svelte b/src/pages/transfer/success.svelte index 0f8b03ed..5d2db4f6 100644 --- a/src/pages/transfer/success.svelte +++ b/src/pages/transfer/success.svelte @@ -8,6 +8,7 @@ import type {TransferManager} from './managers/transferManager' import {updateBalances} from '~/stores/balances-provider' import {activeSession} from '~/store' + import { get } from 'svelte/store' export let transferManager: TransferManager export let transactResult: TransactResult | ethers.providers.TransactionResponse @@ -41,9 +42,10 @@ ) { clearInterval(refreshInterval) } + // Fetch the balances - updateBalances($activeSession!) - }, 1000) + updateBalances(get(activeSession)!) + }, 2000) // Timeout after 30 seconds setTimeout(() => {