Commit 99a3cfaf authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

feat: support NATIVE page for all supported chains (#4722)

support NATIVE page for all supported chains
parent 6c908eb7
...@@ -388,6 +388,20 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = ...@@ -388,6 +388,20 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } =
'WMATIC', 'WMATIC',
'Wrapped MATIC' 'Wrapped MATIC'
), ),
[SupportedChainId.CELO]: new Token(
SupportedChainId.CELO,
'0x471ece3750da237f93b8e339c536989b8978a438',
18,
'CELO',
'Celo native asset'
),
[SupportedChainId.CELO_ALFAJORES]: new Token(
SupportedChainId.CELO_ALFAJORES,
'0xf194afdf50b03e69bd7d057c1aa9e10c9954e4c9',
18,
'CELO',
'Celo native asset'
),
} }
export function isCelo(chainId: number): chainId is SupportedChainId.CELO | SupportedChainId.CELO_ALFAJORES { export function isCelo(chainId: number): chainId is SupportedChainId.CELO | SupportedChainId.CELO_ALFAJORES {
......
...@@ -112,29 +112,31 @@ export default function TokenDetails() { ...@@ -112,29 +112,31 @@ export default function TokenDetails() {
const token = useTokenQuery(tokenAddress ?? '', currentChainName, timePeriod).tokens?.[0] const token = useTokenQuery(tokenAddress ?? '', currentChainName, timePeriod).tokens?.[0]
const navigate = useNavigate() const navigate = useNavigate()
const switchChains = (newChain: Chain) => { const switchChains = useCallback(
if (tokenAddressParam === 'NATIVE') { (newChain: Chain) => {
navigate(`/tokens/${newChain.toLowerCase()}/NATIVE`) const chainSegment = newChain.toLowerCase()
} else { if (tokenAddressParam === 'NATIVE') {
token?.project?.tokens?.forEach((token) => { navigate(`/tokens/${chainSegment}/NATIVE`)
if (token.chain === newChain && token.address) { } else {
navigate(`/tokens/${newChain.toLowerCase()}/${token.address}`) token?.project?.tokens?.forEach((token) => {
} if (token.chain === newChain && token.address) {
}) navigate(`/tokens/${chainSegment}/${token.address}`)
} }
} })
}
},
[navigate, token?.project?.tokens, tokenAddressParam]
)
useOnGlobalChainSwitch(switchChains) useOnGlobalChainSwitch(switchChains)
const [continueSwap, setContinueSwap] = useState<{ resolve: (value: boolean | PromiseLike<boolean>) => void }>() const [continueSwap, setContinueSwap] = useState<{ resolve: (value: boolean | PromiseLike<boolean>) => void }>()
// TODO: Make useToken() work on non-mainenet chains or replace this logic
const shouldShowSpeedbump = !useIsUserAddedTokenOnChain(tokenAddress, chainId) && tokenWarning !== null const shouldShowSpeedbump = !useIsUserAddedTokenOnChain(tokenAddress, chainId) && tokenWarning !== null
// Show token safety modal if Swap-reviewing a warning token, at all times if the current token is blocked // Show token safety modal if Swap-reviewing a warning token, at all times if the current token is blocked
const onReviewSwap = useCallback(() => { const onReviewSwap = useCallback(
return new Promise<boolean>((resolve) => { () => new Promise<boolean>((resolve) => (shouldShowSpeedbump ? setContinueSwap({ resolve }) : resolve(true))),
shouldShowSpeedbump ? setContinueSwap({ resolve }) : resolve(true) [shouldShowSpeedbump]
}) )
}, [shouldShowSpeedbump])
const onResolveSwap = useCallback( const onResolveSwap = useCallback(
(value: boolean) => { (value: boolean) => {
...@@ -191,12 +193,6 @@ export default function TokenDetails() { ...@@ -191,12 +193,6 @@ export default function TokenDetails() {
? new Token(CHAIN_NAME_TO_CHAIN_ID[currentChainName], token.address, 18, token.symbol, token.name) ? new Token(CHAIN_NAME_TO_CHAIN_ID[currentChainName], token.address, 18, token.symbol, token.name)
: undefined) : undefined)
// TODO: Fix this logic to not automatically redirect on refresh, yet still catch invalid addresses
//const location = useLocation()
//if (token === undefined) {
// return <Navigate to={{ ...location, pathname: '/tokens' }} replace />
//}
return ( return (
<TokenDetailsLayout> <TokenDetailsLayout>
{token && ( {token && (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment