2
0

🐛 (billing) Fix currency possible mismatch on sub update

This commit is contained in:
Baptiste Arnaud
2022-11-29 13:17:46 +01:00
parent 43a85b5529
commit f9ffdbc4c5
7 changed files with 18 additions and 5 deletions

View File

@ -176,11 +176,11 @@ export const guessIfUserIsEuropean = () =>
: europeanUnionExclusiveLanguageCodes.includes(languageCode)
})
export const formatPrice = (price: number) => {
export const formatPrice = (price: number, currency?: 'eur' | 'usd') => {
const isEuropean = guessIfUserIsEuropean()
const formatter = new Intl.NumberFormat(isEuropean ? 'fr-FR' : 'en-US', {
style: 'currency',
currency: isEuropean ? 'EUR' : 'USD',
currency: currency?.toUpperCase() ?? (isEuropean ? 'EUR' : 'USD'),
maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
})
return formatter.format(price)