feat: three nuxt frontends, demo seed, rounding + money-exponent + rate-cast fixes, archived specs

This commit is contained in:
Chengdong Zhang
2026-09-17 13:34:38 +08:00
parent dc9fd31c5e
commit 653f13161a
85 changed files with 4327 additions and 106 deletions
+25
View File
@@ -0,0 +1,25 @@
import { formatMoney } from "@vmall/shared";
import type { Currency } from "@vmall/shared";
/** Currency-aware money formatter: exponents come from the API, cached app-wide. */
export function useMoney() {
const { $api } = useNuxtApp();
const { locale } = useI18n();
const currencies = useState<Currency[]>("vmall.currencies", () => []);
async function load(): Promise<void> {
if (currencies.value.length > 0) return;
try {
currencies.value = await $api.listCurrencies();
} catch {
/* keep empty; fmt falls back to exponent 2 */
}
}
function fmt(amountMinor: number, currency: string): string {
const exponent = currencies.value.find((c) => c.code === currency)?.exponent ?? 2;
return formatMoney(amountMinor, currency, exponent, locale.value);
}
return { currencies, load, fmt };
}