From 028e7eae7699931453cc7803d5e51000b89fec8f Mon Sep 17 00:00:00 2001 From: Korbinian Date: Wed, 5 Jun 2024 12:44:22 +0200 Subject: [PATCH] block review step if funds too low --- .../bridge-ui/src/components/Alert/Alert.svelte | 2 +- .../src/components/Bridge/FungibleBridge.svelte | 5 ++++- .../ReviewStep/ReviewStep.svelte | 15 +++++++++++++-- .../StepNavigation/StepNavigation.svelte | 6 +++++- packages/bridge-ui/src/i18n/en.json | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/bridge-ui/src/components/Alert/Alert.svelte b/packages/bridge-ui/src/components/Alert/Alert.svelte index 13844da0cd9..7586b6cb2f5 100644 --- a/packages/bridge-ui/src/components/Alert/Alert.svelte +++ b/packages/bridge-ui/src/components/Alert/Alert.svelte @@ -23,7 +23,7 @@ iconFillClass: 'fill-warning-content', }, error: { - alertClass: 'alert-danger', + alertClass: 'alert-error', iconType: 'x-close-circle', iconFillClass: 'fill-error-content', }, diff --git a/packages/bridge-ui/src/components/Bridge/FungibleBridge.svelte b/packages/bridge-ui/src/components/Bridge/FungibleBridge.svelte index c89c0979383..346d036eea8 100644 --- a/packages/bridge-ui/src/components/Bridge/FungibleBridge.svelte +++ b/packages/bridge-ui/src/components/Bridge/FungibleBridge.svelte @@ -19,6 +19,7 @@ let stepDescription: string; let hasEnoughEth: boolean = false; + let hasEnoughFundsToContinue: boolean = false; let exceedsQuota: boolean = false; let bridgingStatus: BridgingStatus; let needsManualReviewConfirmation: boolean; @@ -58,7 +59,8 @@ on:editTransactionDetails={handleTransactionDetailsClick} on:goBack={handleBackClick} bind:needsManualReviewConfirmation - bind:hasEnoughEth /> + bind:hasEnoughEth + bind:hasEnoughFundsToContinue /> {:else if activeStep === BridgeSteps.RECIPIENT} @@ -70,6 +72,7 @@ diff --git a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ReviewStep/ReviewStep.svelte b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ReviewStep/ReviewStep.svelte index cbbb8fa2f46..2a9f62feb4d 100644 --- a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ReviewStep/ReviewStep.svelte +++ b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ReviewStep/ReviewStep.svelte @@ -6,15 +6,17 @@ import { chainConfig } from '$chainConfig'; import { Alert } from '$components/Alert'; import { ProcessingFee, Recipient } from '$components/Bridge/SharedBridgeComponents'; - import { destNetwork as destChain, enteredAmount, selectedToken } from '$components/Bridge/state'; + import { destNetwork as destChain, enteredAmount, processingFee, selectedToken } from '$components/Bridge/state'; import { PUBLIC_SLOW_L1_BRIDGING_WARNING } from '$env/static/public'; import { LayerType } from '$libs/chain'; import { isStablecoin, isSupported, isWrapped, type Token } from '$libs/token'; import { isToken } from '$libs/token/isToken'; + import { ethBalance } from '$stores/balance'; import { connectedSourceChain } from '$stores/network'; export let hasEnoughEth: boolean = false; export let needsManualReviewConfirmation = false; + export let hasEnoughFundsToContinue: boolean = false; let recipientComponent: Recipient; let processingFeeComponent: ProcessingFee; @@ -38,6 +40,12 @@ needsManualReviewConfirmation = false; } + $: if ($processingFee + $enteredAmount > $ethBalance || !hasEnoughEth) { + hasEnoughFundsToContinue = false; + } else { + hasEnoughFundsToContinue = true; + } + const dispatch = createEventDispatcher(); const editTransactionDetails = () => { @@ -85,6 +93,7 @@ +
{$t('bridge.nft.step.review.recipient_details')}
@@ -95,7 +104,9 @@ Recipient & Processing Fee
- +{#if !hasEnoughFundsToContinue} + {$t('bridge.alerts.not_enough_funds')} +{/if} {#if wrapped} {@html wrappedAssetWarning} diff --git a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/StepNavigation/StepNavigation.svelte b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/StepNavigation/StepNavigation.svelte index 2df6ee5c4bf..b81a7285e0d 100644 --- a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/StepNavigation/StepNavigation.svelte +++ b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/StepNavigation/StepNavigation.svelte @@ -11,6 +11,7 @@ export let activeStep: BridgeSteps = BridgeSteps.IMPORT; export let validatingImport = false; + export let hasEnoughFundsToContinue: boolean; export let needsManualReviewConfirmation: boolean; export let needsManualRecipientConfirmation: boolean; export let bridgingStatus: BridgingStatus; @@ -100,7 +101,10 @@ {/if} - handleNextStep()}> + handleNextStep()}> {nextStepButtonText} diff --git a/packages/bridge-ui/src/i18n/en.json b/packages/bridge-ui/src/i18n/en.json index 564fb717fa9..59889ac3195 100644 --- a/packages/bridge-ui/src/i18n/en.json +++ b/packages/bridge-ui/src/i18n/en.json @@ -39,6 +39,7 @@ "nft_scan_again": "Scan again" }, "alerts": { + "not_enough_funds": "You do not have enough funds to cover the processing fee and transaction fee", "slow_bridging": "Please note: Bridging to L1 will take around 24hrs!", "smart_contract_wallet": "It seems you are using a smart contract wallet. Please double check that the recipient matches your wallet on the destination or change it accordingly.", "stable_coin": "You are bridging a stable coin. For USDC, we are currently partnering with Stargate Bridge for liquidity. Consider using their bridge, as the ecosystem partners are likely using their bridged version",