FEC-365: Extend UI-kit MoneyInput with Non-Iso Currencies#3223
Conversation
🦋 Changeset detectedLatest commit: 573f2e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 98 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…out specified value
ByronDWall
left a comment
There was a problem hiding this comment.
This is a good safeguard and I'm going to approve, but I think it's worth considering a less naive fallback for the fractionDigits than always defaulting to 2.
| currencyCode, | ||
| centAmount: NaN, | ||
| fractionDigits: allCurrencies[currencyCode].fractionDigits, | ||
| fractionDigits: allCurrencies[currencyCode].fractionDigits ?? 2, |
There was a problem hiding this comment.
It's more verbose, but I think it would make sense to get the CLDR fraction digits for a currency code, I think the error state if the currency code isn't ISO standard when it has no fractionDigits would be very helpful. Also, I could see future issues if we naively default to 2.
| fractionDigits: allCurrencies[currencyCode].fractionDigits ?? 2, | |
| let fractionDigits = allCurrencies[currencyCode].fractionDigits; | |
| if(!fractionDigits){ | |
| const formatter = new Intl.NumberFormat(locale, { | |
| style: "currency", | |
| currencyCode | |
| }); | |
| // KRW → 0, USD → 2, BHD → 3 | |
| const { minimumFractionDigits } = formatter.resolvedOptions(); | |
| let fractionDigits = minimumFractionDigits; | |
| } | |
| const createEmptyMoneyValue = (currencyCode: TCurrencyCode): TMoneyValue => ({ | |
| type: 'centPrecision', | |
| currencyCode, | |
| centAmount: NaN, | |
| fractionDigits | |
| }); | |
There was a problem hiding this comment.
It does make sense, I mean it changes a default to the correct default, but it also changes existing behavior. Personally I can't foresee possible side-effects, but I can imagine there are some so this is probably better tackled in its own ticket.
@ByronDWall Thx for pointing this out |
Summary
This PR adds support for non-ISO currency variants (HUF0, KZT0,...) in the currency lookup table from
MoneyInputThis change is needed so that non-ISO currencies are correctly recognized and handled in the Merchant Center money inputs.
https://commercetools.atlassian.net/browse/FEC-354