Skip to content

Commit

Permalink
fix conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Oct 28, 2023
1 parent 38b6f51 commit 4ebd7e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions packages/bridge-ui-v2/src/components/Bridge/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +103,7 @@
}
}
}
$validatingAmount = false;
}
// TODO: feels like we need a state machine here
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -178,7 +180,6 @@
: commonConditions;
</script>

<!--
bridging {bridging}<br />
balance {hasBalance}<br />
validating {$validatingAmount}<br />
Expand All @@ -188,7 +189,9 @@ canDoNothing {canDoNothing} <br />
$insufficientAllowance {insufficientAllowance} <br />
commonConditions {commonConditions}
enteredAmount {$enteredAmount}<br />
tokenBalance {$tokenBalance}<br /> -->
tokenBalance {$tokenBalance}<br />
enteredAmount {#if $enteredAmount}test
{/if}<br />
<div class="f-between-center w-full gap-4">
{#if $selectedToken && $selectedToken.type !== TokenType.ETH}
<Button
Expand Down
1 change: 0 additions & 1 deletion packages/bridge-ui-v2/src/components/Bridge/Amount.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
// $: showInsiffucientAllowanceAlert = $insufficientAllowance && !$errorComputingBalance && !$computingBalance;
</script>

{$enteredAmount}
<div class="Amount f-col space-y-2">
<div class="f-between-center text-secondary-content">
<label class="body-regular" for={inputId}>{$t('inputs.amount.label')}</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
-->
{#if activeStep === NFTSteps.REVIEW}
<div class="f-col w-full gap-4">
<Actions {approve} {bridge} />
<Actions bind:this={actionsComponent} {approve} {bridge} />
<button on:click={previousStep} class="flex justify-center py-3 link">
{$t('common.back')}
</button>
Expand Down

0 comments on commit 4ebd7e7

Please sign in to comment.