From a091bc05bd64f0a0c9a930e4fe296adf363a7233 Mon Sep 17 00:00:00 2001 From: shadab-taiko <108871478+shadab-taiko@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:31:26 +0530 Subject: [PATCH] fix(bridge): multiple message processed toasts (#8186) --- packages/bridge-ui/src/App.svelte | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index 88f0dacfb5d..4eedd15104b 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -157,16 +157,29 @@ }); }); + const transactionToIntervalMap = new Map(); + transactions.subscribe((store) => { if (store) { store.forEach(async (tx) => { - if (tx.interval) clearInterval(tx.interval); + const txInterval = transactionToIntervalMap.get(tx.ethersTx.hash); + if (txInterval) { + clearInterval(txInterval); + transactionToIntervalMap.delete(tx.ethersTx.hash); + } if (tx.status === MessageStatus.New) { const provider = providerMap.get(tx.toChainId); + const interval = setInterval(async () => { - tx.interval = interval; + const txInterval = transactionToIntervalMap.get(tx.ethersTx.hash); + if (txInterval !== interval) { + clearInterval(txInterval); + transactionToIntervalMap.delete(tx.ethersTx.hash); + } + + transactionToIntervalMap.set(tx.ethersTx.hash, interval); if (!tx.signal) return; const contract = new ethers.Contract( @@ -180,7 +193,9 @@ if (messageStatus === MessageStatus.Done) { successToast("Bridge message processed successfully"); - clearInterval(tx.interval); + const txOngoingInterval = transactionToIntervalMap.get(tx.ethersTx.hash); + clearInterval(txOngoingInterval); + transactionToIntervalMap.delete(tx.ethersTx.hash); } }, 20 * 1000); }