import type { LiFiStepExtended } from '@lifi/sdk'; import MonetizationOnIcon from '@mui/icons-material/MonetizationOn'; import { Box, Typography } from '@mui/material'; import type { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import { formatUnits } from 'viem'; import { getStepFeeCostsBreakdown } from '../../utils'; export const StepFeeBreakdown: React.FC<{ step: LiFiStepExtended; }> = ({ step }) => { const { t } = useTranslation(); let fees = 0; const feeComponents: ReactNode[] = []; const isDone = step.execution?.status === 'DONE'; const gasCosts = step.execution?.gasCosts ?? step.estimate.gasCosts; const feeCosts = step.execution?.feeCosts ?? step.estimate.feeCosts; if (gasCosts) { const { token, amount, amountUSD } = getStepFeeCostsBreakdown(gasCosts); const formattedGasAmount = token ? parseFloat(formatUnits(amount, token.decimals))?.toFixed(9) : 0; fees += amountUSD; feeComponents.push( {isDone ? t('main.fees.networkPaid') : t('main.fees.networkEstimated')} {t(`format.currency`, { value: amountUSD })} ({formattedGasAmount}{' '} {token.symbol}) , ); } if (feeCosts) { const filteredfeeCosts = feeCosts?.filter((fee) => !fee.included); if (filteredfeeCosts?.length) { const { token, amount, amountUSD } = getStepFeeCostsBreakdown(filteredfeeCosts); const formattedFeeAmount = token ? parseFloat(formatUnits(amount, token.decimals))?.toFixed(9) : 0; fees += amountUSD; feeComponents.push( {isDone ? t('main.fees.providerPaid') : t('main.fees.providerEstimated')} {t(`format.currency`, { value: amountUSD })} ({formattedFeeAmount}{' '} {token.symbol}) , ); } } return ( {t(`format.currency`, { value: fees, })} {feeComponents} ); };