Skip to content

Fix Order Status Hydration Bug issue #219#220

Merged
grunch merged 2 commits into
mainfrom
chebizarro/issue219
Jul 22, 2025
Merged

Fix Order Status Hydration Bug issue #219#220
grunch merged 2 commits into
mainfrom
chebizarro/issue219

Conversation

@chebizarro

@chebizarro chebizarro commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Fixes #219

Orders with cooperative cancellation or dispute were incorrectly showing as pending, waiting-buyer-invoice, or waiting-payment after app restart, instead of their actual cooperative cancellation or dispute states.

Root Cause

The OrderState._getStatusFromAction() method was missing explicit mappings for several critical actions, causing them to fall through to the default case during order hydration from storage when the app restarts.

Solution

Added comprehensive action-to-status mappings for all missing actions:

Critical Fixes:

cooperativeCancelInitiatedByYou/ByPeer → Status.cooperativelyCanceled
disputeInitiatedByYou/ByPeer → Status.dispute
Additional Completeness Fixes:

release → Status.success
cancel → Status.canceled
buyerInvoiceAccepted → Status.active
holdInvoicePaymentCanceled → Status.canceled
Admin actions → appropriate statuses (adminSettle → settledByAdmin, etc.)
Informational actions → preserve current status

Summary by CodeRabbit

  • New Features

    • Expanded order status updates to recognize a wider range of actions, providing more detailed and accurate status information during the order process.
  • Bug Fixes

    • Improved handling of status updates for various order actions, ensuring that the displayed order status accurately reflects recent activity.

@chebizarro chebizarro requested a review from Catrya July 22, 2025 03:59
@coderabbitai

coderabbitai Bot commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The update enhances the internal status mapping logic within the OrderState model by expanding the set of action-to-status associations in the _getStatusFromAction method. It introduces finer-grained status handling for cooperative cancellations, disputes, admin settlements, and informational actions, without altering any public interfaces or method signatures.

Changes

File(s) Change Summary
lib/features/order/models/order_state.dart Refined internal status mapping in _getStatusFromAction; adjusted peer object formatting in updateWith.

Estimated code review effort

2 (~15 minutes)

Poem

In the warren where orders hop and play,
New actions guide their status on the way.
Disputes and cancels, now clear as can be,
Admins and peers, all mapped properly.
With every hop, the logic grows bright—
Orders leap forward, statuses set right!
🐇✨


📜 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 0256e85 and e09f589.

📒 Files selected for processing (1)
  • lib/features/order/models/order_state.dart (3 hunks)
📓 Path-based instructions (2)
lib/**/*.dart

📄 CodeRabbit Inference Engine (CLAUDE.md)

lib/**/*.dart: Use S.of(context).yourKey for all user-facing strings
Always check mounted before using context after async operations

Files:

  • lib/features/order/models/order_state.dart
**/*.dart

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • lib/features/order/models/order_state.dart
🧠 Learnings (2)
📓 Common learnings
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.
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.
lib/features/order/models/order_state.dart (3)

Learnt from: chebizarro
PR: #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.

Learnt from: CR
PR: MostroP2P/mobile#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-20T01:48:43.335Z
Learning: Applies to lib/core/mostro_fsm.dart : Order state transitions are managed by core/mostro_fsm.dart

Learnt from: chebizarro
PR: #74
File: lib/features/trades/models/trade_state.dart:1-15
Timestamp: 2025-05-08T16:06:33.665Z
Learning: In the context of the Mostro Mobile app, the TradeState class is specifically constructed using the tradeStateProvider. While some fields are nullable (lastAction and orderPayload), they are still marked as required parameters to ensure they are explicitly considered during state construction.

🧰 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 check mounted before using context after async operations

Files:

  • lib/features/order/models/order_state.dart
**/*.dart

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • lib/features/order/models/order_state.dart
🧠 Learnings (2)
📓 Common learnings
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.
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.
lib/features/order/models/order_state.dart (3)

Learnt from: chebizarro
PR: #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.

Learnt from: CR
PR: MostroP2P/mobile#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-20T01:48:43.335Z
Learning: Applies to lib/core/mostro_fsm.dart : Order state transitions are managed by core/mostro_fsm.dart

Learnt from: chebizarro
PR: #74
File: lib/features/trades/models/trade_state.dart:1-15
Timestamp: 2025-05-08T16:06:33.665Z
Learning: In the context of the Mostro Mobile app, the TradeState class is specifically constructed using the tradeStateProvider. While some fields are nullable (lastAction and orderPayload), they are still marked as required parameters to ensure they are explicitly considered during state construction.

🔇 Additional comments (4)
lib/features/order/models/order_state.dart (4)

115-120: LGTM! Good formatting improvement.

The multi-line formatting of the Peer constructor calls improves readability without changing functionality.


169-191: LGTM! Logical action-to-status mappings.

The new action mappings are logically sound:

  • buyerInvoiceAcceptedactive correctly indicates an active order after invoice acceptance
  • releasesuccess properly represents successful order completion
  • cancel, adminCancel, holdInvoicePaymentCanceledcanceled appropriately handle various cancellation scenarios

These mappings address the core issue described in the PR objectives.


194-211: Excellent fix for the order status hydration bug!

These new status group mappings directly address the core issue described in PR #219:

  • Cooperative cancellation: cooperativeCancelInitiatedByYou/ByPeercooperativelyCanceled
  • Dispute handling: Various dispute actions → dispute status
  • Admin settlements: adminSettle/adminSettledsettledByAdmin

This ensures orders with these actions will display correct statuses after app restart instead of defaulting to pending/waiting states.


212-220: Smart handling of informational actions.

The preservation of current status for informational actions (rateUser, paymentFailed, invoiceUpdated, etc.) is well-designed. These actions provide updates without representing state transitions, so maintaining the existing status ensures order states remain stable during hydration.

The fallback to payloadStatus ?? status provides appropriate flexibility while preventing unintended status changes.


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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

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

tACK

@grunch grunch merged commit 96fd81f into main Jul 22, 2025
2 checks passed
@grunch grunch deleted the chebizarro/issue219 branch July 22, 2025 12:45
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.

Status error upon restarting the app

2 participants