import { OpenInNewRounded } from '@mui/icons-material' import { Avatar, Box, Link, ListItemAvatar, ListItemText, Skeleton, Slide, Typography, } from '@mui/material' import { ChainType } from '@openocean.finance/widget-sdk' import type { MouseEventHandler } from 'react' import { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' 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, accountAddress, isBalanceLoading, startAdornment, endAdornment, }) => { const handleClick: MouseEventHandler = (e) => { e.stopPropagation() onClick?.(token.address, chain?.id) } return ( {startAdornment} {endAdornment} ) } export const TokenListItemButton: React.FC = ({ onClick, token, chain, accountAddress, isBalanceLoading, }) => { const { t } = useTranslation() const { getAddressLink } = useExplorer() const container = useRef(null) const timeoutId = useRef>(undefined) const [showAddress, setShowAddress] = useState(false) const tokenAddress = chain?.chainType === ChainType.UTXO ? accountAddress : token.address const onMouseEnter = () => { timeoutId.current = setTimeout(() => { if (tokenAddress) { setShowAddress(true) } }, 350) } const onMouseLeave = () => { clearTimeout(timeoutId.current) if (showAddress) { setShowAddress(false) } } const tokenAmount = formatTokenAmount(token.amount, token.decimals) const tokenPrice = formatTokenPrice( token.amount, token.priceUSD, token.decimals ) return ( {token.symbol?.[0]} {token.name} {shortenAddress(tokenAddress)} e.stopPropagation()} > } /> {accountAddress ? ( isBalanceLoading ? ( ) : ( {token.amount ? ( {t('format.tokenAmount', { value: tokenAmount, })} ) : 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 ( ) }