fix, feat: add currency conversion stub

uses proper JS api for currency formatting and preparations for showing other currencies based on page locale
This commit is contained in:
xenticore
2025-04-16 14:53:34 -04:00
parent dcf45c2740
commit 84daf5b2d6
2 changed files with 58 additions and 7 deletions

View File

@@ -1,8 +1,47 @@
import { conversion_ref_usd } from '../config';
export function defaultCurrencyForPageLocale(locale: string): string | null {
switch (locale) {
case 'de':
case 'fr':
case 'it':
case 'nl':
case 'hu':
return 'EUR';
case 'ja':
return 'JPY';
case 'tr':
return 'TRY';
case 'da':
return 'DKK';
case 'pt-br':
return 'BRL';
case 'zh-hans':
case 'zh-hant':
return 'CNY';
case 'ko':
return 'KRW';
case 'cs':
return 'CZK';
case 'ru':
return 'RUB';
case 'pl':
return 'PLN';
default:
return null;
}
}
export function convertTF2PriceToUSD(keys: number, metal: number, keyPrice: number): number {
const pureMetal = (keys * keyPrice) + metal;
// Round price up to nearest cent
return Math.ceil(pureMetal * conversion_ref_usd * 100) / 100
}
export function convertUSD(usd: number, currency: string): number {
const cur = currency.toUpperCase()
if(cur === 'USD') return usd
throw new Error(`Not implemented`)
}