Skip to content

Conversation

@Catrya
Copy link
Member

@Catrya Catrya commented Oct 17, 2025

fix #325

  • Add invalidFiatCurrency to CantDoReason enum
  • Fix bug in NotificationListenerWidget: change values['action'] to values['reason']
  • Add localized error messages for invalid fiat currency in en/es/it
  • Add session cleanup and navigation for invalidFiatCurrency errors
  • Update CantDoNotificationMapper with new error type

Summary by CodeRabbit

  • New Features
    • Added proper error handling when the selected fiat currency is not supported by the Mostro instance, displaying a helpful message suggesting to try another instance.
    • Improved session management to automatically clean up and navigate back to the order book when this error occurs.
    • Extended localization support with new message translations in English, Spanish, and Italian.

  - Add invalidFiatCurrency to CantDoReason enum
  - Fix bug in NotificationListenerWidget: change values['action'] to values['reason']
  - Add localized error messages for invalid fiat currency in en/es/it
  - Add session cleanup and navigation for invalidFiatCurrency errors
  - Update CantDoNotificationMapper with new error type
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 17, 2025

Walkthrough

The pull request adds support for handling invalid fiat currency scenarios. A new enum constant invalidFiatCurrency is introduced to CantDoReason, enabling detection and proper handling when a Mostro instance doesn't accept a selected currency. Session cleanup and user-friendly navigation are triggered upon this condition, with localized error messages provided across multiple languages.

Changes

Cohort / File(s) Summary
Enum Extension
lib/data/models/enums/cant_do_reason.dart
Added new enum constant invalidFiatCurrency('invalid_fiat_currency') to expand CantDoReason values and automatic inclusion in lookup mappings
Notifier Logic
lib/features/order/notfiers/add_order_notifier.dart
Added handling for CantDoReason.invalidFiatCurrency to trigger session cleanup and navigation; introduced private helper method _cleanupSessionAndNavigateBack() that logs, deletes session, navigates to home, and invalidates the notifier
Localization
lib/l10n/intl_en.arb, lib/l10n/intl_es.arb, lib/l10n/intl_it.arb
Added new translation key invalidFiatCurrency with localized messages: English "This Mostro instance doesn't accept the selected currency, try another instance", Spanish "Este mostro no acepta la moneda que seleccionaste, prueba con otra instancia", Italian equivalent
Notification Mapping
lib/shared/widgets/notification_listener_widget.dart
Added mapping entry for 'invalid_fiat_currency' to return localized invalidFiatCurrency; updated payload extraction logic to use next.values['reason'] instead of next.values['action'] with fallback handling

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AddOrderNotifier as AddOrderNotifier
    participant SessionNotifier as sessionNotifierProvider
    participant Router as Navigation
    
    User->>AddOrderNotifier: Order action triggers<br/>CantDoReason.invalidFiatCurrency
    AddOrderNotifier->>AddOrderNotifier: Detect invalidFiatCurrency
    AddOrderNotifier->>AddOrderNotifier: Call _cleanupSessionAndNavigateBack()
    Note over AddOrderNotifier: Log cleanup action
    AddOrderNotifier->>SessionNotifier: Delete session by requestId
    SessionNotifier->>SessionNotifier: Session removed
    AddOrderNotifier->>Router: Navigate to home ('/')
    AddOrderNotifier->>AddOrderNotifier: Invalidate notifier
    Router->>User: Display home/order book
Loading
sequenceDiagram
    participant NotificationService
    participant NotificationListenerWidget as Notification Widget
    participant Context
    participant L10n
    
    NotificationService->>NotificationListenerWidget: CantDo notification received<br/>reason: 'invalid_fiat_currency'
    NotificationListenerWidget->>NotificationListenerWidget: Extract reason from payload
    NotificationListenerWidget->>NotificationListenerWidget: Call CantDoNotificationMapper.getMessage()
    NotificationListenerWidget->>L10n: Resolve invalidFiatCurrency key
    L10n->>NotificationListenerWidget: Return localized message
    NotificationListenerWidget->>Context: Display error notification<br/>with localized message
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are straightforward additions with minimal complexity: a single new enum value, localized strings across three language files (repetitive pattern), basic session cleanup logic, and mapping updates. No intricate logic or architectural changes are introduced.

Possibly related PRs

Suggested reviewers

  • chebizarro
  • grunch

Poem

🐰 A fiat that won't fly on this Mostro so bright,
We catch it with reason and set things right,
Clean up the session, then homeward we go,
In English, Spanish, Italian—let users all know! 💱✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat: add invalid_fiat_currency error handling with session cleanup" is fully related to the main change in the changeset. The PR introduces a new error type (invalidFiatCurrency) to the CantDoReason enum and implements comprehensive handling for it across multiple files, including the AddOrderNotifier with session cleanup and navigation logic, localization strings in three languages, and mapper updates. The title accurately captures both the primary objective (adding the new error handling) and the key implementation detail (session cleanup), making it clear and specific without unnecessary noise or vague language.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cant-do-currency

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 873b2b6 and ba5eb48.

📒 Files selected for processing (6)
  • lib/data/models/enums/cant_do_reason.dart (1 hunks)
  • lib/features/order/notfiers/add_order_notifier.dart (2 hunks)
  • lib/l10n/intl_en.arb (1 hunks)
  • lib/l10n/intl_es.arb (1 hunks)
  • lib/l10n/intl_it.arb (1 hunks)
  • lib/shared/widgets/notification_listener_widget.dart (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
lib/l10n/intl_{en,es,it}.arb

📄 CodeRabbit inference engine (CLAUDE.md)

Add new localization keys to all three ARB files (en, es, it)

Files:

  • lib/l10n/intl_it.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
lib/l10n/*.arb

📄 CodeRabbit inference engine (CLAUDE.md)

For parameterized strings, include proper ARB metadata

Files:

  • lib/l10n/intl_it.arb
  • lib/l10n/intl_en.arb
  • lib/l10n/intl_es.arb
lib/**/*.dart

📄 CodeRabbit inference engine (CLAUDE.md)

lib/**/*.dart: Use post-frame callbacks for UI side effects (e.g., SnackBars/dialogs)
Use S.of(context).keyName for all user-facing strings (no hardcoded text)
Always use localized strings instead of hardcoded text
Pass BuildContext to methods that need localization (use S.of(context))
Check mounted before using BuildContext after async gaps
Use const constructors where possible

Name Riverpod providers as Provider or Notifier

Files:

  • lib/data/models/enums/cant_do_reason.dart
  • lib/shared/widgets/notification_listener_widget.dart
  • lib/features/order/notfiers/add_order_notifier.dart
**/*.dart

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.dart: All code comments must be in English
Use clear, concise English for variable and function names
Maintain zero flutter analyze issues
Use latest Flutter/Dart APIs (e.g., prefer withValues() over withOpacity())
Remove unused imports and dependencies

**/*.dart: Use Dart formatter defaults (two-space indentation, trailing commas) and run flutter format before committing
Resolve all Flutter analyzer warnings (flutter analyze must be clean)

Files:

  • lib/data/models/enums/cant_do_reason.dart
  • lib/shared/widgets/notification_listener_widget.dart
  • lib/features/order/notfiers/add_order_notifier.dart
lib/data/**

📄 CodeRabbit inference engine (AGENTS.md)

Store persistence and API code under lib/data/

Files:

  • lib/data/models/enums/cant_do_reason.dart
lib/shared/**

📄 CodeRabbit inference engine (AGENTS.md)

Put shared utilities in lib/shared/

Files:

  • lib/shared/widgets/notification_listener_widget.dart
lib/features/**

📄 CodeRabbit inference engine (AGENTS.md)

Place application feature code under lib/features//, grouped by domain

Files:

  • lib/features/order/notfiers/add_order_notifier.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (8)
lib/data/models/enums/cant_do_reason.dart (1)

25-25: LGTM! New enum constant added correctly.

The invalidFiatCurrency enum constant follows the existing pattern and will be automatically included in the _valueMap lookup, ensuring proper string-to-enum conversion.

lib/features/order/notfiers/add_order_notifier.dart (2)

48-54: LGTM! Appropriate error handling for invalid fiat currency.

The new handling for invalidFiatCurrency correctly distinguishes between retriable errors (out of range amounts) and non-retriable errors (unsupported currency). Triggering cleanup and navigation instead of retry is the right approach when the Mostro instance doesn't support the selected currency.


118-130: LGTM! Clean session cleanup implementation.

The _cleanupSessionAndNavigateBack() method properly handles the error case by:

  1. Deleting the session state to prevent stale data
  2. Navigating back to the order book ('/') for the user to try a different currency or instance
  3. Invalidating the notifier to clean up resources
lib/l10n/intl_it.arb (1)

170-170: LGTM! Italian localization added correctly.

The Italian translation for invalidFiatCurrency is clear and consistent with the other language versions, properly guiding users to try a different Mostro instance.

lib/l10n/intl_en.arb (1)

170-170: LGTM! English localization added correctly.

The English translation for invalidFiatCurrency is clear and actionable, guiding users to try a different Mostro instance when their selected currency is not supported.

lib/shared/widgets/notification_listener_widget.dart (2)

30-30: LGTM! Mapping added for new cant-do reason.

The invalid_fiat_currency mapping correctly links to the localized invalidFiatCurrency message, consistent with the existing cant-do reason mappings.


79-79: Excellent bug fix! Corrects cant-do payload extraction.

This change fixes a pre-existing bug in the cant-do notification handling. At this point in the code, we already know action == Action.cantDo, and the specific reason (e.g., 'invalid_invoice', 'out_of_range_sats_amount', 'invalid_fiat_currency') is stored in the 'reason' field of the payload, not 'action'.

This fix ensures all cant-do notifications display the correct localized message, not just the new invalidFiatCurrency one.

lib/l10n/intl_es.arb (1)

146-146: LGTM! Spanish localization added correctly.

The Spanish translation for invalidFiatCurrency is clear and consistent with the English and Italian versions, properly instructing users to try another Mostro instance.


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.

Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

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

tACK

@grunch grunch merged commit 82aaa4b into main Oct 20, 2025
2 checks passed
@grunch grunch deleted the cant-do-currency branch October 20, 2025 13:52
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.

Add cant-do invalid_fiat_currency

3 participants