import 'server-only'; import { fmtMoney } from '@/lib/format'; import { getDisplayCurrency } from '@/lib/auth/session'; import { latestRate } from './fx'; export interface Display { currency: string; rate: number; /** true when the requested currency had no FX rate and USD is shown instead */ fallback: boolean; money: (usd: number | null | undefined, opts?: { compact?: boolean; digits?: number }) => string; } /** Resolve the member's display currency and a formatter converting USD values at the latest rate. */ export async function getDisplay(): Promise { const currency = await getDisplayCurrency(); const rate = await latestRate(currency); const effective = rate ? currency : 'USD'; const r = rate ?? 1; return { currency: effective, rate: r, fallback: !rate && currency !== 'USD', money: (usd, opts) => (usd === null || usd === undefined ? '—' : fmtMoney(usd * r, effective, opts)), }; }