-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract isCctpTransfer logic to useIsCctpTransfer hook (#1910)
- Loading branch information
1 parent
efe9702
commit bf46d79
Showing
2 changed files
with
54 additions
and
44 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
51 changes: 51 additions & 0 deletions
51
packages/arb-token-bridge-ui/src/components/TransferPanel/hooks/useIsCctpTransfer.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,51 @@ | ||
import { useNetworks } from '../../../hooks/useNetworks' | ||
import { useNetworksRelationship } from '../../../hooks/useNetworksRelationship' | ||
import { useAppState } from '../../../state' | ||
import { isNetwork } from '../../../util/networks' | ||
import { | ||
isTokenArbitrumOneNativeUSDC, | ||
isTokenArbitrumSepoliaNativeUSDC, | ||
isTokenMainnetUSDC, | ||
isTokenSepoliaUSDC | ||
} from '../../../util/TokenUtils' | ||
|
||
export const useIsCctpTransfer = function () { | ||
const { | ||
app: { selectedToken } | ||
} = useAppState() | ||
const [networks] = useNetworks() | ||
const { childChain, isDepositMode, isTeleportMode } = | ||
useNetworksRelationship(networks) | ||
const { isArbitrumOne, isArbitrumSepolia } = isNetwork(childChain.id) | ||
|
||
if (!selectedToken) { | ||
return false | ||
} | ||
|
||
if (isTeleportMode) { | ||
return false | ||
} | ||
|
||
if (isDepositMode) { | ||
if (isTokenMainnetUSDC(selectedToken.address) && isArbitrumOne) { | ||
return true | ||
} | ||
|
||
if (isTokenSepoliaUSDC(selectedToken.address) && isArbitrumSepolia) { | ||
return true | ||
} | ||
} else { | ||
if (isTokenArbitrumOneNativeUSDC(selectedToken.address) && isArbitrumOne) { | ||
return true | ||
} | ||
|
||
if ( | ||
isTokenArbitrumSepoliaNativeUSDC(selectedToken.address) && | ||
isArbitrumSepolia | ||
) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |