Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move token state into query params #1770

Open
wants to merge 125 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 124 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
09dcda7
sanitize query params server-side
spsjvc Jan 26, 2024
0c96f54
forgot to export
spsjvc Jan 26, 2024
c64cb4f
fix
spsjvc Jan 26, 2024
0cbadce
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Feb 8, 2024
7ee3ba6
Fix server-side sanitizing of network query param for orbit chains
chrstph-dvx Feb 8, 2024
b78af5c
Omit server sanitization if both chains are missing
chrstph-dvx Feb 8, 2024
6d347e6
Keep previous params
chrstph-dvx Feb 12, 2024
eed4192
Properly encode amount param
chrstph-dvx Feb 13, 2024
8996822
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Feb 13, 2024
ce0837c
Merge branch 'master' into feat-sanitize-query-params-server-side
fionnachan Feb 13, 2024
1388a70
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Feb 22, 2024
3ac1ae9
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Mar 8, 2024
fb6e2d7
simplify getDestinationChainIds
chrstph-dvx Mar 8, 2024
c672d43
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Jul 18, 2024
4708a2a
Merge branch 'master' into feat-sanitize-query-params-server-side
chrstph-dvx Jul 18, 2024
934418f
token-query-params
brtkx Jul 19, 2024
941a8a9
fix
brtkx Jul 19, 2024
44b8608
fixes
brtkx Jul 22, 2024
0e05993
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jul 22, 2024
6047fc4
unused var
brtkx Jul 22, 2024
b53430e
fix
brtkx Jul 22, 2024
3252775
try
brtkx Jul 22, 2024
12d6a41
fix e2e
brtkx Jul 22, 2024
038c544
e2e fixes and clean up
brtkx Jul 22, 2024
059a969
clean ups and fixes e2e
brtkx Jul 22, 2024
976617c
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jul 22, 2024
5e16815
fixes
brtkx Jul 22, 2024
62d7668
fixes
brtkx Jul 23, 2024
0e26cb0
fixes
brtkx Jul 23, 2024
83fde15
Merge branch 'feat-sanitize-query-params-server-side' of github.com:O…
brtkx Jul 23, 2024
707cd12
video
brtkx Jul 23, 2024
3c1379d
video
brtkx Jul 23, 2024
76965c3
revert
brtkx Jul 23, 2024
6dcdf2a
try
brtkx Jul 23, 2024
4b60ae8
reduce rerendering
brtkx Jul 23, 2024
ea5e0bc
fixes
brtkx Jul 23, 2024
921927f
log
brtkx Jul 23, 2024
6fbd77f
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jul 23, 2024
552f7f6
optimization
brtkx Jul 23, 2024
12fcae3
try fix tests
brtkx Jul 23, 2024
93529c9
Revert "try fix tests"
brtkx Jul 23, 2024
9acd027
fix
brtkx Jul 23, 2024
f06e4b2
fix
brtkx Jul 23, 2024
9eb3400
remove videos
brtkx Jul 23, 2024
0f24a23
Merge branch 'master' into token-query-params
brtkx Jul 23, 2024
1910fd4
Merge branch 'master' into token-query-params
brtkx Jul 25, 2024
eb2e8eb
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jul 29, 2024
e2c0bac
merge changes
brtkx Jul 29, 2024
23f17b9
merge
brtkx Jul 29, 2024
be37c03
clean up
brtkx Jul 29, 2024
b5dd720
fix usdce bals
brtkx Jul 29, 2024
0508911
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Aug 5, 2024
afa23a3
fix
brtkx Aug 5, 2024
b8b35c5
address hook comments
brtkx Aug 6, 2024
128ed01
Merge branch 'master' into token-query-params
brtkx Aug 6, 2024
1524536
fixes
brtkx Aug 6, 2024
9108a5c
Merge branch 'token-query-params' of github.com:OffchainLabs/arbitrum…
brtkx Aug 6, 2024
a01384c
Merge branch 'master' into token-query-params
brtkx Aug 6, 2024
99bca1b
updates
brtkx Aug 6, 2024
d35e69d
Merge github.com:OffchainLabs/arbitrum-token-bridge into token-query-…
brtkx Aug 6, 2024
5944ec2
merge
brtkx Aug 6, 2024
2bd4938
fix
brtkx Aug 6, 2024
c70da10
fix
brtkx Aug 6, 2024
2fc92cf
token loaders
brtkx Aug 9, 2024
9247fd5
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Aug 9, 2024
4ffe912
loader color
brtkx Aug 9, 2024
c01e2e5
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Aug 28, 2024
904afb9
updates
brtkx Aug 28, 2024
b9b567e
fix
brtkx Aug 28, 2024
04ea158
fix tests
brtkx Aug 29, 2024
c70c2ee
Merge branch 'master' into token-query-params
fionnachan Aug 30, 2024
be331dc
Merge branch 'master' into token-query-params
fionnachan Sep 2, 2024
012ae4a
fix
brtkx Sep 2, 2024
01af184
Merge branch 'token-query-params' of github.com:OffchainLabs/arbitrum…
brtkx Sep 2, 2024
be8c31e
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Sep 9, 2024
d7d4dec
fix
brtkx Sep 9, 2024
1c408bf
fix
brtkx Sep 9, 2024
38f650c
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Sep 9, 2024
b230818
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Nov 25, 2024
a326ce0
fix
brtkx Nov 25, 2024
f6207cb
Merge branch 'master' into token-query-params
chrstph-dvx Nov 26, 2024
e6d6d4c
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Dec 19, 2024
402aed4
fix build
brtkx Dec 23, 2024
18fba1a
Merge branch 'master' into token-query-params
brtkx Dec 23, 2024
410d974
Merge branch 'master' into token-query-params
brtkx Dec 23, 2024
37b7305
Merge branch 'master' into token-query-params
fionnachan Dec 24, 2024
5e706d0
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jan 15, 2025
ee76052
merge
brtkx Jan 15, 2025
ed32a52
fix build
brtkx Jan 15, 2025
f821bdc
address comments
brtkx Jan 15, 2025
4ddf44a
remove chaining
brtkx Jan 15, 2025
861ecd6
revert
brtkx Jan 15, 2025
303d07f
resolve conflicts
brtkx Jan 21, 2025
78b0edc
e2e
brtkx Jan 21, 2025
1dcc1e2
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jan 21, 2025
ff33ccd
merge
brtkx Jan 21, 2025
a4b3804
merge
brtkx Jan 21, 2025
9615a7d
fix unit tests
brtkx Jan 21, 2025
30b910e
fix
brtkx Jan 21, 2025
b2faa3c
fix
brtkx Jan 21, 2025
6c4ff0a
fix
brtkx Jan 22, 2025
bbb3800
fix
brtkx Jan 22, 2025
ce9f123
fix e2e
brtkx Jan 22, 2025
da191f1
fix e2e
brtkx Jan 22, 2025
03168af
fix
brtkx Jan 22, 2025
537fe19
fix
brtkx Jan 22, 2025
cad8013
fix query key
brtkx Jan 22, 2025
44d76ce
fix
brtkx Jan 22, 2025
32623ec
Merge branch 'master' into token-query-params
brtkx Jan 22, 2025
aa57156
clean up
brtkx Jan 23, 2025
a085234
Merge branch 'token-query-params' of github.com:OffchainLabs/arbitrum…
brtkx Jan 23, 2025
7ba58c8
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jan 29, 2025
c7dc09e
add swr key string
brtkx Jan 29, 2025
baf7cd7
fixes
brtkx Jan 29, 2025
a193bf1
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Jan 29, 2025
6cc0ec4
update key string
brtkx Jan 30, 2025
64f89dc
fix usdc
brtkx Jan 30, 2025
b97c14e
remove console log
brtkx Jan 30, 2025
687768e
remove console log
brtkx Jan 30, 2025
16dc3c3
fix cctp tests
brtkx Jan 30, 2025
20160f9
fix
brtkx Jan 30, 2025
af811fa
fix
brtkx Jan 30, 2025
85a3e2d
clean up
brtkx Jan 30, 2025
af0ffd2
clean up
brtkx Jan 30, 2025
a079e1a
fix dialogs
brtkx Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions packages/arb-token-bridge-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { TokenBridgeParams } from '../../hooks/useArbTokenBridge'
import { WelcomeDialog } from './WelcomeDialog'
import { BlockedDialog } from './BlockedDialog'
import { AppContextProvider } from './AppContext'
import { config, useActions, useAppState } from '../../state'
import { config, useActions } from '../../state'
import { MainContent } from '../MainContent/MainContent'
import { ArbTokenBridgeStoreSync } from '../syncers/ArbTokenBridgeStoreSync'
import { TokenListSyncer } from '../syncers/TokenListSyncer'
Expand All @@ -33,7 +33,6 @@ import { TOS_LOCALSTORAGE_KEY } from '../../constants'
import { getProps } from '../../util/wagmi/setup'
import { useAccountIsBlocked } from '../../hooks/useAccountIsBlocked'
import { useCCTPIsBlocked } from '../../hooks/CCTP/useCCTPIsBlocked'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { sanitizeQueryParams, useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { HeaderConnectWalletButton } from '../common/HeaderConnectWalletButton'
Expand All @@ -59,46 +58,22 @@ const rainbowkitTheme = merge(darkTheme(), {

const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => {
const actions = useActions()
const {
app: { selectedToken }
} = useAppState()
const [networks] = useNetworks()
const { childChain, childChainProvider, parentChain, parentChainProvider } =
useNetworksRelationship(networks)
const nativeCurrency = useNativeCurrency({ provider: childChainProvider })

// We want to be sure this fetch is completed by the time we open the USDC modals
useCCTPIsBlocked()

const [tokenBridgeParams, setTokenBridgeParams] =
useState<TokenBridgeParams | null>(null)

useEffect(() => {
Copy link
Contributor Author

@brtkx brtkx Jul 22, 2024

Choose a reason for hiding this comment

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

This caused a lot of rerenders because useSelectedToken uses tokenBridge data under the hood. This block of code is not needed anyway because we set token to null when networks change

if (!nativeCurrency.isCustom) {
return
}

const selectedTokenAddress = selectedToken?.address.toLowerCase()
const selectedTokenL2Address = selectedToken?.l2Address?.toLowerCase()
// This handles a super weird edge case where, for example:
//
// Your setup is: from Arbitrum One to Mainnet, and you have $ARB selected as the token you want to bridge over.
// You then switch your destination network to a network that has $ARB as its native currency.
// For this network, $ARB can only be bridged as the native currency, and not as a standard ERC-20, which is why we have to reset the selected token.
if (
selectedTokenAddress === nativeCurrency.address ||
selectedTokenL2Address === nativeCurrency.address
) {
actions.app.setSelectedToken(null)
}
}, [selectedToken, nativeCurrency])

// Listen for account and network changes
useEffect(() => {
// Any time one of those changes
setTokenBridgeParams(null)
actions.app.setConnectionState(ConnectionState.LOADING)
actions.app.reset(networks.sourceChain.id)
actions.app.reset()
actions.app.setChainIds({
l1NetworkChainId: parentChain.id,
l2NetworkChainId: childChain.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { formatAmount, formatUSD } from '../../util/NumberUtils'
import { getExplorerUrl, isNetwork } from '../../util/networks'
import { useGasPrice } from '../../hooks/useGasPrice'
import { NativeCurrencyErc20 } from '../../hooks/useNativeCurrency'
import { useAppState } from '../../state'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { shortenAddress } from '../../util/CommonUtils'
import { NoteBox } from '../common/NoteBox'
import { BridgeTransferStarterFactory } from '@/token-bridge-sdk/BridgeTransferStarterFactory'
import { useSelectedToken } from '../../hooks/useSelectedToken'
import { useIsBatchTransferSupported } from '../../hooks/TransferPanel/useIsBatchTransferSupported'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'

Expand All @@ -29,8 +29,7 @@ export function CustomFeeTokenApprovalDialog(
const { customFeeToken, isOpen } = props

const { ethToUSD } = useETHPrice()
const { app } = useAppState()
const { selectedToken } = app
const [selectedToken] = useSelectedToken()

const [networks] = useNetworks()
const { sourceChain, destinationChain } = networks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { InformationCircleIcon } from '@heroicons/react/24/outline'
import { useMemo } from 'react'
import { twMerge } from 'tailwind-merge'

import { useAppState } from '../../state'
import { getNetworkName, isNetwork } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { Tooltip } from '../common/Tooltip'
Expand All @@ -14,6 +13,7 @@ import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { NativeCurrencyPrice, useIsBridgingEth } from './NativeCurrencyPrice'
import { isTokenNativeUSDC } from '../../util/TokenUtils'
import { useSelectedToken } from '../../hooks/useSelectedToken'

function getGasFeeTooltip(chainId: ChainId) {
const { isEthereumMainnetOrTestnet } = isNetwork(chainId)
Expand Down Expand Up @@ -54,9 +54,7 @@ export function EstimatedGas({
}: {
chainType: 'source' | 'destination'
}) {
const {
app: { selectedToken }
} = useAppState()
const [selectedToken] = useSelectedToken()
const [networks] = useNetworks()
const {
childChain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { NativeCurrency } from '../../hooks/useNativeCurrency'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { useAppState } from '../../state'
import { isNetwork } from '../../util/networks'
import { useETHPrice } from '../../hooks/useETHPrice'
import { formatUSD } from '../../util/NumberUtils'
import { useSelectedToken } from '../../hooks/useSelectedToken'

export function useIsBridgingEth(childChainNativeCurrency: NativeCurrency) {
const {
app: { selectedToken }
} = useAppState()
const [selectedToken] = useSelectedToken()
const isBridgingEth =
selectedToken === null && !childChainNativeCurrency.isCustom
return isBridgingEth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Tab } from '@headlessui/react'
import Hop from '@/images/bridge/hop.png'

import { useAppState } from '../../state'
import { TabButton } from '../common/Tab'
import { BridgesTable } from '../common/BridgesTable'
import { SecurityNotGuaranteed } from './SecurityLabels'
Expand All @@ -10,6 +9,7 @@ import { FastBridgeInfo, FastBridgeNames } from '../../util/fastBridges'
import { getNetworkName, isNetwork } from '../../util/networks'
import { ChainId } from '../../types/ChainId'
import { ether } from '../../constants'
import { useSelectedToken } from '../../hooks/useSelectedToken'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'
import { useNetworks } from '../../hooks/useNetworks'

Expand Down Expand Up @@ -47,9 +47,7 @@ function getDialogSourceAndDestinationChains({
}

export function OneNovaTransferDialog(props: UseDialogProps) {
const {
app: { selectedToken }
} = useAppState()
const [selectedToken] = useSelectedToken()
const [{ amount }] = useArbQueryParams()
const [{ sourceChain, destinationChain }] = useNetworks()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useMemo } from 'react'
import { utils } from 'ethers'
import { Popover } from '@headlessui/react'
import { ChevronDownIcon } from '@heroicons/react/24/outline'
import { twMerge } from 'tailwind-merge'

import { useAppState } from '../../state'
import { TokenSearch } from '../TransferPanel/TokenSearch'
import { sanitizeTokenSymbol } from '../../util/TokenUtils'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
Expand All @@ -17,6 +17,10 @@ import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { Transition } from '../common/Transition'
import { SafeImage } from '../common/SafeImage'
import { useTokensFromLists, useTokensFromUser } from './TokenSearchUtils'
import { Loader } from '../common/atoms/Loader'
import { useSelectedToken } from '../../hooks/useSelectedToken'
import { useTokenLists } from '../../hooks/useTokenLists'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'

export type TokenButtonOptions = {
symbol?: string
Expand All @@ -29,13 +33,13 @@ export function TokenButton({
}: {
options?: TokenButtonOptions
}): JSX.Element {
const {
app: { selectedToken }
} = useAppState()
const [selectedToken] = useSelectedToken()
const disabled = options?.disabled ?? false

const [networks] = useNetworks()
const { childChainProvider } = useNetworksRelationship(networks)
const { childChain, childChainProvider } = useNetworksRelationship(networks)
const { isLoading: isLoadingTokenLists } = useTokenLists(childChain.id)
const [{ token: tokenFromSearchParams }] = useArbQueryParams()

const tokensFromLists = useTokensFromLists()
const tokensFromUser = useTokensFromUser()
Expand All @@ -57,6 +61,17 @@ export function TokenButton({
})
}, [selectedToken, networks.sourceChain.id, nativeCurrency.symbol, options])

const isLoadingToken = useMemo(() => {
// don't show loader if native currency is selected
if (!tokenFromSearchParams) {
return false
}
if (!utils.isAddress(tokenFromSearchParams)) {
return false
}
return isLoadingTokenLists
}, [tokenFromSearchParams, isLoadingTokenLists])

const tokenLogoSrc = useMemo(() => {
if (typeof options?.logoSrc !== 'undefined') {
return options.logoSrc || nativeCurrency.logoUrl
Expand Down Expand Up @@ -90,19 +105,27 @@ export function TokenButton({
disabled={disabled}
>
<div className="flex items-center gap-2">
<SafeImage
src={tokenLogoSrc}
alt={`${selectedToken?.symbol ?? nativeCurrency.symbol} logo`}
className="h-5 w-5 shrink-0"
/>
<span className="text-xl font-light">{tokenSymbol}</span>
{!disabled && (
<ChevronDownIcon
className={twMerge(
'h-3 w-3 text-gray-6 transition-transform duration-200',
open ? '-rotate-180' : 'rotate-0'
{isLoadingToken ? (
<Loader size="small" color="white" />
) : (
<>
<SafeImage
src={tokenLogoSrc}
alt={`${
selectedToken?.symbol ?? nativeCurrency.symbol
} logo`}
className="h-5 w-5 shrink-0"
/>
<span className="text-xl font-light">{tokenSymbol}</span>
{!disabled && (
<ChevronDownIcon
className={twMerge(
'h-3 w-3 text-gray-6 transition-transform duration-200',
open ? '-rotate-180' : 'rotate-0'
)}
/>
)}
/>
</>
)}
</div>
</Popover.Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLatest } from 'react-use'
import { create } from 'zustand'

import { useERC20L1Address } from '../../hooks/useERC20L1Address'
import { useActions, useAppState } from '../../state'
import { useAppState } from '../../state'
import {
erc20DataToErc20BridgeToken,
fetchErc20Data,
Expand All @@ -22,6 +22,7 @@ import { useTransferDisabledDialogStore } from './TransferDisabledDialog'
import { TokenInfo } from './TokenInfo'
import { NoteBox } from '../common/NoteBox'
import { isTeleportEnabledToken } from '../../util/TokenTeleportEnabledUtils'
import { useSelectedToken } from '../../hooks/useSelectedToken'

enum ImportStatus {
LOADING,
Expand Down Expand Up @@ -66,10 +67,10 @@ export function TokenImportDialog({
const { address: walletAddress } = useAccount()
const {
app: {
arbTokenBridge: { bridgeTokens, token },
selectedToken
arbTokenBridge: { bridgeTokens, token }
}
} = useAppState()
const [selectedToken, setSelectedToken] = useSelectedToken()
const [networks] = useNetworks()
const {
childChain,
Expand All @@ -78,7 +79,6 @@ export function TokenImportDialog({
parentChainProvider,
isTeleportMode
} = useNetworksRelationship(networks)
const actions = useActions()

const tokensFromUser = useTokensFromUser()
const latestTokensFromUser = useLatest(tokensFromUser)
Expand Down Expand Up @@ -177,9 +177,9 @@ export function TokenImportDialog({
const selectToken = useCallback(
async (_token: ERC20BridgeToken) => {
await token.updateTokenData(_token.address)
actions.app.setSelectedToken(_token)
setSelectedToken(_token.address)
},
[token, actions]
[token, setSelectedToken]
)

useEffect(() => {
Expand Down Expand Up @@ -258,7 +258,6 @@ export function TokenImportDialog({
l1Address,
onClose,
selectToken,
selectedToken,
tokensFromUser
])

Expand Down
Loading