-
Notifications
You must be signed in to change notification settings - Fork 209
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 3/3 #2090
Open
chrstph-dvx
wants to merge
5
commits into
fs-1001/add-usecallbacks
Choose a base branch
from
fs-1001/replace-useAppState-calls
base: fs-1001/add-usecallbacks
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,11 @@ import { createOvermind, Overmind } from 'overmind' | |
import { Provider } from 'overmind-react' | ||
import { useLocalStorage } from '@uidotdev/usehooks' | ||
|
||
import { ConnectionState } from '../../util' | ||
import { TokenBridgeParams } from '../../hooks/useArbTokenBridge' | ||
import { WelcomeDialog } from './WelcomeDialog' | ||
import { BlockedDialog } from './BlockedDialog' | ||
import { AppContextProvider } from './AppContext' | ||
import { config, useActions, useAppState } from '../../state' | ||
import { MainContent } from '../MainContent/MainContent' | ||
import { ArbTokenBridgeStoreSync } from '../syncers/ArbTokenBridgeStoreSync' | ||
import { BalanceUpdater } from '../syncers/BalanceUpdater' | ||
import { TokenListSyncer } from '../syncers/TokenListSyncer' | ||
import { Header } from '../common/Header' | ||
import { HeaderAccountPopover } from '../common/HeaderAccountPopover' | ||
|
@@ -34,14 +30,14 @@ 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 { sanitizeQueryParams } from '../../hooks/useNetworks' | ||
import { HeaderConnectWalletButton } from '../common/HeaderConnectWalletButton' | ||
import { onDisconnectHandler } from '../../util/walletConnectUtils' | ||
import { addressIsSmartContract } from '../../util/AddressUtils' | ||
import { useSyncConnectedChainToAnalytics } from './useSyncConnectedChainToAnalytics' | ||
import { isDepositMode } from '../../util/isDepositMode' | ||
import { useInterval } from 'react-use' | ||
import { useArbTokenBridge } from '../../hooks/useArbTokenBridge' | ||
import { useUpdateUSDCBalances } from '../../hooks/CCTP/useUpdateUSDCBalances' | ||
|
||
declare global { | ||
interface Window { | ||
|
@@ -58,86 +54,25 @@ const rainbowkitTheme = merge(darkTheme(), { | |
} | ||
} as Theme) | ||
|
||
const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => { | ||
function AppContent() { | ||
const { address, isConnected } = useAccount() | ||
const { isBlocked } = useAccountIsBlocked() | ||
const [tosAccepted] = useLocalStorage<boolean>(TOS_LOCALSTORAGE_KEY, false) | ||
const { openConnectModal } = useConnectModal() | ||
const actions = useActions() | ||
const { | ||
app: { selectedToken } | ||
} = useAppState() | ||
const [networks] = useNetworks() | ||
const { childChain, childChainProvider, parentChain, parentChainProvider } = | ||
useNetworksRelationship(networks) | ||
const nativeCurrency = useNativeCurrency({ provider: childChainProvider }) | ||
const { | ||
token: { updateTokenData } | ||
} = useArbTokenBridge() | ||
const { updateUSDCBalances } = useUpdateUSDCBalances({ | ||
walletAddress: address | ||
}) | ||
|
||
// 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(() => { | ||
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.setChainIds({ | ||
l1NetworkChainId: parentChain.id, | ||
l2NetworkChainId: childChain.id | ||
}) | ||
|
||
if ( | ||
isDepositMode({ | ||
sourceChainId: networks.sourceChain.id, | ||
destinationChainId: networks.destinationChain.id | ||
}) | ||
) { | ||
console.info('Deposit mode detected:') | ||
actions.app.setConnectionState(ConnectionState.L1_CONNECTED) | ||
} else { | ||
console.info('Withdrawal mode detected:') | ||
actions.app.setConnectionState(ConnectionState.L2_CONNECTED) | ||
} | ||
|
||
setTokenBridgeParams({ | ||
l1: { | ||
network: parentChain, | ||
provider: parentChainProvider | ||
}, | ||
l2: { | ||
network: childChain, | ||
provider: childChainProvider | ||
} | ||
}) | ||
}, [ | ||
networks.sourceChain.id, | ||
parentChain.id, | ||
childChain.id, | ||
parentChain, | ||
childChain, | ||
parentChainProvider, | ||
childChainProvider | ||
]) | ||
|
||
useEffect(() => { | ||
axios | ||
.get( | ||
|
@@ -149,20 +84,14 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => { | |
.catch(err => { | ||
console.warn('Failed to fetch warning tokens:', err) | ||
}) | ||
}, []) | ||
|
||
if (!tokenBridgeParams) { | ||
return null | ||
} | ||
|
||
return <ArbTokenBridgeStoreSync tokenBridgeParams={tokenBridgeParams} /> | ||
} | ||
}, [actions.app]) | ||
|
||
function AppContent() { | ||
const { address, isConnected } = useAccount() | ||
const { isBlocked } = useAccountIsBlocked() | ||
const [tosAccepted] = useLocalStorage<boolean>(TOS_LOCALSTORAGE_KEY, false) | ||
const { openConnectModal } = useConnectModal() | ||
useInterval(() => { | ||
updateUSDCBalances() | ||
if (selectedToken) { | ||
updateTokenData(selectedToken.address) | ||
} | ||
Comment on lines
+91
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed back here |
||
}, 10_000) | ||
|
||
useEffect(() => { | ||
if (tosAccepted && !isConnected) { | ||
|
@@ -219,8 +148,6 @@ function AppContent() { | |
<HeaderAccountPopover /> | ||
</Header> | ||
<TokenListSyncer /> | ||
<BalanceUpdater /> | ||
<ArbTokenBridgeStoreSyncWrapper /> | ||
<MainContent /> | ||
</> | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, tested with APE token for Ape chain and it works well after deletion