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

refactor: Remove useArbTokenBridge from store #1479

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1a053aa
Remove useArbTokenBridge from store
chrstph-dvx Jan 26, 2024
0e08dfd
Update syncers
chrstph-dvx Jan 26, 2024
14f7d20
Add useCallback to useArbTokenBridge, move addBridgeTokenListToBridge
chrstph-dvx Jan 26, 2024
955547e
Memoize useTransactions
chrstph-dvx Jan 26, 2024
2d39062
Fix typing
chrstph-dvx Jan 26, 2024
4ad3bb5
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Jan 26, 2024
7dc7d8c
Reset useArbTokenBridge
chrstph-dvx Jan 29, 2024
4cf85e2
Add shared zustand store for bridgeTokens
chrstph-dvx Jan 29, 2024
c02f0e5
Replace params with useNetworks in useArbTokenBridge
chrstph-dvx Jan 29, 2024
a96c5a6
Add addBridgeTokenListToBridge to useArbTokenBridge
chrstph-dvx Jan 29, 2024
d2e4846
Move updateTokenData
chrstph-dvx Jan 29, 2024
1ffeabb
Move addToken
chrstph-dvx Jan 29, 2024
65583ee
Move addToExecutedMessagesCache
chrstph-dvx Jan 29, 2024
b87dc6f
Add useCallback for updateEthBalances
chrstph-dvx Jan 29, 2024
b4da51b
Add useCallback for useArbTokenBridge functions
chrstph-dvx Jan 29, 2024
207c6f9
Memoize returned object in useArbTokenBridge
chrstph-dvx Jan 29, 2024
8cef344
Remove unused import
chrstph-dvx Jan 29, 2024
aa1b575
Rework call to useArbTokenBridge
chrstph-dvx Jan 29, 2024
f2c7c82
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Jan 30, 2024
59f56e4
Keep track of source/destination chain in state
chrstph-dvx Jan 30, 2024
5354099
Fix warning with missing autoresizer style
chrstph-dvx Jan 30, 2024
b6503cd
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Jan 31, 2024
130e603
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Feb 8, 2024
5576101
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Feb 8, 2024
dcb5145
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Feb 20, 2024
f96c6a7
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Feb 27, 2024
22b6448
Remove ledger from yarn.lock
chrstph-dvx Feb 27, 2024
96e9124
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Mar 20, 2024
0af6601
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Jul 30, 2024
8be9478
fix import dialog
fionnachan Jul 31, 2024
cfcadf2
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
fionnachan Jul 31, 2024
5df85c3
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Aug 1, 2024
801d145
Fix import token
chrstph-dvx Aug 1, 2024
38cf72a
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Aug 2, 2024
d8e12da
Add missing hooks in App
chrstph-dvx Aug 2, 2024
3bd8a45
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
fionnachan Aug 2, 2024
303d33d
Remove connectionState
chrstph-dvx Aug 2, 2024
ce1ade6
Remove unused import
chrstph-dvx Aug 2, 2024
b868e0e
Add lost code after merge
chrstph-dvx Aug 2, 2024
a99a910
Remove commented code
chrstph-dvx Aug 5, 2024
fe8b01a
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
fionnachan Aug 6, 2024
7dd835d
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Aug 14, 2024
24440ca
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Aug 14, 2024
d915ff1
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Aug 19, 2024
e52eebe
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
fionnachan Aug 30, 2024
396576e
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Sep 9, 2024
04c22f8
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Sep 9, 2024
d7a8593
Merge branch 'master' into 1432-use-usenetworksrelationship-inside-us…
chrstph-dvx Sep 9, 2024
30462e6
Remove extra token button
chrstph-dvx Sep 9, 2024
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
Copy link
Member

Choose a reason for hiding this comment

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

useAppState is now an unused import

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 { useActions } from '../../state'
import {
erc20DataToErc20BridgeToken,
fetchErc20Data,
Expand Down
40 changes: 34 additions & 6 deletions packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff on this file is actually fairly simple:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be browsed from commit 7dc7d8c

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
getL1ERC20Address,
getL2ERC20Address,
l1TokenIsDisabled,
isValidErc20
isValidErc20,
getL3ERC20Address
} from '../util/TokenUtils'
import { getL2NativeToken } from '../util/L2NativeUtils'
import { CommonAddress } from '../util/CommonAddressUtils'
Expand All @@ -38,6 +39,7 @@ import { useNetworksRelationship } from './useNetworksRelationship'
import { BridgeTokenList, fetchTokenListFromURL } from '../util/TokenListUtils'
import { useDestinationAddressStore } from '../components/TransferPanel/AdvancedSettings'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
import { isTeleport } from '@/token-bridge-sdk/teleport'

export const wait = (ms = 0) => {
return new Promise(res => setTimeout(res, ms))
Expand Down Expand Up @@ -213,12 +215,36 @@ export const useArbTokenBridge = (): ArbTokenBridge => {
l2Address = lowercasedErc20L1orL2Address
} else {
// looks like l1 address was provided
// l1Address = lowercasedErc20L1orL2Address
// l2Address = await getL2ERC20Address({
// erc20L1Address: l1Address,
// l1Provider: parentChainProvider,
// l2Provider: childChainProvider
// })
fionnachan marked this conversation as resolved.
Show resolved Hide resolved
l1Address = lowercasedErc20L1orL2Address
l2Address = await getL2ERC20Address({
erc20L1Address: l1Address,
l1Provider: parentChainProvider,
l2Provider: childChainProvider
})

// 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({
sourceChainId: parentChain.id,
destinationChainId: childChain.id
})
) {
// this can be a bit hard to follow, but it will resolve when we have code-wide better naming for variables
// here `l2Address` actually means `childChainAddress`, and `l2.provider` is actually being used as a child-chain-provider, which in this case will be L3
l2Address = await getL3ERC20Address({
erc20L1Address: l1Address,
l1Provider: parentChainProvider,
l3Provider: childChainProvider // in case of teleport transfer, the l2.provider being used here is actually the l3 provider
})
} else {
l2Address = await getL2ERC20Address({
erc20L1Address: l1Address,
l1Provider: parentChainProvider,
l2Provider: childChainProvider
})
}
}

const bridgeTokensToAdd: ContractStorage<ERC20BridgeToken> = {}
Expand Down Expand Up @@ -261,7 +287,9 @@ export const useArbTokenBridge = (): ArbTokenBridge => {
}
},
[
childChain.id,
childChainProvider,
parentChain.id,
parentChainProvider,
setBridgeTokens,
updateErc20L1Balance,
Expand Down
8 changes: 0 additions & 8 deletions packages/arb-token-bridge-ui/src/state/app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { ERC20BridgeToken } from '../../hooks/arbTokenBridge.types'
import { Context } from '..'
import { ConnectionState } from '../../util'
import { WarningTokens } from './state'

export const setConnectionState = (
{ state }: Context,
connectionState: ConnectionState
) => {
state.app.connectionState = connectionState
}

export const setSelectedToken = (
{ state }: Context,
token: ERC20BridgeToken | null
Expand Down
3 changes: 0 additions & 3 deletions packages/arb-token-bridge-ui/src/state/app/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
L2ToL3MessageData,
TxnType
} from '../../hooks/useTransactions'
import { ConnectionState } from '../../util'
import { CCTPSupportedChainId } from '../cctpState'
import { Address } from '../../util/AddressUtils'

Expand Down Expand Up @@ -88,7 +87,6 @@ export interface WarningTokens {

export type AppState = {
warningTokens: WarningTokens
connectionState: number
selectedToken: ERC20BridgeToken | null
verifying: WhiteListState
sourceChainId: number | null
Expand All @@ -97,7 +95,6 @@ export type AppState = {

const defaultState: AppState = {
warningTokens: {} as WarningTokens,
connectionState: ConnectionState.LOADING,
sourceChainId: null,
destinationChainId: null,
verifying: WhiteListState.ALLOWED,
Expand Down
7 changes: 0 additions & 7 deletions packages/arb-token-bridge-ui/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export enum ConnectionState {
LOADING,
L1_CONNECTED,
L2_CONNECTED,
NETWORK_ERROR
}

export const sanitizeImageSrc = (url: string): string => {
if (url.startsWith('ipfs')) {
return `https://ipfs.io/ipfs/${url.substring(7)}`
Expand Down
Loading