import { Box, Stack, Typography } from '@mui/material'; import { useLocaleContext } from '@arcblock/ux/lib/Locale/context'; import { tSafe } from '../../utils/format'; interface TotalDisplayProps { label?: string; total: string; usdEquivalent?: string | null; } // Split a price string like "1,234.56 TBA" into parts for display function splitPrice(total: string): { prefix: string; integer: string; decimal: string; suffix: string } { if (!total) return { prefix: '', integer: '0', decimal: '', suffix: '' }; const trimmed = total.trim(); // Handle "$X.XX" format if (trimmed.startsWith('$')) { const numPart = trimmed.slice(1).trim(); const dotIdx = numPart.indexOf('.'); if (dotIdx >= 0) { return { prefix: '$', integer: numPart.slice(0, dotIdx), decimal: `.${numPart.slice(dotIdx + 1)}`, suffix: '', }; } return { prefix: '$', integer: numPart, decimal: '', suffix: '' }; } // Handle "123.45 TBA" or "0 TBA" format const parts = trimmed.split(/\s+/); const numStr = parts[0] || '0'; const unit = parts.slice(1).join(' '); const dotIdx = numStr.indexOf('.'); if (dotIdx >= 0) { return { prefix: '', integer: numStr.slice(0, dotIdx), decimal: `.${numStr.slice(dotIdx + 1)}`, suffix: unit, }; } return { prefix: '', integer: numStr, decimal: '', suffix: unit }; } export default function TotalDisplay({ label = undefined, total, usdEquivalent = undefined }: TotalDisplayProps) { const { t } = useLocaleContext(); const { prefix, integer, decimal, suffix } = splitPrice(total); return ( {/* Left: label + promo link */} {label || tSafe(t, 'payment.checkout.totalDueToday', 'Total due today')} {/* Right: big price */} {/* Currency symbol / prefix */} {prefix && ( {prefix} )} {/* Integer part — extra large */} {integer} {/* Decimal part — lighter */} {decimal && ( {decimal} )} {/* Currency unit */} {suffix && ( {suffix} )} {/* USD equivalent */} {usdEquivalent && ( ≈ {usdEquivalent} )} ); }