Skip to content

fix: ensure cancellation detection for orders in waiting states#252

Merged
Catrya merged 2 commits into
mainfrom
fix-cancel
Aug 4, 2025
Merged

fix: ensure cancellation detection for orders in waiting states#252
Catrya merged 2 commits into
mainfrom
fix-cancel

Conversation

@Catrya

@Catrya Catrya commented Aug 2, 2025

Copy link
Copy Markdown
Member
  • Fix cancellation detection for waiting states in _checkTimeoutAndCleanup()
  • Delete sessions when orders are canceled from waiting states
  • Add cancellation notification and navigation
  • Document cancellation detection in waiting states

Summary by CodeRabbit

  • New Features

    • Added support for detecting and handling order cancellations, ensuring sessions are deleted and users are notified and redirected to the Order Book when a cancellation occurs.
  • Documentation

    • Updated documentation to describe the new cancellation detection and cleanup process, including user notifications and session handling.
  • Localization

    • Added new order cancellation notification messages in English, Spanish, and Italian.
  • Bug Fixes

    • Enhanced notification system to display order cancellation messages to users.

@coderabbitai

coderabbitai Bot commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce explicit handling of order cancellations in both documentation and implementation. The system now detects cancellations via public events, cleans up sessions for both maker and taker roles, notifies the user, and navigates back to the order book. Documentation was updated to describe this unified cancellation and timeout detection process.

Changes

Cohort / File(s) Change Summary
Documentation Update
CLAUDE.md
Added a section on "Cancellation Detection & Cleanup," detailing how cancellations are detected, sessions are cleaned up, and users are notified and redirected. Updated the "Key Implementation" section to mention unified event monitoring for timeouts and cancellations.
Order Notifier Logic
lib/features/order/notfiers/order_notifier.dart
Extended _checkTimeoutAndCleanup to handle order cancellations detected via public events, deleting sessions and notifying users. Updated handleEvent to log and skip timeout detection for canceled events. Comments and logging improved for clarity.
Localization Strings
lib/l10n/intl_en.arb, lib/l10n/intl_es.arb, lib/l10n/intl_it.arb
Added new localization string key "orderCanceled" with appropriate translations in English, Spanish, and Italian for cancellation notifications.
Notification Widget Update
lib/shared/widgets/notification_listener_widget.dart
Added handling of the new "orderCanceled" custom message key to display the localized cancellation notification in the UI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OrderNotifier
    participant EventMonitor
    participant UI

    EventMonitor->>OrderNotifier: Public event (status: canceled or pending)
    OrderNotifier->>OrderNotifier: _checkTimeoutAndCleanup()
    alt Event is canceled & newer
        OrderNotifier->>OrderNotifier: Delete session (maker/taker)
        OrderNotifier->>UI: Show cancellation notification
        OrderNotifier->>UI: Navigate to Order Book
    else Event is pending & newer
        alt Maker scenario
            OrderNotifier->>OrderNotifier: Persist timeout reversal, update state
        else Taker scenario
            OrderNotifier->>OrderNotifier: Delete session
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • chebizarro
  • grunch

Poem

🐇
Orders may come and orders may go,
Now cancellations are caught in the flow.
With sessions cleaned up and users informed,
The order book’s tidy, no chaos is formed!
Hop, hop, hooray—
Bugs and confusion, swept clean away!
🥕✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 4353c23 and 15eba97.

📒 Files selected for processing (6)
  • CLAUDE.md (1 hunks)
  • lib/features/order/notfiers/order_notifier.dart (4 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 (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lib/l10n/intl_it.arb
🚧 Files skipped from review as they are similar to previous changes (5)
  • CLAUDE.md
  • lib/l10n/intl_en.arb
  • lib/shared/widgets/notification_listener_widget.dart
  • lib/l10n/intl_es.arb
  • lib/features/order/notfiers/order_notifier.dart
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-cancel

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6b682e and 20b463f.

📒 Files selected for processing (2)
  • CLAUDE.md (1 hunks)
  • lib/features/order/notfiers/order_notifier.dart (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
lib/**/*.dart

📄 CodeRabbit Inference Engine (CLAUDE.md)

lib/**/*.dart: Use S.of(context).yourKey for all user-facing strings
Always use localized strings instead of hardcoded text
Pass BuildContext to methods that need localization
Always use latest APIs (e.g., withValues() instead of withOpacity())
Always check mounted before using context after async operations

Files:

  • lib/features/order/notfiers/order_notifier.dart
**/*.dart

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.dart: Remove unused imports and dependencies
Use const constructors where possible

Files:

  • lib/features/order/notfiers/order_notifier.dart
🧠 Learnings (8)
📓 Common learnings
Learnt from: chebizarro
PR: MostroP2P/mobile#74
File: lib/services/mostro_service.dart:97-103
Timestamp: 2025-05-06T15:49:55.079Z
Learning: In the Mostro protocol, an order cannot be canceled unless it has a valid orderId, so null checks on orderId during cancel operations are unnecessary.
📚 Learning: mostroservice methods like takebuyorder() and takesellorder() return future and trigger side e...
Learnt from: chebizarro
PR: MostroP2P/mobile#110
File: test/notifiers/take_order_notifier_test.dart:72-74
Timestamp: 2025-06-04T19:35:20.209Z
Learning: MostroService methods like takeBuyOrder() and takeSellOrder() return Future<void> and trigger side effects through other mechanisms rather than direct return values. When testing these methods, focus on verifying method calls and testing state changes through the provider system rather than mocking return values.

Applied to files:

  • CLAUDE.md
  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: in abstractmostronotifier, state updates occur for all messages regardless of timestamp to hydrate t...
Learnt from: chebizarro
PR: MostroP2P/mobile#127
File: lib/features/order/notfiers/abstract_mostro_notifier.dart:45-54
Timestamp: 2025-06-26T15:03:23.529Z
Learning: In AbstractMostroNotifier, state updates occur for all messages regardless of timestamp to hydrate the OrderNotifier from MostroStorage during sync, while handleEvent is only called for recent messages (within 60 seconds) to prevent re-triggering side effects like notifications and navigation for previously handled messages. This design prevents displaying stale notifications when the app is reopened or brought to the foreground.

Applied to files:

  • CLAUDE.md
  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: in abstractmostronotifier, the handleevent method is synchronous and returns void, not future....
Learnt from: Catrya
PR: MostroP2P/mobile#215
File: lib/features/order/notfiers/order_notifier.dart:0-0
Timestamp: 2025-07-20T23:33:17.689Z
Learning: In AbstractMostroNotifier, the handleEvent method is synchronous and returns void, not Future<void>. Do not suggest adding await to super.handleEvent() calls as this would cause compilation errors.

Applied to files:

  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: applies to lib/core/mostro_fsm.dart : order state transitions must be managed by `core/mostro_fsm.da...
Learnt from: CR
PR: MostroP2P/mobile#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-30T14:10:43.895Z
Learning: Applies to lib/core/mostro_fsm.dart : Order state transitions must be managed by `core/mostro_fsm.dart`

Applied to files:

  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: in the mostro protocol, an order cannot be canceled unless it has a valid orderid, so null checks on...
Learnt from: chebizarro
PR: MostroP2P/mobile#74
File: lib/services/mostro_service.dart:97-103
Timestamp: 2025-05-06T15:49:55.079Z
Learning: In the Mostro protocol, an order cannot be canceled unless it has a valid orderId, so null checks on orderId during cancel operations are unnecessary.

Applied to files:

  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: encapsulate business logic in notifiers...
Learnt from: CR
PR: MostroP2P/mobile#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-30T14:10:43.895Z
Learning: Encapsulate business logic in Notifiers

Applied to files:

  • lib/features/order/notfiers/order_notifier.dart
📚 Learning: in the orderstate refactor, public keys should be accessed via `tradestate.peer?.publickey` from the...
Learnt from: chebizarro
PR: MostroP2P/mobile#110
File: lib/features/trades/widgets/mostro_message_detail_widget.dart:134-141
Timestamp: 2025-06-08T23:54:09.987Z
Learning: In the OrderState refactor, public keys should be accessed via `tradeState.peer?.publicKey` from the OrderState instance rather than through `session?.peer?.publicKey`, as the OrderState encapsulates peer information directly.

Applied to files:

  • lib/features/order/notfiers/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 (2)
lib/features/order/notfiers/order_notifier.dart (1)

25-34: LGTM! Good defensive programming.

Adding the cancellation check prevents conflicting operations between timeout detection and cancellation handling.

CLAUDE.md (1)

74-81: Excellent documentation of the cancellation handling.

The documentation clearly describes the cancellation detection mechanism and its behavior, with accurate references to the implementation. This will be valuable for future maintenance.

Comment thread lib/features/order/notfiers/order_notifier.dart
Catrya added 2 commits August 4, 2025 09:35
  - Fix cancellation detection for waiting states in
  _checkTimeoutAndCleanup()
  - Delete sessions when orders are canceled from waiting states
  - Add cancellation notification and navigation
  - Document cancellation detection in waiting states
  - Use showCustomMessage('orderCanceled') instead of showInformation()
  - Add orderCanceled case to notification_listener_widget.dart
  - Add orderCanceled key to all ARB localization files (en, es, it)
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.

1 participant