import AccessTimeIcon from '@mui/icons-material/AccessTimeFilled';
import LayersIcon from '@mui/icons-material/Layers';
import MonetizationOnIcon from '@mui/icons-material/MonetizationOn';
import { Box, Typography } from '@mui/material';
import type { TFunction } from 'i18next';
import { useTranslation } from 'react-i18next';
import { formatUnits } from 'viem';
import { getFeeCostsBreakdown, getGasCostsBreakdown } from '../../utils';
import { IconTypography } from './RouteCard.style';
import type { FeesBreakdown, RouteCardEssentialsProps } from './types';
export const RouteCardEssentialsExpanded: React.FC<
RouteCardEssentialsProps
> = ({ route }) => {
const { t, i18n } = useTranslation();
const executionTimeMinutes = Math.ceil(
route.steps
.map((step) => step.estimate.executionDuration)
.reduce((duration, x) => duration + x, 0) / 60,
);
const gasCostUSD = parseFloat(route.gasCostUSD ?? '') || 0.01;
const gasCosts = getGasCostsBreakdown(route);
const feeCosts = getFeeCostsBreakdown(route, false);
const fees =
gasCostUSD + feeCosts.reduce((sum, feeCost) => sum + feeCost.amountUSD, 0);
return (
{t(`format.currency`, {
value: fees,
})}
{t('main.fees.networkEstimated')}
{getFeeBreakdownTypography(gasCosts, t)}
{feeCosts.length ? (
{t('main.fees.providerEstimated')}
{getFeeBreakdownTypography(feeCosts, t)}
) : null}
{route.steps.length}
{t(`tooltip.numberOfSteps`)}
{new Intl.NumberFormat(i18n.language, {
style: 'unit',
unit: 'minute',
unitDisplay: 'long',
}).format(executionTimeMinutes)}
);
};
const getFeeBreakdownTypography = (fees: FeesBreakdown[], t: TFunction) =>
fees.map((fee, index) => (
{t(`format.currency`, { value: fee.amountUSD })} (
{parseFloat(formatUnits(fee.amount, fee.token.decimals))?.toFixed(9)}{' '}
{fee.token.symbol})
));