Skip to content

Commit

Permalink
feat(bridge-ui-v2): NFT bridging (#14949)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Oct 16, 2023
1 parent 0d1dd42 commit 36c5ccd
Show file tree
Hide file tree
Showing 22 changed files with 1,200 additions and 316 deletions.
13 changes: 9 additions & 4 deletions packages/bridge-ui-v2/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export const recommentProcessingFee = {
ethGasLimit: BigInt(900_000),
erc20NotDeployedGasLimit: BigInt(3_100_000),
erc20DeployedGasLimit: BigInt(1_100_000),
erc721NotDeployedGasLimit: BigInt(3_400_000),
erc721NotDeployedGasLimit: BigInt(2_400_000),
erc721DeployedGasLimit: BigInt(1_100_000),
erc1155NotDeployedGasLimit: BigInt(4_000_000),
erc1155NotDeployedGasLimit: BigInt(2_600_000),
erc1155DeployedGasLimit: BigInt(1_100_000),
};

Expand All @@ -15,9 +15,14 @@ export const processingFeeComponent = {

export const bridgeService = {
noOwnerGasLimit: BigInt(140_000),
noTokenDeployedGasLimit: BigInt(3_000_000),
noERC20TokenDeployedGasLimit: BigInt(3_000_000),
erc20GasLimitThreshold: BigInt(2_500_000),
unpredictableGasLimit: BigInt(1_000_000),

noERC721TokenDeployedGasLimit: BigInt(2_400_000),
erc721GasLimitThreshold: BigInt(3_000_000),

noERC1155TokenDeployedGasLimit: BigInt(2_600_000),
erc1155GasLimitThreshold: BigInt(3_000_000),
};

export const pendingTransaction = {
Expand Down
38 changes: 30 additions & 8 deletions packages/bridge-ui-v2/src/components/Bridge/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Button } from '$components/Button';
import { Icon } from '$components/Icon';
import { TokenType } from '$libs/token';
import { type NFT, TokenType } from '$libs/token';
import { account, network } from '$stores';
import {
Expand All @@ -13,6 +13,7 @@
errorComputingBalance,
insufficientAllowance,
insufficientBalance,
notApproved,
recipientAddress,
selectedToken,
tokenBalance,
Expand Down Expand Up @@ -50,18 +51,40 @@
// Conditions for approve/bridge steps
$: isSelectedERC20 = $selectedToken && $selectedToken.type === TokenType.ERC20;
$: isTokenApproved = isSelectedERC20 && $enteredAmount && !$insufficientAllowance && !$validatingAmount;
$: isTokenApproved =
$selectedToken?.type === TokenType.ERC20
? isSelectedERC20 && $enteredAmount && !$insufficientAllowance && !$validatingAmount
: $selectedToken?.type === TokenType.ERC721 || $selectedToken?.type === TokenType.ERC1155
? allTokensApproved
: false;
// Check if all NFTs are approved
$: allTokensApproved =
$selectedToken?.type === TokenType.ERC721 || $selectedToken?.type === TokenType.ERC1155
? $notApproved.get(($selectedToken as NFT).tokenId)
: false;
// Conditions to disable/enable buttons
$: disableApprove = canDoNothing || !$insufficientAllowance || $validatingAmount || approving;
$: disableBridge = canDoNothing || $insufficientAllowance || $insufficientBalance || $validatingAmount || bridging;
$: disableApprove =
$selectedToken?.type === TokenType.ERC20
? canDoNothing || $insufficientBalance || $validatingAmount || approving || isTokenApproved
: $selectedToken?.type === TokenType.ERC721
? allTokensApproved || approving
: $selectedToken?.type === TokenType.ERC1155
? allTokensApproved || approving
: approving;
// General loading state
// $: loading = approving || bridging;
$: disableBridge =
$selectedToken?.type === TokenType.ERC20
? canDoNothing || $insufficientAllowance || $insufficientBalance || $validatingAmount || bridging
: $selectedToken?.type === TokenType.ERC721 || $selectedToken?.type === TokenType.ERC1155
? !allTokensApproved
: bridging || !hasAddress || !hasNetworks || !hasBalance || !$selectedToken || !$enteredAmount;
</script>

<div class="f-between-center w-full gap-4">
{#if isSelectedERC20}
{#if $selectedToken && $selectedToken.type !== TokenType.ETH}
<Button
type="primary"
class="px-[28px] py-[14px] rounded-full flex-1"
Expand All @@ -81,7 +104,6 @@
</Button>
<Icon type="arrow-right" />
{/if}

<Button
type="primary"
class="px-[28px] py-[14px] rounded-full flex-1 text-white"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum AddressInputState {
Default = 'default',
Valid = 'valid',
Invalid = 'invalid',
TooShort = 'too_short',
Validating = 'validating',
Default,
Valid,
Invalid,
TooShort,
Validating,
}

1 comment on commit 36c5ccd

@vercel
Copy link

@vercel vercel bot commented on 36c5ccd Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal-taikoxyz.vercel.app
bridge-ui-v2-internal.vercel.app
bridge-ui-v2-internal-git-main-taikoxyz.vercel.app

Please sign in to comment.