Skip to content

feat(order): show amount limits in fiat in the create order screen#605

Merged
grunch merged 4 commits into
mainfrom
improve-range-message
Jun 10, 2026
Merged

feat(order): show amount limits in fiat in the create order screen#605
grunch merged 4 commits into
mainfrom
improve-range-message

Conversation

@Catrya

@Catrya Catrya commented May 29, 2026

Copy link
Copy Markdown
Member

The range error now shows the limits in the fiat currency the user typed, with the sats range in parentheses.

Before: "...allows between 100 and 1000000 sats."
After: "...allows between 1 and 734 USD (100 - 1000000 sats)."

  • Pure fiatAmountLimits helper reuses the already-loaded rate (no extra calls)
  • Min rounds up, max rounds down, floored at 1 (field is integer-only)
  • Falls back to the sats message when the range collapses below 1 fiat
  • Localized in en/es/it/de/fr + helper unit tests
image

Summary by CodeRabbit

  • New Features
    • Order amount validation now shows range-aware error messages including both fiat and satoshi limits.
    • Amount input now displays the selected fiat currency in prompts and labels.
  • Localization
    • Added range-based fiat validation messages and updated currency-specific prompt strings for EN/DE/ES/FR/IT.
  • Tests
    • Added tests verifying fiat conversion, rounding, clamping and displayability logic for order amount limits.

Review Change Stack

Catrya added 2 commits May 29, 2026 13:18
  currency

  - Convert the node's sats min/max back to whole fiat
  using the loaded rate
  - Round min up / max down, floor min at 1 (field is
  integer-only, no decimals)
  - Fall back to the sats message when the range collapses
  below 1 fiat
  - Add pure fiatAmountLimits helper + unit tests; drop
  validation debugPrint
  currency

  - Convert the node's sats min/max back to whole fiat
  using the loaded rate
  - Round min up / max down, floor min at 1 (field is
  integer-only, no decimals)
  - Append the raw sats range in parentheses so users see
  why the fiat range moves
  - Fall back to the sats-only message when the range
  collapses below 1 fiat
  - Add pure fiatAmountLimits helper + unit tests; drop
  validation debugPrint
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: abcc7cfc-b97b-4772-a201-d14c6e16820b

📥 Commits

Reviewing files that changed from the base of the PR and between d099519 and b81bfef.

📒 Files selected for processing (7)
  • lib/features/order/screens/add_order_screen.dart
  • lib/features/order/widgets/amount_section.dart
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_it.arb
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/l10n/intl_de.arb
  • lib/features/order/screens/add_order_screen.dart
  • lib/l10n/intl_it.arb
  • lib/l10n/intl_en.arb

Walkthrough

Adds a fiat-conversion utility for satoshi bounds, integrates it into order validation to provide range-aware localized errors, passes the selected fiat code into the amount widget, adds unit tests for conversion logic, and updates localization keys/messages in five locale files.

Changes

Fiat amount range validation for orders

Layer / File(s) Summary
Fiat amount limits utility
lib/shared/utils/order_amount_limits.dart
New FiatAmountLimits and fiatAmountLimits() converting sats min/max to whole fiat units (ceil min, floor max, min clamped to 1, non-displayable when exchangeRate ≤ 0).
Fiat amount limits tests
test/shared/utils/order_amount_limits_test.dart
Tests rounding, minimum clamping, collapse-to-non-displayable behavior, and invalid exchange rate handling for fiatAmountLimits().
Validation refactor with range-aware errors
lib/features/order/screens/add_order_screen.dart
Imports the limits utility, refactors _validateSatsRange() to compute fiat-equivalent bounds and return new range-aware localized error messages when displayable, and wires selectedFiatCode into AmountSection.
AmountSection fiatCode API and title
lib/features/order/widgets/amount_section.dart
Adds optional fiatCode property and updates _getTitle() to derive a currency label from fiatCode and use currency-specific localized title strings.
Localized range validation error strings
lib/l10n/intl_en.arb, lib/l10n/intl_de.arb, lib/l10n/intl_es.arb, lib/l10n/intl_fr.arb, lib/l10n/intl_it.arb
Adds fiatAmountTooLowRange and fiatAmountTooHighRange keys with placeholder metadata (minAmount, maxAmount, fiatCode, minSats, maxSats) and replaces enterAmountYouWantToReceive/enterAmountYouWantToSend with currency-aware variants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • grunch
  • mostronator
  • AndreaDiazCorreia

Poem

A rabbit hops converting sats to pay,
Ceilings and floors keep limits at bay,
When fiat fits, the message sings clear,
Else fallback words quietly appear,
Five tongues now warn where amounts stray 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: displaying amount limits in fiat currency in the create order screen, which aligns with all file modifications across validation logic, localization, and UI components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve-range-message

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/shared/utils/order_amount_limits_test.dart`:
- Around line 19-27: The explanatory comment in the test for fiatAmountLimits is
wrong: the conversion for minSats=50 with exchangeRate=100000 yields
50/100000000*100000 = 0.05 (not 0.5); update the inline comment in the test case
(the one above the fiatAmountLimits call in order_amount_limits_test.dart) to
show "0.05" so it correctly documents the conversion while keeping the assertion
that the value is clamped to 1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4bafd724-20a1-44d6-bb52-544739b07021

📥 Commits

Reviewing files that changed from the base of the PR and between e46854f and 6d9918e.

📒 Files selected for processing (8)
  • lib/features/order/screens/add_order_screen.dart
  • lib/l10n/intl_de.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
  • lib/l10n/intl_fr.arb
  • lib/l10n/intl_it.arb
  • lib/shared/utils/order_amount_limits.dart
  • test/shared/utils/order_amount_limits_test.dart

Comment thread test/shared/utils/order_amount_limits_test.dart
mostronatorcoder[bot]
mostronatorcoder Bot previously approved these changes May 29, 2026

@mostronatorcoder mostronatorcoder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed the current revision and I do not see a blocking issue here.

What I checked:

  • The conversion logic is directionally correct for this UI: min rounds up, max rounds down, and the minimum is floored at 1 because the field only accepts whole fiat values.
  • The fallback to the sats-only message when the fiat range collapses below 1 is the right behavior; otherwise the user would see a fake whole-fiat range they cannot actually enter.
  • Reusing the already-loaded exchange rate is the right tradeoff here. This improves the message without adding extra fetches or cross-cutting changes.
  • The raw sats bounds are still appended in the range message, which is useful context and makes the moving fiat range less surprising.
  • The helper extraction and unit tests are good. They cover the important rounding/displayability cases rather than just snapshotting strings.

I only saw a minor doc/comment nit in the tests, not a functional problem. Approving this revision.

  - AmountSection takes the selected fiatCode and shows e.g. Enter the amount of USD you want to receive; falls back to fiat when none
  - Replace the generic enterAmount keys with currency-parameterized ones in en/es/it/de/fr
@Catrya

Catrya commented May 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mostronatorcoder mostronatorcoder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the latest head. I still do not see a blocking issue here.

The new follow-up change also looks fine to me:

  • Passing the selected fiatCode into AmountSection makes the prompt more explicit without changing validation semantics.
  • The null/empty fallback to the generic "fiat" label is reasonable, so the UI does not regress when the code is not selected yet.
  • The earlier conversion/range behavior still looks correct, and the test-comment nit was fixed.
  • CI is green.

Approved on the current revision.

@codaMW

codaMW commented Jun 10, 2026

Copy link
Copy Markdown
1000100790 - Copy tACK

Tested on Nokia C31 (Android 12), branch improve-range-message,
fiat currency MWK.

Scenarios tested:

  1. Amount too low (1 MWK) → error shows fiat range with sats in
    parentheses ✓
  2. Amount too high (999999 MWK) → correct upper bound error ✓
  3. Boundary value (639 MWK) → accepted without error ✓
  4. Valid amount (50000 MWK) → no error ✓

Observation investigated:
The error message showed minimum as 640 MWK while 639 MWK was
accepted. I investigated and confirmed this is expected behaviour:
at the current rate, 639 MWK converts to exactly 500 sats via
_calculateSatsFromFiat() (which uses .round()), so validation
passes. The displayed 640 comes from fiatAmountLimits() using
.ceil() on a floating point value of 639.something. The gap is
sub-1-MWK floating point imprecision at the boundary
1000100787 - Copy
1000100790 - Copy
not a
logic error.

Unit tests: 6/6 passing.

No issues found. The fiat-first error message is a meaningful UX
improvement for users who think in local currency.

@codaMW codaMW left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tACK

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@grunch grunch merged commit 338b48f into main Jun 10, 2026
2 checks passed
@grunch grunch deleted the improve-range-message branch June 10, 2026 20:31
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