Change currency config to required

It'll default to `$` and `en-US` when the config is generated through the `nodecg defaultconfig` command
This commit is contained in:
Lordmau5 2024-03-14 09:14:49 +01:00
parent 4d521b4e12
commit a422777f71
4 changed files with 16 additions and 13 deletions

View File

@ -109,13 +109,18 @@
"type": "string", "type": "string",
"default": "en-US" "default": "en-US"
} }
} },
"required": [
"symbol",
"countryCode"
]
} }
}, },
"required": [ "required": [
"shorts", "shorts",
"thisEvent", "thisEvent",
"online" "online",
"currency"
] ]
}, },
"omnibar": { "omnibar": {

View File

@ -36,10 +36,8 @@ export function msToTimeStr(ms: number): string {
/** /**
* Simple formatter for displaying currency amounts. * Simple formatter for displaying currency amounts.
* @param amount Amount as a integer/float. * @param amount Amount as a integer/float.
* @param _symbol The currency symbol * @param _symbol The currency symbol (defaults to what's set in the config)
* (defaults to what's set in the config, or `$` if the config isn't set) * @param _countryCode The country code (defaults to what's set in the config)
* @param _countryCode The country code
* (defaults to what's set in the config, or `en-US` if the config isn't set)
*/ */
export function formatCurrency( export function formatCurrency(
amount: number, amount: number,
@ -47,8 +45,8 @@ export function formatCurrency(
_countryCode?: string, _countryCode?: string,
): string { ): string {
const cfg = (config as DeepWritable<Configschema>).event.currency; const cfg = (config as DeepWritable<Configschema>).event.currency;
const symbol = _symbol || cfg?.symbol || '$'; const symbol = _symbol || cfg.symbol;
const countryCode = _countryCode || cfg?.countryCode || 'en-US'; const countryCode = _countryCode || cfg.countryCode;
if (amount >= 100) { if (amount >= 100) {
return `${symbol}${Math.floor(amount).toLocaleString( return `${symbol}${Math.floor(amount).toLocaleString(

View File

@ -155,8 +155,8 @@ export default class extends Vue {
get totalStr(): string { get totalStr(): string {
// "Reset" value every 10k, specific to ESA Legends 2023. // "Reset" value every 10k, specific to ESA Legends 2023.
const symbol = nodecg.bundleConfig.event.currency?.symbol || '$'; const symbol = nodecg.bundleConfig.event.currency.symbol;
const countryCode = nodecg.bundleConfig.event.currency?.countryCode || 'en-US'; const countryCode = nodecg.bundleConfig.event.currency.countryCode;
const esal23 = nodecg.bundleConfig.event.shorts === 'esal23'; const esal23 = nodecg.bundleConfig.event.shorts === 'esal23';

View File

@ -13,9 +13,9 @@ export interface Configschema {
thisEvent: number; thisEvent: number;
online: boolean | ("partial" | "full"); online: boolean | ("partial" | "full");
fallbackTwitchTitle?: string; fallbackTwitchTitle?: string;
currency?: { currency: {
symbol?: string; symbol: string;
countryCode?: string; countryCode: string;
}; };
}; };
omnibar: { omnibar: {