-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HelpScout 1199960 - Fixing intlFormat.ts error when currency is not defined #987
Conversation
Bundle sizes [mpdx-react]Compared against 1b734b6 No significant changes found |
Preview branch generated at https://fix-intl-format-error.d3dytjb8adxkk5.amplifyapp.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, not sure I can add much insight into your PR's but I added a few thoughts.
minimumFractionDigits: decimal ? 2 : 0, | ||
maximumFractionDigits: decimal ? 2 : 0, | ||
}).format(Number.isFinite(amount) ? amount : 0); | ||
if (!currency) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get the same effect by giving it default argument of USD? I guess in that case we’d have to give locale a default as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what we had before with currency ?? 'USD'
, but for some reason it was still causing an error. Adding the if statement it prevent the error from happening.
|
||
it('handles an error', () => { | ||
expect(currencyFormat(1234.56, ' ', 'en-GB')).toEqual('1234.56 '); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know what happens if an absurd currency is given?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is and it causes an error, we will revert to only returning the total amount with the currency in the text after it.
See line 36 on src/lib/intlFormat.ts
I'm getting a server error from the preview. I'm assuming it's unrelated. |
Description
In this PR, I've fixed an error that happens when the currency is not defined. If the currency is not defined, it shows the white screen of death.
I've ensured the currency is defined and that even if it fails, it will return some value to prevent the white screen of death from happening.
HelpScout issue: https://secure.helpscout.net/conversation/2666844539/1199960?folderId=7296147
To Test:
Checklist: