wip(freight): migration 0017 + model/column-list groundwork for add-freight-templates
This commit is contained in:
@@ -12,12 +12,15 @@ export function usePrice() {
|
||||
async function ensureCurrencies(): Promise<Currency[]> {
|
||||
if (currencies.value.length > 0) return currencies.value;
|
||||
if (!currencyRequest.value) {
|
||||
currencyRequest.value = $api.listCurrencies().then((list) => {
|
||||
currencies.value = list;
|
||||
return list;
|
||||
}).finally(() => {
|
||||
currencyRequest.value = null;
|
||||
});
|
||||
currencyRequest.value = $api
|
||||
.listCurrencies()
|
||||
.then((list) => {
|
||||
currencies.value = list;
|
||||
return list;
|
||||
})
|
||||
.finally(() => {
|
||||
currencyRequest.value = null;
|
||||
});
|
||||
}
|
||||
return currencyRequest.value;
|
||||
}
|
||||
@@ -26,7 +29,11 @@ export function usePrice() {
|
||||
return currencies.value.find((item) => item.code === code)?.exponent ?? 2;
|
||||
}
|
||||
|
||||
async function convertAmount(amountMinor: number, from: string, to = currency.value): Promise<number> {
|
||||
async function convertAmount(
|
||||
amountMinor: number,
|
||||
from: string,
|
||||
to = currency.value,
|
||||
): Promise<number> {
|
||||
if (from === to) return amountMinor;
|
||||
const key = `${amountMinor}:${from}:${to}`;
|
||||
const cached = cache.value.get(key);
|
||||
@@ -36,7 +43,11 @@ export function usePrice() {
|
||||
return converted.amount_minor;
|
||||
}
|
||||
|
||||
async function formatPrice(amountMinor: number, from: string, to = currency.value): Promise<string> {
|
||||
async function formatPrice(
|
||||
amountMinor: number,
|
||||
from: string,
|
||||
to = currency.value,
|
||||
): Promise<string> {
|
||||
await ensureCurrencies();
|
||||
const amount = await convertAmount(amountMinor, from, to);
|
||||
return formatMoney(amount, to, exponentFor(to), locale.value);
|
||||
|
||||
Reference in New Issue
Block a user