Skip to content

feat(ui): parse DashSpend amount locale-agnostically so comma decimals aren't dropped - #852

Merged
romchornyi merged 1 commit into
swift-sdk-integrationfrom
fix/dashspend-decimal-locale
Jul 22, 2026
Merged

romchornyi merged 1 commit into
swift-sdk-integrationfrom
fix/dashspend-decimal-locale

Conversation

@romchornyi

Copy link
Copy Markdown
Contributor

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 as 5.5 or 5.9 silently drops the fraction and buys 5.

Root cause: the flexible-amount confirmation (DashSpendPayScreen.handlePayAction) and the single/multiple segment toggle (DashSpendFlexibleContent) read the typed amount via String.decimal(), which is Decimal(string:locale:) with a nil locale. That only recognizes . as the decimal mark, so on a comma locale the input string "5,5" parses only up to the comma and returns 5. The ?? viewModel.amount fallback never fires because the naive parse returns a (wrong) non-nil value, so the correct viewModel.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 feeds amount from (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 against Locale.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: enter 5.5/5.9 for 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:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

… 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.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a752dc5d-94f0-4f3b-8fd6-8a9e68d74a4c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dashspend-decimal-locale

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@romchornyi
romchornyi merged commit 348b6fd into swift-sdk-integration Jul 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants