feat: add currency conversions to price table

Exchange rates are loaded once per page and passed to price row generation, so we don't hit the cache more than once.
This commit is contained in:
xenticore
2025-04-16 18:24:27 -04:00
parent fcf077c877
commit 1d92d9e20c
3 changed files with 12 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import { conversion_ref_usd } from '../config';
import { ExchangeRates } from '../exchangeRateService';
export function defaultCurrencyForPageLocale(locale: string): string | null {
switch (locale) {
@@ -39,9 +40,9 @@ export function convertTF2PriceToUSD(keys: number, metal: number, keyPrice: numb
return Math.ceil(pureMetal * conversion_ref_usd * 100) / 100
}
export function convertUSD(usd: number, currency: string): number {
export function convertUSD(usd: number, currency: string, rates: ExchangeRates): number {
const cur = currency.toUpperCase()
if(cur === 'USD') return usd
throw new Error(`Not implemented`)
return usd * rates[cur]
}