import type { TokenAmount } from '@lifi/sdk' import { Box, Tooltip } from '@mui/material' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js' import type { RouteLabel } from '../../types/widget.js' import { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js' import type { CardProps } from '../Card/Card.js' import { Card } from '../Card/Card.js' import { CardLabel, CardLabelTypography } from '../Card/CardLabel.js' import { getMatchingLabels } from './getMatchingLabels.js' import { RouteToken } from './RouteToken.js' import type { RouteCardProps } from './types.js' export const RouteCard: React.FC< RouteCardProps & Omit > = ({ route, active, variant = 'default', expanded: defaultExpanded, ...other }) => { const { t } = useTranslation() const { mode, modeOptions, routeLabels, hiddenUI } = useWidgetConfig() const token: TokenAmount = mode === 'custom' && modeOptions?.custom?.type !== 'deposit' ? { ...route.fromToken, amount: BigInt(route.fromAmount) } : { ...route.toToken, amount: BigInt(route.toAmount) } const impactToken: TokenAmount | undefined = mode !== 'custom' && !hiddenUI?.routeCardPriceImpact ? { ...route.fromToken, amount: BigInt(route.fromAmount) } : undefined const [tags, customLabels]: [string[], RouteLabel[]] = useMemo(() => { const mainTag = route.tags?.find( (tag) => tag === 'CHEAPEST' || tag === 'FASTEST' ) const tags: string[] = mainTag ? [mainTag] : [] const { combinedFeesUSD } = getAccumulatedFeeCostsBreakdown(route) if (!combinedFeesUSD) { tags.push('gasless') } if (route.steps.length > 1) { tags.push('multistep') } const customLabels = getMatchingLabels(route, routeLabels) return [tags, customLabels] }, [route.tags, route, routeLabels]) const cardContent = ( {mode !== 'refuel' && (tags.length || customLabels.length) ? ( {tags?.map((tag) => { const formattedTag = tag.toLowerCase() const tooltipKey = `tooltip.${formattedTag}` as any const tooltipText = t(tooltipKey) const hasTooltip = tooltipText !== tooltipKey const cardLabel = ( {t(`main.tags.${formattedTag}` as any)} ) return hasTooltip ? ( {cardLabel} ) : ( cardLabel ) })} {customLabels.map((label, index) => ( {label.text} ))} ) : null} ) return mode === 'refuel' || variant === 'cardless' ? ( cardContent ) : ( {cardContent} ) }