From 1468f539a0021368d4e9e541caa37138419c7d80 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Fri, 24 Mar 2023 13:20:03 -0700 Subject: [PATCH 1/2] didnt await the promise --- packages/bridge-ui/src/components/Transaction.svelte | 4 ++-- packages/bridge-ui/src/components/form/BridgeForm.svelte | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/components/Transaction.svelte b/packages/bridge-ui/src/components/Transaction.svelte index 10b1b205d70..00135090699 100644 --- a/packages/bridge-ui/src/components/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transaction.svelte @@ -79,7 +79,7 @@ } // confirm after switch chain that it worked. - if (!isOnCorrectChain($signer, bridgeTx.toChainId)) { + if (!(await isOnCorrectChain($signer, bridgeTx.toChainId))) { errorToast('You are connected to the wrong chain in your wallet'); return; } @@ -128,7 +128,7 @@ } // confirm after switch chain that it worked. - if (!isOnCorrectChain($signer, bridgeTx.fromChainId)) { + if (!(await isOnCorrectChain($signer, bridgeTx.fromChainId))) { errorToast('You are connected to the wrong chain in your wallet'); return; } diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index add1a6502e9..f3dfef08673 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -218,7 +218,7 @@ throw Error('Invalid custom recipient address'); } - if (!isOnCorrectChain($signer, $fromChain.id)) { + if (!(await isOnCorrectChain($signer, $fromChain.id))) { errorToast('You are connected to the wrong chain in your wallet'); return; } From 7c01bbc8b24215ece853ec5339f79eac17c8476b Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Fri, 24 Mar 2023 13:24:15 -0700 Subject: [PATCH 2/2] forgot to await promise fml, plus additional checks, btnDisabled was throwing error and broken --- .../src/components/form/BridgeForm.svelte | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index f3dfef08673..241d70b61b6 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -123,20 +123,24 @@ return allowance; } - function isBtnDisabled( + async function isBtnDisabled( signer: Signer, amount: string, token: Token, tokenBalance: string, requiresAllowance: boolean, memoError: string, + fromChain: Chain, ) { if (!signer) return true; if (!tokenBalance) return true; - - const chainId = $fromChain.id; + if (!fromChain) return true; + const chainId = fromChain.id; if (!chainId || !chains[chainId.toString()]) return true; + + if (!(await isOnCorrectChain(signer, fromChain.id))) return true; + if (!amount || ethers.utils.parseUnits(amount).eq(BigNumber.from(0))) return true; if (isNaN(parseFloat(amount))) return true; @@ -373,14 +377,17 @@ $: getUserBalance($signer, $token, $fromChain); - $: btnDisabled = isBtnDisabled( + $: isBtnDisabled( $signer, amount, $token, tokenBalance, requiresAllowance, memoError, - ); + $fromChain, + ) + .then((d) => (btnDisabled = d)) + .catch((e) => console.error(e)); $: checkAllowance(amount, $token, $bridgeType, $fromChain, $signer) .then((a) => (requiresAllowance = a))