You've already forked tf2wikipricing
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:
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user