import { DoubleDownArrow } from '@/components/icons/DoubleDownArrow' import { useBridgeState } from '@/state/slices/bridge/hooks' import { CHAINS_BY_ID } from '@/constants/chains' import { formatBigIntToString } from '@/utils/formatBigIntToString' const formatBridgeFee = ( nativeFee: bigint | undefined, nativePrecision: number | undefined ) => { if (!nativePrecision || typeof nativeFee !== 'bigint' || nativeFee <= 0n) { return null } const fullPrecision = formatBigIntToString( nativeFee, nativePrecision, nativePrecision ) if (!fullPrecision) { return null } const [whole, fraction = ''] = fullPrecision.split('.') const trimmedFraction = fraction.replace(/0+$/, '') if (!trimmedFraction) { return whole } const firstNonZero = trimmedFraction.search(/[1-9]/) const decimalPlaces = whole === '0' ? Math.min(trimmedFraction.length, Math.max(4, firstNonZero + 2)) : Math.min(trimmedFraction.length, 4) const visibleFraction = trimmedFraction.slice(0, decimalPlaces) return visibleFraction ? `${whole}.${visibleFraction}` : whole } const getEstimatedTimeLabel = (estimatedTime?: number | null) => { if (!estimatedTime) { return null } if (estimatedTime > 60) { return `${Math.ceil(estimatedTime / 60)} minutes` } return `${estimatedTime} seconds` } const getFormattedBridgeFee = ({ nativeFee, originChainId, isValidQuote, loading, }: { nativeFee: bigint | undefined originChainId?: number isValidQuote: boolean loading: boolean }) => { if (!originChainId || !isValidQuote || loading) { return null } return formatBridgeFee( nativeFee, CHAINS_BY_ID[originChainId]?.nativeCurrency.decimals ) } export const Receipt = ({ quote, loading, send, receive }) => { const { originChainId, destinationChainId } = useBridgeState() const estTime = getEstimatedTimeLabel(quote?.estimatedTime) const isValidQuote = Boolean(quote.outputAmount) const nativeFeeSymbol = originChainId ? CHAINS_BY_ID[originChainId]?.nativeCurrency.symbol : null const formattedBridgeFee = getFormattedBridgeFee({ nativeFee: quote?.nativeFee, originChainId, isValidQuote, loading, }) const shouldShowBridgeFee = Boolean(formattedBridgeFee) return (
{loading ? ( <> fetching... ) : isValidQuote ? ( <> {' '} {estTime} via {quote?.bridgeModuleName} {' '} ) : (
Powered by  Synapse
)}
Router
{loading ? '...' : isValidQuote ? quote?.bridgeModuleName : '-'}
Origin
{originChainId ? CHAINS_BY_ID[originChainId]?.name : '-'}
Destination
{destinationChainId ? CHAINS_BY_ID[destinationChainId]?.name : '-'}
Send
{send ? send : '-'}
{shouldShowBridgeFee && ( <>
Bridge fee
{formattedBridgeFee} {nativeFeeSymbol ? ` ${nativeFeeSymbol}` : ''}
)}
Receive
{loading ? '...' : isValidQuote ? receive : '-'}
) }