refactor: split currency and key/metal formatting into separate units

this simplifies functions and tests, and will make currency optional/variable later
This commit is contained in:
xenticore
2025-04-16 14:04:39 -04:00
parent cb07930c6d
commit dcf45c2740
5 changed files with 51 additions and 19 deletions

View File

@@ -0,0 +1,8 @@
import { conversion_ref_usd } from '../config';
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
}

View File

@@ -7,7 +7,6 @@ function toFixed(num: number, fixed: number) {
}
export function formatPrice(keys: number, metal: number, keyPrice: number, locale: string = 'en') {
const pureMetal = (keys * keyPrice) + metal;
const formattedKeys = +(keys + (metal / keyPrice)).toFixed(2)
var output: string = ''
@@ -16,13 +15,6 @@ export function formatPrice(keys: number, metal: number, keyPrice: number, local
} else {
output += $T("%@ ref").replace('%@', (+toFixed(metal, 2)).toLocaleString(locale))
}
const currencyFormatter = new Intl.NumberFormat(locale, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
// Round price up to nearest cent
const price = Math.ceil(pureMetal * conversion_ref_usd * 100) / 100
output += ` (US$${currencyFormatter.format(price)})`
return output;
}