From 7c01bbc8b24215ece853ec5339f79eac17c8476b Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Fri, 24 Mar 2023 13:24:15 -0700 Subject: [PATCH] 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))