-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update switch chain logic (#1916)
- Loading branch information
1 parent
15d2439
commit 7c9c055
Showing
4 changed files
with
136 additions
and
146 deletions.
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
52 changes: 52 additions & 0 deletions
52
packages/arb-token-bridge-ui/src/components/TransferPanel/hooks/useIsTransferAllowed.ts
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useMemo } from 'react' | ||
import { useAccount, useNetwork } from 'wagmi' | ||
|
||
import { useAppState } from '../../../state' | ||
import { useNetworks } from '../../../hooks/useNetworks' | ||
import { useDestinationAddressError } from './useDestinationAddressError' | ||
|
||
export function useIsTransferAllowed() { | ||
const { | ||
app: { | ||
arbTokenBridgeLoaded, | ||
arbTokenBridge: { eth } | ||
} | ||
} = useAppState() | ||
const { address: walletAddress, isConnected } = useAccount() | ||
// do not use `useChainId` because it won't detect chains outside of our wagmi config | ||
const { chain } = useNetwork() | ||
const [networks] = useNetworks() | ||
const { destinationAddressError } = useDestinationAddressError() | ||
|
||
return useMemo(() => { | ||
const isConnectedToTheWrongChain = chain?.id !== networks.sourceChain.id | ||
|
||
if (!arbTokenBridgeLoaded) { | ||
return false | ||
} | ||
if (!eth) { | ||
return false | ||
} | ||
if (!isConnected) { | ||
return false | ||
} | ||
if (!walletAddress) { | ||
return false | ||
} | ||
if (isConnectedToTheWrongChain) { | ||
return false | ||
} | ||
if (!!destinationAddressError) { | ||
return false | ||
} | ||
return true | ||
}, [ | ||
arbTokenBridgeLoaded, | ||
chain?.id, | ||
destinationAddressError, | ||
isConnected, | ||
eth, | ||
networks.sourceChain.id, | ||
walletAddress | ||
]) | ||
} |
13 changes: 0 additions & 13 deletions
13
packages/arb-token-bridge-ui/src/hooks/useIsConnectedToArbitrum.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/arb-token-bridge-ui/src/hooks/useIsConnectedToOrbitChain.ts
This file was deleted.
Oops, something went wrong.