33 lines
980 B
JavaScript
33 lines
980 B
JavaScript
// Single source of truth for billing currencies on the frontend.
|
|
|
|
export const DEFAULT_BILLING_CURRENCY = 'usd';
|
|
|
|
// Order here drives the order of the currency toggle in the UI.
|
|
export const SUPPORTED_BILLING_CURRENCIES = ['usd', 'brl'];
|
|
|
|
export const BILLING_CURRENCY_CONFIG = {
|
|
usd: {
|
|
code: 'usd',
|
|
intlLocale: 'en-US',
|
|
i18nLabelKey: 'BILLING_SETTINGS.CURRENCY.OPTIONS.USD',
|
|
},
|
|
brl: {
|
|
code: 'brl',
|
|
intlLocale: 'pt-BR',
|
|
i18nLabelKey: 'BILLING_SETTINGS.CURRENCY.OPTIONS.BRL',
|
|
},
|
|
};
|
|
|
|
export const getCurrencyConfig = code =>
|
|
BILLING_CURRENCY_CONFIG[(code || DEFAULT_BILLING_CURRENCY).toLowerCase()] ||
|
|
BILLING_CURRENCY_CONFIG[DEFAULT_BILLING_CURRENCY];
|
|
|
|
export const formatCurrencyAmount = (amount, code, options = {}) => {
|
|
const { intlLocale, code: currencyCode } = getCurrencyConfig(code);
|
|
return new Intl.NumberFormat(intlLocale, {
|
|
style: 'currency',
|
|
currency: currencyCode.toUpperCase(),
|
|
...options,
|
|
}).format(amount);
|
|
};
|