fix: pin toLocaleString() calls to en-US locale - #1400
Conversation
Several number formatting call sites relied on the host machine's default locale instead of a fixed one, causing inconsistent digit grouping in the UI and non-deterministic test failures on non-US locales.
|
Hey @GuTS805! Thanks for the ticket and fix. Can you take a look at https://github.com/GuTS805/jam/blob/986aea014c5643e223584ba091ff1a71fa0582fb/src/lib/utils.test.ts#L40 ? Maybe this approach can be generalized. I don't think a fix should include hardcoding the locale in components, but rather only adapt the tests to setup everything correctly (i.e. setup various locales). What do you think? |
kishore08-07
left a comment
There was a problem hiding this comment.
Thanks for the PR! While this fixes the test failures, but hardcoding 'en-US' directly in the ui components has a few drawbacks:
- breaks i18n support,
- could lead to inconsistent ui: balances (btc/sats) will still format using the user's browser locale, creating a mix of formatting styles on the same screen.
|
Thanks both for the feedback. good points on hardcoding the locale in components. I've reworked this:
Tests now pass deterministically regardless of the machine's locale, and the UI behavior is unchanged. Let me know if this matches what you had in mind. |
theborakompanioni
left a comment
There was a problem hiding this comment.
utACK.
CI would need to run in a different locale than en-US to be sure this does not break again. Good follow-up?
|
Good point. Happy to look into adding a non-en-US locale to the CI test matrix as a follow-up (either a separate PR or a tracking issue, whichever you'd prefer). |
Closes #1398
Pins the remaining unpinned
toLocaleString()calls (block heights, fee rates, offer/fidelity-bond sizes, scheduled-transaction counts) toen-US, so number formatting is consistent regardless of the host machine's locale.Also fixed
ImportDetailsForm.test.tsx, which built its expected string using an unpinnedtoLocaleString()and would otherwise mismatch the now-pinned component output.Tested:
npx vitest run --project unit— 264/264 relevant tests pass.tsc -bbuild clean.