TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import 'server-only';2import { fmtMoney } from '@/lib/format';3import { getDisplayCurrency } from '@/lib/auth/session';4import { latestRate } from './fx';56export interface Display {7 currency: string;8 rate: number;9 /** true when the requested currency had no FX rate and USD is shown instead */10 fallback: boolean;11 money: (usd: number | null | undefined, opts?: { compact?: boolean; digits?: number }) => string;12}1314/** Resolve the member's display currency and a formatter converting USD values at the latest rate. */15export async function getDisplay(): Promise<Display> {16 const currency = await getDisplayCurrency();17 const rate = await latestRate(currency);18 const effective = rate ? currency : 'USD';19 const r = rate ?? 1;20 return {21 currency: effective,22 rate: r,23 fallback: !rate && currency !== 'USD',24 money: (usd, opts) => (usd === null || usd === undefined ? '—' : fmtMoney(usd * r, effective, opts)),25 };26}27