feat: three nuxt frontends, demo seed, rounding + money-exponent + rate-cast fixes, archived specs
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user