import OpenInNewIcon from '@mui/icons-material/OpenInNewRounded'; import { Avatar, Box, Link, ListItemAvatar, ListItemText, Skeleton, Slide, Typography, } from '@mui/material'; import { MouseEventHandler, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { formatUnits } from 'viem'; import { formatTokenAmount, formatTokenPrice, shortenAddress, } from '../../utils'; import { IconButton, ListItem, ListItemButton } from './TokenList.style'; import type { TokenListItemButtonProps, TokenListItemProps } from './types'; export const TokenListItem: React.FC = ({ onClick, size, start, token, chain, showBalance, isBalanceLoading, startAdornment, endAdornment, }) => { const handleClick: MouseEventHandler = (e) => { e.stopPropagation(); onClick?.(token.address); }; return ( {startAdornment} {endAdornment} ); }; export const TokenListItemButton: React.FC = ({ onClick, token, chain, showBalance, isBalanceLoading, }) => { const { t } = useTranslation(); const tokenPrice = token.amount ? formatTokenPrice( formatUnits(token.amount, token.decimals), token.priceUSD, ) : undefined; const container = useRef(null); const timeoutId = useRef>(); const [showAddress, setShowAddress] = useState(false); const onMouseEnter = () => { timeoutId.current = setTimeout(() => setShowAddress(true), 350); }; const onMouseLeave = () => { clearTimeout(timeoutId.current); if (showAddress) { setShowAddress(false); } }; return ( {token.symbol?.[0]} {token.name} {shortenAddress(token.address)} e.stopPropagation()} > } /> {showBalance ? ( isBalanceLoading ? ( ) : ( {token.amount ? ( {t('format.number', { value: formatTokenAmount(token.amount, token.decimals), })} ) : null} {tokenPrice ? ( {t(`format.currency`, { value: tokenPrice, })} ) : null} ) ) : null} ); }; export const TokenListItemSkeleton = () => { return ( } disablePadding sx={{ position: 'relative', flexDirection: 'row', alignItems: 'center' }} > } secondary={} /> ); }; export const TokenAmountSkeleton: React.FC = () => { return ( ); };