Skip to content

Commit

Permalink
refactor: use isDepositMode in App.tsx (#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan authored Oct 18, 2024
1 parent 38a06f6 commit 0a9d9a2
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/arb-token-bridge-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -98,30 +99,23 @@ 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,
l2NetworkChainId: childChain.id
})

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({
Expand Down

0 comments on commit 0a9d9a2

Please sign in to comment.