From 6c49689cbd1d8ebe987cbc8401fda817246527b6 Mon Sep 17 00:00:00 2001 From: Bartek Date: Mon, 2 Sep 2024 15:30:48 +0200 Subject: [PATCH 1/4] feat: new amount input design (#1860) --- .../components/TransferPanel/TokenButton.tsx | 8 +- .../DestinationNetworkBox.tsx | 174 +++++++++--------- .../TransferPanelMain/SourceNetworkBox.tsx | 90 ++------- .../TransferPanel/TransferPanelMainInput.tsx | 142 +++++++++++--- .../TransferPanel/useTransferReadiness.ts | 25 ++- .../useTransferReadinessUtils.ts | 26 ++- .../src/components/common/atoms/Loader.tsx | 10 +- .../tests/e2e/cypress.d.ts | 2 + .../tests/e2e/specs/login.cy.ts | 2 +- .../tests/e2e/specs/urlQueryParam.cy.ts | 41 ++--- .../tests/support/commands.ts | 7 +- 11 files changed, 304 insertions(+), 223 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx index c090e311a3..eaa43c8007 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TokenButton.tsx @@ -57,7 +57,7 @@ export function TokenButton({ {({ open }) => ( <> )} */} - - {tokenSymbol} - + {tokenSymbol} {!disabled && ( + + {/* In deposit mode, when user selected USDC on mainnet, + the UI shows the Arb One balance of both USDC.e and native USDC */} + {showUsdcSpecificInfo && isDepositMode && ( + + )} + + ) + } + + if (nativeCurrency.isCustom) { + return ( + + ) + } + + return ( + + ) +} + +export function DestinationNetworkBox({ + customFeeTokenBalances, + showUsdcSpecificInfo +}: { + customFeeTokenBalances: Balances + showUsdcSpecificInfo: boolean +}) { + const { address: walletAddress } = useAccount() + const [networks] = useNetworks() const { destinationAddress } = useDestinationAddressStore() const destinationAddressOrWalletAddress = destinationAddress || walletAddress const [ @@ -58,7 +136,6 @@ export function DestinationNetworkBox({ return ( <> @@ -70,87 +147,10 @@ export function DestinationNetworkBox({ {destinationAddressOrWalletAddress && utils.isAddress(destinationAddressOrWalletAddress) && ( - <> - - {/* In deposit mode, when user selected USDC on mainnet, - the UI shows the Arb One balance of both USDC.e and native USDC */} - {isDepositMode && showUsdcSpecificInfo && ( - - )} - {nativeCurrency.isCustom ? ( - <> - - {!isDepositMode && ( - - )} - - ) : ( - - )} - + )} diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx index cf0ba5a22a..b41ba30d1c 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/SourceNetworkBox.tsx @@ -1,27 +1,17 @@ import { ChangeEventHandler, useCallback, useEffect, useMemo } from 'react' +import { utils } from 'ethers' import { getNetworkName } from '../../../util/networks' import { NetworkButton, NetworkSelectionContainer } from '../../common/NetworkSelectionContainer' -import { - BalancesContainer, - ETHBalance, - NetworkContainer, - NetworkListboxPlusBalancesContainer -} from '../TransferPanelMain' -import { TokenBalance } from './TokenBalance' -import { NetworkType } from './utils' +import { NetworkContainer } from '../TransferPanelMain' import { useAppState } from '../../../state' import { useNetworks } from '../../../hooks/useNetworks' import { useNativeCurrency } from '../../../hooks/useNativeCurrency' import { useNetworksRelationship } from '../../../hooks/useNetworksRelationship' -import { - Balances, - useSelectedTokenBalances -} from '../../../hooks/TransferPanel/useSelectedTokenBalances' -import { useBalances } from '../../../hooks/useBalances' +import { Balances } from '../../../hooks/TransferPanel/useSelectedTokenBalances' import { ETH_BALANCE_ARTICLE_LINK, USDC_LEARN_MORE_LINK @@ -39,6 +29,7 @@ import { useDialog } from '../../common/Dialog' import { useTransferReadiness } from '../useTransferReadiness' import { useIsBatchTransferSupported } from '../../../hooks/TransferPanel/useIsBatchTransferSupported' import { useSelectedTokenDecimals } from '../../../hooks/TransferPanel/useSelectedTokenDecimals' +import { useBalanceOnSourceChain } from '../../../hooks/useBalanceOnSourceChain' export function SourceNetworkBox({ customFeeTokenBalances, @@ -53,8 +44,6 @@ export function SourceNetworkBox({ const { app: { selectedToken } } = useAppState() - const { ethParentBalance, ethChildBalance } = useBalances() - const selectedTokenBalances = useSelectedTokenBalances() const nativeCurrency = useNativeCurrency({ provider: childChainProvider }) const [{ amount, amount2 }] = useArbQueryParams() const { setAmount, setAmount2 } = useSetInputAmount() @@ -66,6 +55,7 @@ export function SourceNetworkBox({ const isBatchTransferSupported = useIsBatchTransferSupported() const decimals = useSelectedTokenDecimals() const { errorMessages } = useTransferReadiness() + const ethBalanceSourceChain = useBalanceOnSourceChain(null) const isMaxAmount = amount === AmountQueryParamEnum.MAX const isMaxAmount2 = amount2 === AmountQueryParamEnum.MAX @@ -109,69 +99,21 @@ export function SourceNetworkBox({ const tokenButtonOptionsAmount2 = useMemo( () => ({ symbol: nativeCurrency.symbol, - disabled: true + disabled: true, + balance: ethBalanceSourceChain + ? Number(utils.formatEther(ethBalanceSourceChain)) + : undefined }), - [nativeCurrency.symbol] + [ethBalanceSourceChain, nativeCurrency.symbol] ) return ( <> - - - - - {nativeCurrency.isCustom ? ( - <> - - {/* Only show ETH balance on parent chain */} - {isDepositMode && ( - - )} - - ) : ( - - )} - - +
{isBatchTransferSupported && ( @@ -190,10 +133,11 @@ export function SourceNetworkBox({ errorMessage={errorMessages?.inputAmount2} value={amount2} onChange={handleAmount2Change} - tokenButtonOptions={tokenButtonOptionsAmount2} + options={tokenButtonOptionsAmount2} maxAmount={maxAmount2} isMaxAmount={isMaxAmount2} decimals={nativeCurrency.decimals} + customFeeTokenBalances={customFeeTokenBalances} /> )} diff --git a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx index ad3efc5e98..c10a404096 100644 --- a/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMainInput.tsx @@ -10,29 +10,44 @@ import { useMemo } from 'react' import { TokenButton, TokenButtonOptions } from './TokenButton' import { useNetworks } from '../../hooks/useNetworks' import { useNetworksRelationship } from '../../hooks/useNetworksRelationship' -import { useSelectedTokenBalances } from '../../hooks/TransferPanel/useSelectedTokenBalances' +import { + Balances, + useSelectedTokenBalances +} from '../../hooks/TransferPanel/useSelectedTokenBalances' import { useAppState } from '../../state' import { useBalances } from '../../hooks/useBalances' import { TransferReadinessRichErrorMessage } from './useTransferReadinessUtils' import { ExternalLink } from '../common/ExternalLink' import { useTransferDisabledDialogStore } from './TransferDisabledDialog' +import { formatAmount } from '../../util/NumberUtils' +import { useNativeCurrency } from '../../hooks/useNativeCurrency' +import { Loader } from '../common/atoms/Loader' import { sanitizeAmountQueryParam } from '../../hooks/useArbQueryParams' import { truncateExtraDecimals } from '../../util/NumberUtils' -function MaxButton(props: React.ButtonHTMLAttributes) { - const { className = '', ...rest } = props - +function MaxButton({ + customFeeTokenBalances, + className = '', + ...rest +}: React.ButtonHTMLAttributes & { + customFeeTokenBalances: Balances +}) { const { app: { selectedToken } } = useAppState() const [networks] = useNetworks() - const { isDepositMode } = useNetworksRelationship(networks) + const { isDepositMode, childChainProvider } = + useNetworksRelationship(networks) const { ethParentBalance, ethChildBalance } = useBalances() const selectedTokenBalances = useSelectedTokenBalances() + const nativeCurrency = useNativeCurrency({ provider: childChainProvider }) const maxButtonVisible = useMemo(() => { const ethBalance = isDepositMode ? ethParentBalance : ethChildBalance + const customFeeTokenBalance = isDepositMode + ? customFeeTokenBalances.parentBalance + : customFeeTokenBalances.childBalance const tokenBalance = isDepositMode ? selectedTokenBalances.parentBalance : selectedTokenBalances.childBalance @@ -45,17 +60,23 @@ function MaxButton(props: React.ButtonHTMLAttributes) { return !tokenBalance.isZero() } + if (nativeCurrency.isCustom) { + return customFeeTokenBalance && !customFeeTokenBalance.isZero() + } + if (!ethBalance) { return false } return !ethBalance.isZero() }, [ + isDepositMode, ethParentBalance, ethChildBalance, + customFeeTokenBalances, selectedTokenBalances, selectedToken, - isDepositMode + nativeCurrency.isCustom ]) if (!maxButtonVisible) { @@ -66,7 +87,7 @@ function MaxButton(props: React.ButtonHTMLAttributes) {
From 59756ff795b8b4b91cbd5d7328e1f171f62ea3ae Mon Sep 17 00:00:00 2001 From: Dewansh Date: Tue, 3 Sep 2024 19:40:43 +0530 Subject: [PATCH 4/4] chore: rename teleporter helpers (#1823) --- .../TransactionsTableDetailsSteps.tsx | 21 +++++++++---------- .../TransactionsTableRowAction.tsx | 4 ++-- .../components/TransactionHistory/helpers.ts | 5 ++--- .../components/common/TransferCountdown.tsx | 4 ++-- .../src/hooks/useArbTokenBridge.ts | 4 ++-- .../src/hooks/useNetworksRelationship.ts | 4 ++-- .../src/hooks/useRedeemTeleporter.ts | 5 ++--- .../src/hooks/useTransactionHistory.ts | 8 +++---- .../src/hooks/useTransactions.ts | 2 +- .../src/hooks/useTransferDuration.ts | 4 ++-- .../src/state/app/utils.ts | 9 ++++---- .../src/token-bridge-sdk/teleport.ts | 2 +- .../src/token-bridge-sdk/utils.ts | 9 +++++--- .../src/util/RetryableUtils.ts | 9 ++------ .../src/util/TokenUtils.ts | 4 ++-- .../src/util/deposits/helpers.ts | 13 ++++-------- .../fetchEthTeleportsFromSubgraph.ts | 4 ++-- .../src/util/teleports/fetchTeleports.ts | 4 ++-- 18 files changed, 52 insertions(+), 63 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableDetailsSteps.tsx b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableDetailsSteps.tsx index 61a321c1ac..a349b939ff 100644 --- a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableDetailsSteps.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableDetailsSteps.tsx @@ -21,7 +21,7 @@ import { ExternalLink } from '../common/ExternalLink' import { TransferCountdown } from '../common/TransferCountdown' import { isDepositReadyToRedeem } from '../../state/app/utils' import { Address } from '../../util/AddressUtils' -import { isTeleport } from '@/token-bridge-sdk/teleport' +import { isTeleportTx } from '../../hooks/useTransactions' import { firstRetryableLegRequiresRedeem, secondRetryableLegForTeleportRequiresRedeem @@ -31,7 +31,6 @@ import { minutesToHumanReadableTime, useTransferDuration } from '../../hooks/useTransferDuration' -import { isTeleporterTransaction } from '../../hooks/useTransactions' function needsToClaimTransfer(tx: MergedTransaction) { return tx.isCctp || tx.isWithdrawal @@ -119,7 +118,7 @@ const LastStepEndItem = ({ const destinationChainId = tx.isWithdrawal ? tx.parentChainId : tx.childChainId - const isTeleportTx = isTeleport(tx) && isTeleporterTransaction(tx) + const isTeleport = isTeleportTx(tx) if (destinationNetworkTxId) { return ( @@ -134,8 +133,8 @@ const LastStepEndItem = ({ } if ( - (!isTeleportTx && isDepositReadyToRedeem(tx)) || - (isTeleportTx && secondRetryableLegForTeleportRequiresRedeem(tx)) + (!isTeleport && isDepositReadyToRedeem(tx)) || + (isTeleport && secondRetryableLegForTeleportRequiresRedeem(tx)) ) { return ( @@ -226,7 +225,7 @@ export const TransactionsTableDetailsSteps = ({ /> {/* Pending transfer showing the remaining time */} - {!isTeleport(tx) && ( + {!isTeleportTx(tx) && ( )} - {isTeleport(tx) && isTeleporterTransaction(tx) && ( + {isTeleportTx(tx) && ( )} diff --git a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableRowAction.tsx b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableRowAction.tsx index 65da87e937..af4fe167ef 100644 --- a/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableRowAction.tsx +++ b/packages/arb-token-bridge-ui/src/components/TransactionHistory/TransactionsTableRowAction.tsx @@ -19,7 +19,7 @@ import { useRedeemRetryable } from '../../hooks/useRedeemRetryable' import { TransferCountdown } from '../common/TransferCountdown' import { Address } from '../../util/AddressUtils' import { getChainIdForRedeemingRetryable } from '../../util/RetryableUtils' -import { isTeleport } from '@/token-bridge-sdk/teleport' +import { isTeleportTx } from '../../hooks/useTransactions' import { useRedeemTeleporter } from '../../hooks/useRedeemTeleporter' import { sanitizeTokenSymbol } from '../../util/TokenUtils' import { formatAmount } from '../../util/NumberUtils' @@ -67,7 +67,7 @@ export function TransactionsTableRowAction({ await switchNetworkAsync?.(chainIdForRedeemingRetryable) } - if (isTeleport(tx)) { + if (isTeleportTx(tx)) { await teleporterRedeem() } else { await redeem() diff --git a/packages/arb-token-bridge-ui/src/components/TransactionHistory/helpers.ts b/packages/arb-token-bridge-ui/src/components/TransactionHistory/helpers.ts index b5007f77a7..51d7f0001f 100644 --- a/packages/arb-token-bridge-ui/src/components/TransactionHistory/helpers.ts +++ b/packages/arb-token-bridge-ui/src/components/TransactionHistory/helpers.ts @@ -25,11 +25,10 @@ import { AssetType } from '../../hooks/arbTokenBridge.types' import { getDepositStatus } from '../../state/app/utils' import { getBlockBeforeConfirmation } from '../../state/cctpState' import { getAttestationHashAndMessageFromReceipt } from '../../util/cctp/getAttestationHashAndMessageFromReceipt' -import { isTeleport } from '@/token-bridge-sdk/teleport' import { getOutgoingMessageState } from '../../util/withdrawals/helpers' import { getUniqueIdOrHashFromEvent } from '../../hooks/useArbTokenBridge' import { getProviderForChainId } from '../../token-bridge-sdk/utils' -import { isTeleporterTransaction } from '../../hooks/useTransactions' +import { isTeleportTx } from '../../hooks/useTransactions' const PARENT_CHAIN_TX_DETAILS_OF_CLAIM_TX = 'arbitrum:bridge:claim:parent:tx:details' @@ -639,7 +638,7 @@ export function getDestinationNetworkTxId(tx: MergedTransaction) { return tx.cctpData?.receiveMessageTransactionHash } - if (isTeleport(tx) && isTeleporterTransaction(tx)) { + if (isTeleportTx(tx)) { return tx.l2ToL3MsgData?.l3TxID } diff --git a/packages/arb-token-bridge-ui/src/components/common/TransferCountdown.tsx b/packages/arb-token-bridge-ui/src/components/common/TransferCountdown.tsx index 81236de87c..5806342bc8 100644 --- a/packages/arb-token-bridge-ui/src/components/common/TransferCountdown.tsx +++ b/packages/arb-token-bridge-ui/src/components/common/TransferCountdown.tsx @@ -5,7 +5,7 @@ import { useTransferDuration } from '../../hooks/useTransferDuration' import { isNetwork } from '../../util/networks' -import { isTeleporterTransaction } from '../../hooks/useTransactions' +import { isTeleportTx } from '../../hooks/useTransactions' /** * Displays a transfer countdown for a deposit, withdrawal, or cctp. @@ -30,7 +30,7 @@ export function TransferCountdown({ return Calculating... } - const isTeleport = isTeleporterTransaction(tx) + const isTeleport = isTeleportTx(tx) // To get the first retryable only, we subtract the Orbit deposit time (second retryable) if (isTeleport && firstLegOnly) { estimatedMinutesLeft -= getOrbitDepositDuration(isTestnet) diff --git a/packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts b/packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts index 728068a079..955e15a097 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts @@ -34,7 +34,7 @@ import { getL2NativeToken } from '../util/L2NativeUtils' import { CommonAddress } from '../util/CommonAddressUtils' import { isNetwork } from '../util/networks' import { useDestinationAddressStore } from '../components/TransferPanel/AdvancedSettings' -import { isTeleport } from '../token-bridge-sdk/teleport' +import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport' import { getProviderForChainId } from '@/token-bridge-sdk/utils' export const wait = (ms = 0) => { @@ -319,7 +319,7 @@ export const useArbTokenBridge = ( // while deriving the child-chain address, it can be a teleport transfer too, in that case derive L3 address from L1 address // else, derive the L2 address from L1 address OR L3 address from L2 address if ( - isTeleport({ + isValidTeleportChainPair({ sourceChainId: l1.network.id, destinationChainId: l2.network.id }) diff --git a/packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts b/packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts index 3f325b4e62..cb3d25ddfc 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useNetworksRelationship.ts @@ -3,7 +3,7 @@ import { useMemo } from 'react' import { Chain } from 'wagmi' import { UseNetworksState } from './useNetworks' import { isDepositMode } from '../util/isDepositMode' -import { isTeleport } from '@/token-bridge-sdk/teleport' +import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport' type UseNetworksRelationshipState = { childChain: Chain @@ -25,7 +25,7 @@ export function useNetworksRelationship({ destinationChainId: destinationChain.id }) - const isTeleportMode = isTeleport({ + const isTeleportMode = isValidTeleportChainPair({ sourceChainId: sourceChain.id, destinationChainId: destinationChain.id }) diff --git a/packages/arb-token-bridge-ui/src/hooks/useRedeemTeleporter.ts b/packages/arb-token-bridge-ui/src/hooks/useRedeemTeleporter.ts index a4c4dd6980..4845c0e67f 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useRedeemTeleporter.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useRedeemTeleporter.ts @@ -7,7 +7,6 @@ import { import { useSigner } from 'wagmi' import dayjs from 'dayjs' import { getProviderForChainId } from '@/token-bridge-sdk/utils' -import { isTeleport } from '@/token-bridge-sdk/teleport' import { DepositStatus, MergedTransaction, @@ -27,7 +26,7 @@ import { isUserRejectedError } from '../util/isUserRejectedError' import { errorToast } from '../components/common/atoms/Toast' import { useTransactionHistory } from './useTransactionHistory' import { Address } from '../util/AddressUtils' -import { isTeleporterTransaction, L2ToL3MessageData } from './useTransactions' +import { isTeleportTx, L2ToL3MessageData } from './useTransactions' import { UseRedeemRetryableResult } from './useRedeemRetryable' import { getUpdatedTeleportTransfer } from '../components/TransactionHistory/helpers' @@ -172,7 +171,7 @@ export function useRedeemTeleporter( return } - if (!isTeleport(tx) || !isTeleporterTransaction(tx)) { + if (!isTeleportTx(tx)) { throw new Error( 'The transaction being redeemed is not a LayerLeap transaction.' ) diff --git a/packages/arb-token-bridge-ui/src/hooks/useTransactionHistory.ts b/packages/arb-token-bridge-ui/src/hooks/useTransactionHistory.ts index 4523226c31..080c2f0eca 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useTransactionHistory.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useTransactionHistory.ts @@ -17,7 +17,7 @@ import { L2ToL1EventResultPlus, WithdrawalInitiated } from './arbTokenBridge.types' -import { isTeleporterTransaction, Transaction } from './useTransactions' +import { isTeleportTx, Transaction } from './useTransactions' import { MergedTransaction } from '../state/app/state' import { getStandardizedTimestamp, @@ -51,7 +51,7 @@ import { shouldIncludeReceivedTxs, shouldIncludeSentTxs } from '../util/SubgraphUtils' -import { isTeleport } from '@/token-bridge-sdk/teleport' +import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport' import { getProviderForChainId } from '@/token-bridge-sdk/utils' import { Address } from '../util/AddressUtils' import { @@ -377,7 +377,7 @@ const useTransactionHistoryWithoutStatuses = (address: Address | undefined) => { try { // early check for fetching teleport if ( - isTeleport({ + isValidTeleportChainPair({ sourceChainId: chainPair.parentChainId, destinationChainId: chainPair.childChainId }) @@ -716,7 +716,7 @@ export const useTransactionHistory = ( return } - if (isTeleport(tx) && isTeleporterTransaction(tx)) { + if (isTeleportTx(tx)) { const updatedTeleportTransfer = await getUpdatedTeleportTransfer(tx) updateCachedTransaction(updatedTeleportTransfer) return diff --git a/packages/arb-token-bridge-ui/src/hooks/useTransactions.ts b/packages/arb-token-bridge-ui/src/hooks/useTransactions.ts index b2fd7b83b6..616ebbaa6e 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useTransactions.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useTransactions.ts @@ -133,7 +133,7 @@ export interface DepositTransaction extends Transaction { type: 'deposit' | 'deposit-l1' } -export function isTeleporterTransaction( +export function isTeleportTx( tx: Transaction | MergedTransaction ): tx is TeleporterTransaction | TeleporterMergedTransaction { return (tx as TeleporterTransaction).l2ToL3MsgData !== undefined diff --git a/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts b/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts index e5c0264625..7fb58bf135 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts @@ -1,5 +1,5 @@ import dayjs from 'dayjs' -import { isTeleport } from '@/token-bridge-sdk/teleport' +import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport' import { MergedTransaction } from '../state/app/state' import { useRemainingTimeCctp } from '../state/cctpState' @@ -61,7 +61,7 @@ export const useTransferDuration = ( const standardDepositDuration = getStandardDepositDuration(isTestnet) const orbitDepositDuration = getOrbitDepositDuration(isTestnet) - if (isTeleport({ sourceChainId, destinationChainId })) { + if (isValidTeleportChainPair({ sourceChainId, destinationChainId })) { // Deposit only return { approximateDurationInMinutes: diff --git a/packages/arb-token-bridge-ui/src/state/app/utils.ts b/packages/arb-token-bridge-ui/src/state/app/utils.ts index e6e9580fc6..695b4bcabd 100644 --- a/packages/arb-token-bridge-ui/src/state/app/utils.ts +++ b/packages/arb-token-bridge-ui/src/state/app/utils.ts @@ -14,12 +14,11 @@ import { OutgoingMessageState } from '../../hooks/arbTokenBridge.types' import { - isTeleporterTransaction, + isTeleportTx, TeleporterTransaction, Transaction } from '../../hooks/useTransactions' import { getUniqueIdOrHashFromEvent } from '../../hooks/useArbTokenBridge' -import { isTeleport } from '../../token-bridge-sdk/teleport' import { firstRetryableLegRequiresRedeem, secondRetryableLegForTeleportRequiresRedeem @@ -62,7 +61,7 @@ export const getDepositStatus = ( return DepositStatus.L1_PENDING } - if (isTeleporterTransaction(tx)) { + if (isTeleportTx(tx)) { const { l2ToL3MsgData, parentToChildMsgData } = tx // if any of the retryable info is missing, first fetch might be pending @@ -166,7 +165,7 @@ export const transformDeposit = ( sourceChainId: Number(tx.l1NetworkID), destinationChainId: Number(tx.l2NetworkID) } - if (isTeleporterTransaction(tx)) { + if (isTeleportTx(tx)) { return { ...transaction, l2ToL3MsgData: tx.l2ToL3MsgData @@ -298,7 +297,7 @@ export const isWithdrawalReadyToClaim = (tx: MergedTransaction) => { } export const isDepositReadyToRedeem = (tx: MergedTransaction) => { - if (isTeleport(tx) && isTeleporterTransaction(tx)) { + if (isTeleportTx(tx)) { return ( firstRetryableLegRequiresRedeem(tx) || secondRetryableLegForTeleportRequiresRedeem(tx) diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/teleport.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/teleport.ts index 83599b6e6c..34cfb7c96e 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/teleport.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/teleport.ts @@ -14,7 +14,7 @@ import { getChainIdFromProvider, getProviderForChainId } from './utils' import { TELEPORT_ALLOWLIST } from '../util/networks' import { addressIsSmartContract } from '../util/AddressUtils' -export const isTeleport = ({ +export const isValidTeleportChainPair = ({ sourceChainId, destinationChainId }: { diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/utils.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/utils.ts index 480d2cf627..7dbf694b29 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/utils.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/utils.ts @@ -3,7 +3,7 @@ import { Provider, StaticJsonRpcProvider } from '@ethersproject/providers' import { ChainId, isNetwork, rpcURLs } from '../util/networks' import { BridgeTransferStarterPropsWithChainIds } from './BridgeTransferStarter' -import { isTeleport as isTeleportTransfer } from './teleport' +import { isValidTeleportChainPair } from './teleport' import { Erc20Bridger, Erc20L1L3Bridger, @@ -48,7 +48,10 @@ export const getBridgeTransferProperties = ( (isSourceChainOrbit && isDestinationChainEthereumMainnetOrTestnet) || // l2 orbit chains to l1 (isSourceChainOrbit && isDestinationChainArbitrum) // l3 orbit chains to l1 - const isTeleport = isTeleportTransfer({ sourceChainId, destinationChainId }) + const isTeleport = isValidTeleportChainPair({ + sourceChainId, + destinationChainId + }) const isNativeCurrencyTransfer = typeof props.sourceChainErc20Address === 'undefined' @@ -83,7 +86,7 @@ export const getBridger = async ({ }) => { const destinationChainProvider = getProviderForChainId(destinationChainId) - if (isTeleportTransfer({ sourceChainId, destinationChainId })) { + if (isValidTeleportChainPair({ sourceChainId, destinationChainId })) { const l3Network = await getArbitrumNetwork(destinationChainId) return isNativeCurrencyTransfer diff --git a/packages/arb-token-bridge-ui/src/util/RetryableUtils.ts b/packages/arb-token-bridge-ui/src/util/RetryableUtils.ts index e1771510f5..da1111d787 100644 --- a/packages/arb-token-bridge-ui/src/util/RetryableUtils.ts +++ b/packages/arb-token-bridge-ui/src/util/RetryableUtils.ts @@ -7,12 +7,11 @@ import { Signer } from '@ethersproject/abstract-signer' import { Provider } from '@ethersproject/abstract-provider' import dayjs from 'dayjs' import { JsonRpcProvider } from '@ethersproject/providers' -import { isTeleport } from '@/token-bridge-sdk/teleport' import { MergedTransaction, TeleporterMergedTransaction } from '../state/app/state' -import { isTeleporterTransaction } from '../hooks/useTransactions' +import { isTeleportTx } from '../hooks/useTransactions' type GetRetryableTicketParams = { parentChainTxHash: string @@ -144,11 +143,7 @@ export const secondRetryableLegForTeleportRequiresRedeem = ( export const getChainIdForRedeemingRetryable = (tx: MergedTransaction) => { // which chain id needs to be connected to, to redeem the retryable ticket - if ( - isTeleport(tx) && - isTeleporterTransaction(tx) && - firstRetryableLegRequiresRedeem(tx) - ) { + if (isTeleportTx(tx) && firstRetryableLegRequiresRedeem(tx)) { // in teleport, unless it's the final retryable being redeemed, we need to connect to the l2 chain if (!tx.l2ToL3MsgData) { throw Error( diff --git a/packages/arb-token-bridge-ui/src/util/TokenUtils.ts b/packages/arb-token-bridge-ui/src/util/TokenUtils.ts index 54a8af215b..91318f35e7 100644 --- a/packages/arb-token-bridge-ui/src/util/TokenUtils.ts +++ b/packages/arb-token-bridge-ui/src/util/TokenUtils.ts @@ -17,7 +17,7 @@ import { ERC20BridgeToken, TokenType } from '../hooks/arbTokenBridge.types' import { getBridger, getChainIdFromProvider } from '../token-bridge-sdk/utils' import { getL2ConfigForTeleport, - isTeleport + isValidTeleportChainPair } from '../token-bridge-sdk/teleport' import { captureSentryErrorWithExtraData } from './SentryUtils' @@ -483,7 +483,7 @@ export async function isGatewayRegistered({ // for now, we are returning true since we are limiting the tokens to teleport, but we will expand this once we expand the allowList const sourceChainId = await getChainIdFromProvider(parentChainProvider) const destinationChainId = await getChainIdFromProvider(childChainProvider) - if (isTeleport({ sourceChainId, destinationChainId })) { + if (isValidTeleportChainPair({ sourceChainId, destinationChainId })) { return true } diff --git a/packages/arb-token-bridge-ui/src/util/deposits/helpers.ts b/packages/arb-token-bridge-ui/src/util/deposits/helpers.ts index f379a9c6d1..d3af5b97e3 100644 --- a/packages/arb-token-bridge-ui/src/util/deposits/helpers.ts +++ b/packages/arb-token-bridge-ui/src/util/deposits/helpers.ts @@ -17,13 +17,13 @@ import { L2ToL3MessageData, Transaction, TxnStatus, - TeleporterTransaction + TeleporterTransaction, + isTeleportTx } from '../../hooks/useTransactions' import { fetchErc20Data } from '../TokenUtils' import { getL2ConfigForTeleport, - fetchTeleportStatusFromTxId, - isTeleport + fetchTeleportStatusFromTxId } from '../../token-bridge-sdk/teleport' import { getProviderForChainId } from '../../token-bridge-sdk/utils' @@ -68,12 +68,7 @@ export const updateAdditionalDepositData = async ({ isClassic }) - if ( - isTeleport({ - sourceChainId: depositTx.parentChainId, - destinationChainId: depositTx.childChainId - }) - ) { + if (isTeleportTx(depositTx)) { const { status, timestampResolved, l1ToL2MsgData, l2ToL3MsgData } = await fetchTeleporterDepositStatusData({ ...depositTx, diff --git a/packages/arb-token-bridge-ui/src/util/teleports/fetchEthTeleportsFromSubgraph.ts b/packages/arb-token-bridge-ui/src/util/teleports/fetchEthTeleportsFromSubgraph.ts index 62a5e05004..aacbee19a0 100644 --- a/packages/arb-token-bridge-ui/src/util/teleports/fetchEthTeleportsFromSubgraph.ts +++ b/packages/arb-token-bridge-ui/src/util/teleports/fetchEthTeleportsFromSubgraph.ts @@ -1,4 +1,4 @@ -import { isTeleport } from '../../token-bridge-sdk/teleport' +import { isValidTeleportChainPair } from '../../token-bridge-sdk/teleport' import { hasL1Subgraph } from '../SubgraphUtils' import { getAPIBaseUrl, sanitizeQueryParams } from '../index' @@ -81,7 +81,7 @@ export const fetchEthTeleportsFromSubgraph = async ({ // don't query if not a valid teleport configuration if ( - !isTeleport({ + !isValidTeleportChainPair({ sourceChainId: Number(l1ChainId), destinationChainId: Number(l3ChainId) }) diff --git a/packages/arb-token-bridge-ui/src/util/teleports/fetchTeleports.ts b/packages/arb-token-bridge-ui/src/util/teleports/fetchTeleports.ts index c906992757..bfc245ac4b 100644 --- a/packages/arb-token-bridge-ui/src/util/teleports/fetchTeleports.ts +++ b/packages/arb-token-bridge-ui/src/util/teleports/fetchTeleports.ts @@ -10,7 +10,7 @@ import { } from './fetchErc20TeleportsFromSubgraph' import { getL2ConfigForTeleport, - isTeleport + isValidTeleportChainPair } from '../../token-bridge-sdk/teleport' import { getChainIdFromProvider } from '../../token-bridge-sdk/utils' @@ -51,7 +51,7 @@ export const fetchTeleports = async ({ // don't query if not a valid teleport configuration if ( - !isTeleport({ + !isValidTeleportChainPair({ sourceChainId: l1ChainId, destinationChainId: l3ChainId })