import { Box, Tooltip, Typography } from '@mui/material' import type { TFunction } from 'i18next' import type { ReactElement } from 'react' import { useTranslation } from 'react-i18next' import type { FeesBreakdown } from '../utils/fees.js' import { formatTokenAmount } from '../utils/format.js' interface FeeBreakdownTooltipProps { gasCosts?: FeesBreakdown[] feeCosts?: FeesBreakdown[] gasless?: boolean children: ReactElement } export const FeeBreakdownTooltip: React.FC = ({ gasCosts, feeCosts, gasless, children, }) => { const { t } = useTranslation() return ( {gasless ? {t('tooltip.gasless')} : null} {gasCosts?.length && !gasless ? ( {t('main.fees.network')} {getFeeBreakdownTypography(gasCosts, t)} ) : null} {feeCosts?.length && !gasless ? ( {t('main.fees.provider')} {getFeeBreakdownTypography(feeCosts, t)} ) : null} } sx={{ cursor: 'help' }} > {children} ) } const getFeeBreakdownTypography = (fees: FeesBreakdown[], t: TFunction) => fees.map((fee, index) => ( {t('format.currency', { value: fee.amountUSD })} ( {t('format.tokenAmount', { value: formatTokenAmount(fee.amount, fee.token.decimals), })}{' '} {fee.token.symbol}) ))