Repository navigation
feat(ui): parse DashSpend amount locale-agnostically so comma decimals aren't dropped - #852
Merged
Merged
Conversation
… aren't truncated The DashSpend flexible-amount confirmation and single/multiple toggle read the typed amount via String.decimal(), i.e. Decimal(string:locale:) with a nil locale. That only recognizes '.' as the decimal mark, so on a comma-decimal locale it stops at the comma and truncates '5,5' to 5, silently dropping the fraction. The '?? viewModel.amount' fallback never fires because the naive parse returns a (wrong) non-nil value. Route both call sites through PastedAmountParser.parse, the region-agnostic parser the view model already feeds 'amount' from, so every path agrees.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue being fixed or feature implemented
On a comma-decimal locale (e.g. UK/most of Europe, device shows
11,83 US$), entering a fractional DashSpend gift-card amount such as5.5or5.9silently drops the fraction and buys5.Root cause: the flexible-amount confirmation (
DashSpendPayScreen.handlePayAction) and the single/multiple segment toggle (DashSpendFlexibleContent) read the typed amount viaString.decimal(), which isDecimal(string:locale:)with anillocale. That only recognizes.as the decimal mark, so on a comma locale the input string"5,5"parses only up to the comma and returns5. The?? viewModel.amountfallback never fires because the naive parse returns a (wrong) non-nil value, so the correctviewModel.amount(5.5, already computed via the region-agnostic parser) is discarded.What was done?
Routed both call sites through
PastedAmountParser.parse(_:locale:)— the same region-agnostic parser the view model already feedsamountfrom (a single.or,is always the decimal separator). Now every code path agrees on the entered amount regardless of device locale.How Has This Been Tested?
Root-caused from code:
Decimal(string: "5,5", locale: nil) == 5, and the input string carries the locale separator (the view model validates the fractional part againstLocale.current.decimalSeparator). Fix verified by inspection against the shared parser's behavior. Not yet run through a device build — recommend a testnet smoke on a comma-decimal locale: enter5.5/5.9for a flexible gift-card amount and confirm the fraction is preserved at the confirmation screen; regression-check a.-decimal locale still works.Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only