diff --git a/packages/bridge-ui-v2/src/components/Bridge/AddressInput.svelte b/packages/bridge-ui-v2/src/components/Bridge/AddressInput.svelte index be417f388d9..7e9aab6a3da 100644 --- a/packages/bridge-ui-v2/src/components/Bridge/AddressInput.svelte +++ b/packages/bridge-ui-v2/src/components/Bridge/AddressInput.svelte @@ -8,6 +8,9 @@ import { Icon } from '$components/Icon'; import { uid } from '$libs/util/uid'; + export let ethereumAddress: Address | string = ''; + export let labelText = $t('inputs.address_input.label'); + enum State { Valid = 'valid', Invalid = 'invalid', @@ -18,8 +21,6 @@ let inputId = `input-${uid()}`; let state: State; - export let ethereumAddress: Address | string = ''; - const dispatch = createEventDispatcher(); const validateEthereumAddress = (address: string | EventTarget | null) => { @@ -60,7 +61,7 @@
- +
+ import { onDestroy } from 'svelte'; import { t } from 'svelte-i18n'; - import { TransactionExecutionError, UserRejectedRequestError } from 'viem'; + import { type Address, TransactionExecutionError, UserRejectedRequestError } from 'viem'; import { routingContractsMap } from '$bridgeConfig'; import { chainConfig } from '$chainConfig'; @@ -40,7 +41,9 @@ import { pendingTransactions } from '$stores/pendingTransactions'; import Actions from './Actions.svelte'; + import AddressInput from './AddressInput.svelte'; import Amount from './Amount.svelte'; + import IdInput from './IDInput.svelte'; import { ProcessingFee } from './ProcessingFee'; import Recipient from './Recipient.svelte'; import { @@ -54,7 +57,6 @@ } from './state'; import { BridgeTypes, NFTSteps } from './types'; - let activeStep: NFTSteps = NFTSteps.IMPORT; let amountComponent: Amount; let recipientComponent: Recipient; let processingFeeComponent: ProcessingFee; @@ -270,13 +272,8 @@ bridgeTxService.addTxByAddress($account.address, bridgeTx); - // Reset the form (we check if these are still mounted, as the user might have left the page) - if (amountComponent) amountComponent.clearAmount(); - if (recipientComponent) recipientComponent.clearRecipient(); - if (processingFeeComponent) processingFeeComponent.resetProcessingFee(); - - // Update balance after bridging - if (amountComponent) amountComponent.updateBalance(); + // Reset the form + resetForm(); // Refresh user's balance refreshUserBalance(); @@ -309,11 +306,42 @@ } } + $: if ($selectedToken && amountComponent) { + amountComponent.validateAmount(); + } + + const resetForm = () => { + //we check if these are still mounted, as the user might have left the page + if (amountComponent) amountComponent.clearAmount(); + if (recipientComponent) recipientComponent.clearRecipient(); + if (processingFeeComponent) processingFeeComponent.resetProcessingFee(); + if (addressInputComponent) addressInputComponent.clear(); + + // Update balance after bridging + if (amountComponent) amountComponent.updateBalance(); + }; + + // NFT Bridge logic + let activeStep: NFTSteps = NFTSteps.IMPORT; + const nextStep = () => (activeStep = Math.min(activeStep + 1, NFTSteps.CONFIRM)); - const back = () => (activeStep = Math.max(activeStep - 1, NFTSteps.IMPORT)); + const previousStep = () => (activeStep = Math.max(activeStep - 1, NFTSteps.IMPORT)); let nftStepTitle: string; let nftStepDescription: string; + let nftIdArray: number[] = []; + let invalidAddress = false; + let addressInputComponent: AddressInput; + + function onAddressValidation(event: CustomEvent<{ isValidEthereumAddress: boolean; addr: Address }>) { + const { isValidEthereumAddress, addr } = event.detail; + if (isValidEthereumAddress) { + $recipientAddress = addr; + invalidAddress = false; + } else { + invalidAddress = true; + } + } $: { const stepKey = NFTSteps[activeStep].toLowerCase(); // Convert enum to string and to lowercase @@ -321,9 +349,11 @@ nftStepDescription = $t(`bridge.description.nft.${stepKey}`); } - $: if ($selectedToken && amountComponent) { - amountComponent.validateAmount(); - } + $: ethereumAddressBinding = $recipientAddress || undefined; + + onDestroy(() => { + resetForm(); + }); {#if $activeBridge === BridgeTypes.FUNGIBLE} @@ -361,13 +391,40 @@ -
- - -
-
+
+ {#if activeStep === NFTSteps.IMPORT} +
+ +
+ + + + + {:else if activeStep === NFTSteps.REVIEW} +
+ +
+ {:else if activeStep === NFTSteps.CONFIRM} +
+ +
+ {/if} + {nftIdArray} +
+
+ + +
+
{/if} diff --git a/packages/bridge-ui-v2/src/components/Bridge/BridgeTabs.svelte b/packages/bridge-ui-v2/src/components/Bridge/BridgeTabs.svelte index 9a8115cc7bb..7393d4e512c 100644 --- a/packages/bridge-ui-v2/src/components/Bridge/BridgeTabs.svelte +++ b/packages/bridge-ui-v2/src/components/Bridge/BridgeTabs.svelte @@ -20,13 +20,17 @@ {#if PUBLIC_NFT_BRIDGE_ENABLED === 'true'}
diff --git a/packages/bridge-ui-v2/src/components/Bridge/IDInput.svelte b/packages/bridge-ui-v2/src/components/Bridge/IDInput.svelte new file mode 100644 index 00000000000..a4da115a985 --- /dev/null +++ b/packages/bridge-ui-v2/src/components/Bridge/IDInput.svelte @@ -0,0 +1,73 @@ + + +
+
+ +
+
+ + +
+
+ +
+ {#if state === State.Invalid && value !== ''} + + {:else if state === State.Valid} + + {/if} +