import { Box, Tooltip, Typography } from '@mui/material'; import type { TFunction } from 'i18next'; import type { ReactElement } from 'react'; import { useTranslation } from 'react-i18next'; import { formatUnits } from 'viem'; import type { FeesBreakdown } from '../utils/fees.js'; import { TON_CHAIN_ID } from '../utils/constants.js'; export interface FeeBreakdownTooltipProps { gasCosts?: FeesBreakdown[]; feeCosts?: FeesBreakdown[]; children: ReactElement; } export const FeeBreakdownTooltip: React.FC = ({ gasCosts, feeCosts, children, }) => { const { t } = useTranslation(); return ( {gasCosts?.length ? ( {t('main.fees.network')} {getFeeBreakdownTypography(gasCosts, t)} ) : null} {feeCosts?.length ? ( {t('main.fees.provider')} {getFeeBreakdownTypography(feeCosts, t)} ) : null} } sx={{ cursor: 'help' }} > {children} ); }; export const getFeeBreakdownTypography = ( fees: FeesBreakdown[], t: TFunction, ) => { return fees.map((fee, index) => { const amount = parseFloat( formatUnits(fee.amount, fee.token.decimals), )?.toFixed(9); return ( {t(`format.currency`, { value: (fee as any)?.token?.chainId === TON_CHAIN_ID ? fee.amountUSD / 10 : fee.amountUSD, })}{' '} ( {(fee as any)?.token?.chainId === TON_CHAIN_ID ? Number(amount) / 10 : amount}{' '} {fee.token.symbol}) ); }); };