import { dateLocaleCode } from '@/lib/dateFnsI18n'; import { useMemo } from 'react'; import { Lock } from 'lucide-react'; import { parseEscrowToken, type EscrowTokenInfo } from '@/lib/cashuEscrow'; import { cn } from '@/lib/utils'; import { useTranslation } from '@/contexts/language'; function hostOf(url: string): string { try { return new URL(url).host; } catch { return url; } } function formatDate(seconds: number): string { return new Date(seconds * 1000).toLocaleDateString(dateLocaleCode(), { year: 'numeric', month: 'short', day: 'numeric', }); } /** * Read-only escrow summary for a locked Cashu token. Pure/offline (uses * `parseEscrowToken`), so it renders on web as well as native — only the * mint-touching create/redeem actions are native-only. */ export function EscrowPanel({ token, className }: { token: string; className?: string }) { const { t } = useTranslation(); const info = useMemo(() => { try { return parseEscrowToken(token); } catch { return null; } }, [token]); if (!info || !info.locked) return null; const locktime = info.policy?.locktime; return (
{t('marketUi.escrowPanel.escrowed', { amount: info.amount.toLocaleString() })}

{t('marketUi.escrowPanel.mint')}: {hostOf(info.mint)}

{locktime ? (

{info.refundable ? ( <>{t('marketUi.escrowPanel.refundSinceBefore')}{' '} {formatDate(locktime)} ) : ( <>{t('marketUi.escrowPanel.redeemBefore')}{' '} {formatDate(locktime)} )}

) : (

{t('marketUi.escrowPanel.noExpiry')}

)}
); }