From 4ebd7e7cd148ad8adb802f928d857ea18b58cefd Mon Sep 17 00:00:00 2001 From: Korbinian Date: Sat, 28 Oct 2023 21:13:52 +0200 Subject: [PATCH] fix conditions --- .../src/components/Bridge/Actions.svelte | 19 +++++++++++-------- .../src/components/Bridge/Amount.svelte | 1 - .../src/components/Bridge/NFTBridge.svelte | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/bridge-ui-v2/src/components/Bridge/Actions.svelte b/packages/bridge-ui-v2/src/components/Bridge/Actions.svelte index 4e603fe8d50..97aa45b0057 100644 --- a/packages/bridge-ui-v2/src/components/Bridge/Actions.svelte +++ b/packages/bridge-ui-v2/src/components/Bridge/Actions.svelte @@ -49,6 +49,7 @@ //TODO: this should probably be checked somewhere else? export async function checkTokensApproved() { + $validatingAmount = true; if ($selectedToken?.type === TokenType.ERC721 || $selectedToken?.type === TokenType.ERC1155) { if ($account?.address && $network?.id && $destNetwork?.id) { const currentChainId = $network?.id; @@ -102,6 +103,7 @@ } } } + $validatingAmount = false; } // TODO: feels like we need a state machine here @@ -119,7 +121,7 @@ ? $tokenBalance.value > BigInt(0) : false // ERC20 : false); - $: canDoNothing = !hasAddress || !hasNetworks || !hasBalance || !$selectedToken || !$enteredAmount; + $: canDoNothing = !hasAddress || !hasNetworks || !hasBalance || !$selectedToken; // Conditions for approve/bridge steps $: isSelectedERC20 = $selectedToken && $selectedToken.type === TokenType.ERC20; @@ -140,7 +142,7 @@ // Conditions to disable/enable buttons $: disableApprove = $selectedToken?.type === TokenType.ERC20 - ? canDoNothing || $insufficientBalance || $validatingAmount || approving || isTokenApproved + ? canDoNothing || $insufficientBalance || $validatingAmount || approving || isTokenApproved || !$enteredAmount : $selectedToken?.type === TokenType.ERC721 ? allTokensApproved || approving : $selectedToken?.type === TokenType.ERC1155 @@ -161,10 +163,10 @@ !$validatingAmount && !$insufficientBalance; - $: erc20ConditionsSatisfied = !canDoNothing && !$insufficientAllowance && commonConditions && $tokenBalance; - $: erc721ConditionsSatisfied = - allTokensApproved && commonConditions && typeof $tokenBalance === 'bigint' && $tokenBalance && $tokenBalance > 0; - $: erc1155ConditionsSatisfied = allTokensApproved && commonConditions; + $: erc20ConditionsSatisfied = + !canDoNothing && !$insufficientAllowance && commonConditions && $tokenBalance && $enteredAmount; + $: erc721ConditionsSatisfied = allTokensApproved && commonConditions; + $: erc1155ConditionsSatisfied = allTokensApproved && $enteredAmount && $enteredAmount > 0 && commonConditions; $: ethConditionsSatisfied = commonConditions && $enteredAmount && $enteredAmount > 0; $: disableBridge = isERC20 @@ -178,7 +180,6 @@ : commonConditions; - +tokenBalance {$tokenBalance}
+enteredAmount {#if $enteredAmount}test +{/if}
{#if $selectedToken && $selectedToken.type !== TokenType.ETH}