import { useMemo } from "react"; import type { Token } from "../../../../../bridge/index.js"; import type { Chain } from "../../../../../chains/types.js"; import { getCachedChain } from "../../../../../chains/utils.js"; import type { ThirdwebClient } from "../../../../../client/client.js"; import { NATIVE_TOKEN_ADDRESS } from "../../../../../constants/addresses.js"; import { resolveScheme } from "../../../../../utils/ipfs.js"; import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js"; import { iconSize, spacing } from "../../../../core/design-system/index.js"; import { useChainIconUrl, useChainMetadata, } from "../../../../core/hooks/others/useChainQuery.js"; import { genericTokenIcon } from "../../../../core/utils/walletIcon.js"; import { isNativeToken } from "../../ConnectWallet/screens/nativeToken.js"; import { Container } from "../../components/basic.js"; import { ChainName } from "../../components/ChainName.js"; import { fallbackChainIcon } from "../../components/fallbackChainIcon.js"; import { Img } from "../../components/Img.js"; import { Text } from "../../components/text.js"; export function TokenAndChain({ token, client, size, style, }: { token: Omit; client: ThirdwebClient; size: keyof typeof iconSize; style?: React.CSSProperties; }) { const theme = useCustomTheme(); const chain = getCachedChain(token.chainId); return ( {chain.id !== 1 && ( )} {token.name} ); } function TokenIconWithFallback(props: { token: Omit; size: keyof typeof iconSize; client: ThirdwebClient; }) { const chain = getCachedChain(props.token.chainId); const chainMeta = useChainMetadata(chain).data; const theme = useCustomTheme(); const tokenImage = useMemo(() => { if ( isNativeToken(props.token) || props.token.address === NATIVE_TOKEN_ADDRESS ) { if (chainMeta?.nativeCurrency.symbol === "ETH") { return "ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/ethereum/512.png"; // ETH icon } return chainMeta?.icon?.url; } return props.token.iconUri; }, [props.token, chainMeta?.icon?.url, chainMeta?.nativeCurrency.symbol]); return tokenImage ? ( ) : ( {props.token.symbol.slice(0, 1)} ); } export const ChainIcon: React.FC<{ chain: Chain; size: keyof typeof iconSize; client: ThirdwebClient; }> = (props) => { const { url } = useChainIconUrl(props.chain); return ( ); }; const getSrcChainIcon = (props: { client: ThirdwebClient; chainIconUrl?: string; }) => { const url = props.chainIconUrl; if (!url) { return fallbackChainIcon; } try { return resolveScheme({ client: props.client, uri: url, }); } catch { return fallbackChainIcon; } };