Skip to content

feat(#281): currency-aware payment method suggestions in create-order form - #297

Merged
Catrya merged 2 commits into
MostroP2P:mainfrom
codaMW:feat/281-currency-aware-payment-methods
Aug 11, 2026
Merged

feat(#281): currency-aware payment method suggestions in create-order form#297
Catrya merged 2 commits into
MostroP2P:mainfrom
codaMW:feat/281-currency-aware-payment-methods

Conversation

@codaMW

@codaMW codaMW commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Problem

The create-order form showed a single hardcoded list of 10 generic payment methods (_commonMethods in payment_method_section.dart) regardless of the selected fiat currency. A user trading ARS saw Zelle or SEPA, while locally relevant options (MODO, CVU, etc.) were missing and had to be typed by hand.

Solution (v1 parity)

Ports the v1 mobile approach:

  • Adds assets/data/payment_methods.json a currency code -> payment methods map covering 28 currencies plus a default fallback (copied from the v1 mobile app), and registers it in pubspec.yaml.
  • Adds paymentMethodsForCurrencyProvider (lib/features/order/providers/payment_methods_provider.dart):
    • paymentMethodsDataProvider a FutureProvider that loads and decodes the asset once.
    • paymentMethodsForCurrencyProvider a Provider.family<List<String>, String> that returns the list for a given currency, falling back to the default list (and then a hardcoded fallback) for unknown currencies. Returns an empty list while the asset is still loading, so the section renders its custom field without flashing placeholder chips.
  • Wires PaymentMethodSection to be currency-aware:
    • The method picker now shows the list for the currently selected fiat currency (selectedFiatCodeProvider) instead of the hardcoded _commonMethods.
    • When the currency changes, a ref.listen prunes any selected methods that are no longer valid for the new currency.
    • The custom free-text field is left untouched, as specified.
  • Removes the now-unused _commonMethods constant.

Testing

  • Contract test (test/features/order/providers/payment_methods_provider_test.dart): validates the shipped asset and the lookup contract a default fallback plus 20+ currencies, a known currency (ARS) resolves to its specific list, the African currencies added in #625/#627 (MWK -> Airtel Money, KES -> M-PESA) are present, and an unknown currency falls back to default.
  • Verified on a physical device (Nokia C31): the method list updates per selected currency, and selections that are no longer valid clear automatically when the currency changes.
  • flutter analyze clean across the order feature and tests.
1000254410 1000254413 1000254415 1000254412 1000254411 1000254414

Notes

  • The provider reads the asset via rootBundle at runtime; the contract test validates the same lookup logic against the shipped JSON directly (asset loading through rootBundle isn't wired for plain unit tests), while the full provider wiring is exercised on-device.

Closes #281.

Summary by CodeRabbit

  • New Features
    • Added currency-specific payment method options, including digital wallets, bank transfers, cash payments, and other services.
    • Payment methods now update automatically when the selected fiat currency changes.
    • Added fallback payment options when currency-specific methods are unavailable.

…ate-order form

The create-order form showed one hardcoded list of generic methods regardless
of the selected currency. Port the v1 approach: ship assets/data/payment_methods.json
(currency -> methods, 28 currencies + a default fallback) and a currency-aware
provider, and make the payment-method picker show the list matching the selected
fiat currency (falling back to default for unknown currencies). When the currency
changes, selections that are no longer valid are pruned; the custom free-text
field is left untouched.

Verified on a physical device (Nokia C31): the method list updates per currency
and stale selections clear on currency switch. Adds a test covering the
currency->list contract and the default fallback.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@codaMW, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 93a07e0e-e23d-4286-ac40-6674265b0c4a

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6e74a and 07a05e0.

📒 Files selected for processing (2)
  • lib/features/order/widgets/payment_method_section.dart
  • test/features/order/providers/payment_methods_provider_test.dart

Walkthrough

The order form now loads payment methods from a bundled currency mapping. Providers resolve currency-specific and fallback methods. The payment picker updates when fiat currency changes and removes unsupported selections. Provider tests validate asset loading and lookup behavior.

Changes

Currency-aware payment methods

Layer / File(s) Summary
Payment method data and lookup
assets/data/payment_methods.json, pubspec.yaml, lib/features/order/providers/payment_methods_provider.dart, test/features/order/providers/payment_methods_provider_test.dart
The asset defines payment methods by currency and a default entry. Riverpod providers load and resolve the mappings. Tests validate currency coverage and fallback behavior.
Order form payment picker
lib/features/order/widgets/payment_method_section.dart
The form requests methods for the selected fiat currency, removes unsupported selections after currency changes, and passes the available methods to the picker dialog.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant PaymentMethodSection
  participant PaymentMethodsProvider
  participant MethodPickerDialog
  User->>PaymentMethodSection: select fiat currency
  PaymentMethodSection->>PaymentMethodsProvider: request methods for currency
  PaymentMethodsProvider-->>PaymentMethodSection: return supported methods
  PaymentMethodSection->>PaymentMethodSection: remove unsupported selections
  User->>MethodPickerDialog: open payment method picker
  MethodPickerDialog-->>PaymentMethodSection: return selected methods
Loading

Poem

A rabbit hops through currencies bright,
Finds local methods, sorted right.
Old choices fade when currencies change,
New picker chips appear in range.
The fallback waits for paths unknown—
Then carrots mark the mapping shown.

🚥 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 describes the currency-aware payment method suggestions added to the create-order form.
Linked Issues check ✅ Passed The changes implement #281 by adding the v1 mapping, currency lookup, fallback behavior, selection pruning, and custom text preservation.
Out of Scope Changes check ✅ Passed All changes support #281 and include the asset, providers, UI integration, asset registration, and focused tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 3

🤖 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 `@assets/data/payment_methods.json`:
- Around line 2-30: In assets/data/payment_methods.json, add localization
entries for every payment-method label, including the default fallback labels,
while preserving each existing value exactly. Update
payment_methods_provider.dart to resolve these labels for picker display and
payment_method_section.dart to resolve labels for selected chips; keep
serialized and comparison values unchanged so presets, order filters, and
NewOrderParams.paymentMethod continue using the original strings.

In `@lib/features/order/widgets/payment_method_section.dart`:
- Around line 48-56: The currency-change listener around
selectedFiatCodeProvider must not prune selections when
paymentMethodsDataProvider is still loading; gate the valid-method lookup and
pruning until the provider has produced data, preserving selections during the
loading interval. Add a test covering a currency change before the asset future
completes and verify existing selections remain intact.

In `@test/features/order/providers/payment_methods_provider_test.dart`:
- Around line 6-15: The tests currently duplicate the provider’s asset-loading
and currency-fallback logic instead of exercising the providers. Replace direct
use of _loadShipped and _forCurrency with ProviderContainer tests that await
paymentMethodsDataProvider.future and override it when testing
paymentMethodsForCurrencyProvider for known, default, and loading cases; retain
separate assertions for the asset contract, then run flutter analyze and flutter
test.
🪄 Autofix

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 Plus

Run ID: b2974020-266e-4c77-8be6-ff8842012a40

📥 Commits

Reviewing files that changed from the base of the PR and between fc6dc71 and 1f6e74a.

📒 Files selected for processing (5)
  • assets/data/payment_methods.json
  • lib/features/order/providers/payment_methods_provider.dart
  • lib/features/order/widgets/payment_method_section.dart
  • pubspec.yaml
  • test/features/order/providers/payment_methods_provider_test.dart

Comment thread assets/data/payment_methods.json
Comment thread lib/features/order/widgets/payment_method_section.dart
Comment thread test/features/order/providers/payment_methods_provider_test.dart Outdated
…loading

The currency-change listener pruned selected methods against the currency
provider, which returns an empty list until the asset loads — so a currency
change before the load wiped every selection. Gate pruning on the data provider
having resolved. Rework the provider tests to exercise the real providers via a
ProviderContainer with an overridden data source (known, default, and loading
cases), keeping the shipped-asset contract assertions separate.
@codaMW

codaMW commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

#281 is a direct port of v1's currency-aware payment-method list, and v1 ships these labels as plain strings. The labels are used as serialized/comparison values in presets, order filters, and NewOrderParams.paymentMethod, so localizing them requires a display-vs-serialized split across 100+ labels a separate enhancement (CodeRabbit flags it "Heavy lift") rather than part of this port. Happy to open a follow-up issue for label localization if the team wants it.

@ermeme ermeme Bot 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.

Reviewed the current head 07a05e0. The currency-aware payment-method provider matches the issue scope, the shipped asset is registered and well-formed, and the loading-state pruning issue from the earlier bot review is guarded by paymentMethodsDataProvider.hasValue. I also checked the unresolved localization suggestion and agree it is a serialized-value/display-label split that can be handled separately rather than blocking this v1 parity port.

Verified:

  • GitHub checks are green for this head.
  • Local git diff --check passed.
  • assets/data/payment_methods.json parses and has non-empty, duplicate-free method lists.

No blocking issues found.

@Catrya Catrya 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.

tACK

@Catrya
Catrya merged commit 7625b24 into MostroP2P:main Aug 11, 2026
4 checks 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.

Currency-aware payment method suggestions in create-order form

2 participants