diff --git a/frontend/src/components/TokenPicker.jsx b/frontend/src/components/TokenPicker.jsx index 5d3fe892..3147cd4d 100644 --- a/frontend/src/components/TokenPicker.jsx +++ b/frontend/src/components/TokenPicker.jsx @@ -12,7 +12,7 @@ import { import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; -import { useTokenList } from "../hooks/useTokenList"; +import { ChainIdToName, useTokenList, isTestnet } from "../hooks/useTokenList"; import { useTokenSearch } from "../hooks/useTokenSearch"; import { CopyButton } from "./ui/copyButton"; import { Avatar } from "./ui/avatar"; @@ -216,20 +216,22 @@ export function TokenPicker({ setOpen(false); }; + const isOnTestnet = isTestnet(chainId); + return ( <> + {isOnTestnet && ( +
+ +

+ Token selection is disabled on testnets. Please switch to a mainnet network to use this feature. +

+
+ )} + setOpen(false)}>
@@ -315,12 +326,37 @@ export function TokenPicker({
- - Failed to load tokens - - - {tokensError} - + {tokensError.includes("manually input") ? ( + <> + + Testnet:{" "} + {ChainIdToName[chainId] || "Unknown"} ( + {chainId}) + + + Token Selection is not supported in testnets. + + + {tokensError} + + + ) : tokensError.includes("not supported") ? ( + <> + + Chain Not Supported + + {tokensError} + + ) : ( + <> + + Failed to load tokens + + + {tokensError} + + + )}
) : filteredTokens.length === 0 ? ( diff --git a/frontend/src/hooks/useTokenList.js b/frontend/src/hooks/useTokenList.js index 9c42cf7b..af5e6edf 100644 --- a/frontend/src/hooks/useTokenList.js +++ b/frontend/src/hooks/useTokenList.js @@ -7,7 +7,7 @@ const tokenCache = {}; const TESTNET_CHAIN_IDS = new Set([11155111, 5]); // Sepolia, Goerli // Helper function to check if a chain is testnet -const isTestnet = (chainId) => TESTNET_CHAIN_IDS.has(chainId); +export const isTestnet = (chainId) => TESTNET_CHAIN_IDS.has(chainId); export const ChainIdToName = { 1: "ethereum", @@ -25,6 +25,8 @@ export function useTokenList(chainId) { // Return cached tokens if available if (tokenCache[chainId]) { setTokens(tokenCache[chainId]); + setError(null); + setLoading(false); return; }