From 0a9d9a2a1fb098ae9a1fbf931ba321fbd5521032 Mon Sep 17 00:00:00 2001 From: Fionna Chan <13184582+fionnachan@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:42:00 +0800 Subject: [PATCH] refactor: use isDepositMode in App.tsx (#2001) --- .../src/components/App/App.tsx | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/components/App/App.tsx b/packages/arb-token-bridge-ui/src/components/App/App.tsx index 65d3f60ccf..d23f339fb8 100644 --- a/packages/arb-token-bridge-ui/src/components/App/App.tsx +++ b/packages/arb-token-bridge-ui/src/components/App/App.tsx @@ -25,7 +25,7 @@ import { BalanceUpdater } from '../syncers/BalanceUpdater' import { TokenListSyncer } from '../syncers/TokenListSyncer' import { Header } from '../common/Header' import { HeaderAccountPopover } from '../common/HeaderAccountPopover' -import { getNetworkName, isNetwork } from '../../util/networks' +import { getNetworkName } from '../../util/networks' import { ArbQueryParamProvider, useArbQueryParams @@ -41,6 +41,7 @@ import { HeaderConnectWalletButton } from '../common/HeaderConnectWalletButton' import { onDisconnectHandler } from '../../util/walletConnectUtils' import { addressIsSmartContract } from '../../util/AddressUtils' import { useSyncConnectedChainToAnalytics } from './useSyncConnectedChainToAnalytics' +import { isDepositMode } from '../../util/isDepositMode' declare global { interface Window { @@ -98,15 +99,6 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => { // Any time one of those changes setTokenBridgeParams(null) actions.app.setConnectionState(ConnectionState.LOADING) - - const { - isArbitrum: isConnectedToArbitrum, - isOrbitChain: isConnectedToOrbitChain - } = isNetwork(networks.sourceChain.id) - const isParentChainEthereum = isNetwork( - parentChain.id - ).isEthereumMainnetOrTestnet - actions.app.reset(networks.sourceChain.id) actions.app.setChainIds({ l1NetworkChainId: parentChain.id, @@ -114,14 +106,16 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => { }) if ( - (isParentChainEthereum && isConnectedToArbitrum) || - isConnectedToOrbitChain + isDepositMode({ + sourceChainId: networks.sourceChain.id, + destinationChainId: networks.destinationChain.id + }) ) { - console.info('Withdrawal mode detected:') - actions.app.setConnectionState(ConnectionState.L2_CONNECTED) - } else { console.info('Deposit mode detected:') actions.app.setConnectionState(ConnectionState.L1_CONNECTED) + } else { + console.info('Withdrawal mode detected:') + actions.app.setConnectionState(ConnectionState.L2_CONNECTED) } setTokenBridgeParams({