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' export interface FeeBreakdownTooltipProps { gasCosts?: FeesBreakdown[] feeCosts?: FeesBreakdown[] relayerSupport?: boolean children: ReactElement } export const FeeBreakdownTooltip: React.FC = ({ gasCosts, feeCosts, relayerSupport, children, }) => { const { t } = useTranslation() return ( {relayerSupport ? {t('tooltip.relayerService')} : null} {gasCosts?.length && !relayerSupport ? ( {t('main.fees.network')} {getFeeBreakdownTypography(gasCosts, t)} ) : null} {feeCosts?.length && !relayerSupport ? ( {t('main.fees.provider')} {getFeeBreakdownTypography(feeCosts, t)} ) : null} } sx={{ cursor: 'help' }} > {children} ) } export 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}) ))