-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1063 from sharetribe/update-currency-config
Update currency config
- Loading branch information
Showing
5 changed files
with
56 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// See: https://en.wikipedia.org/wiki/ISO_4217 | ||
// See: https://stripe.com/docs/currencies | ||
export const subUnitDivisors = { | ||
AUD: 100, | ||
CAD: 100, | ||
CHF: 100, | ||
CNY: 100, | ||
DKK: 100, | ||
EUR: 100, | ||
GBP: 100, | ||
HKD: 100, | ||
INR: 100, | ||
JPY: 1, | ||
MXN: 100, | ||
NOK: 100, | ||
NZD: 100, | ||
SEK: 100, | ||
SGD: 100, | ||
USD: 100, | ||
}; | ||
|
||
// Currency formatting options. | ||
// See: https://github.com/yahoo/react-intl/wiki/API#formatnumber | ||
export const currencyConfiguration = currency => { | ||
if (!subUnitDivisors[currency]) { | ||
throw new Error(`Configuration missing for currency: ${currency}.`); | ||
} | ||
|
||
return subUnitDivisors[currency] === 1 | ||
? { | ||
style: 'currency', | ||
currency, | ||
currencyDisplay: 'symbol', | ||
useGrouping: true, | ||
// If the currency is not using subunits (like JPY), remove fractions. | ||
minimumFractionDigits: 0, | ||
maximumFractionDigits: 0, | ||
} | ||
: { | ||
style: 'currency', | ||
currency, | ||
currencyDisplay: 'symbol', | ||
useGrouping: true, | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.