import { OpenInNewRounded } from '@mui/icons-material'; import { Avatar, Box, Link, ListItemAvatar, ListItemText, Skeleton, Slide, Typography, styled, } from '@mui/material'; import type { MouseEventHandler } from 'react'; import { useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { formatUnits } from 'viem'; import { useExplorer } from '../../hooks/useExplorer.js'; import { formatTokenAmount, formatTokenPrice } from '../../utils/format.js'; import { shortenAddress } from '../../utils/wallet.js'; import { ListItemButton } from '../ListItem/ListItemButton.js'; import { IconButton, ListItem } from './TokenList.style.js'; import type { TokenListItemButtonProps, TokenListItemProps } from './types.js'; 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 { getAddressLink } = useExplorer(); 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); } }; const VerifiedIcon = styled(Box)(({ theme }) => { return { background: theme.palette.mode === 'light' ? '#fff' : '#121212', width: '20px', height: '20px', borderRadius: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', }; }); return ( {token?.isVerified ? (
) : null} {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 ( ); };