feat: auto-close dispute UI when order reaches terminal state #503
feat: auto-close dispute UI when order reaches terminal state #503
Conversation
- Auto-close dispute when seller releases sats (settledHoldInvoice/success) - Auto-close dispute on cooperative cancellation (canceled) - Differentiate closure reason via dispute.action: 'user-completed' vs 'cooperative-cancel' - Show distinct messages in dispute list and detail view per closure type - Add localization keys in en/es/it/fr for both closure messages
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughWhen an order reaches a terminal state (success/settledHoldInvoice or cooperative cancel), the app auto-marks any associated dispute as Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App as Mobile App
participant OrderState as OrderState
participant DisputeState as DisputeState
participant UI as Dispute UI
User->>App: Completes or cooperatively cancels order
App->>OrderState: Order transitions to terminal state (success / settledHoldInvoice / canceled)
OrderState->>OrderState: Locate dispute by orderId
alt dispute exists and not terminal
OrderState->>DisputeState: Set dispute.status = "closed", action = "user-completed" / "cooperative-cancel"
end
DisputeState->>UI: Emit updated dispute state
UI->>UI: Select localized message based on dispute.action
UI->>App: Render closed dispute message
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/features/order/models/order_state.dart`:
- Around line 194-213: The auto-close branch that sets updatedDispute to action
'cooperative-cancel' currently fires whenever newStatus == Status.canceled;
change it to only run for cooperative cancellation flows by adding a check for
the triggering cancellation action (e.g., require the cancellation Action to be
the cooperative cancel action rather than Action.cancel /
Action.holdInvoicePaymentCanceled / Action.adminCancel). Update the if condition
around updatedDispute.copyWith(... action: 'cooperative-cancel' ...) to verify
the specific cooperative cancellation action (use the existing Action
enum/variable used when status transitions occur) before assigning
'cooperative-cancel' and logging the cooperative message.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
lib/data/models/dispute.dartlib/features/disputes/widgets/dispute_status_content.dartlib/features/order/models/order_state.dartlib/l10n/intl_en.arblib/l10n/intl_es.arblib/l10n/intl_fr.arblib/l10n/intl_it.arb
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/features/order/models/order_state.dart (1)
194-214: LGTM! Past review concern properly addressed.The cooperative-cancel branch now correctly guards against non-cooperative cancellation actions by checking
message.action == Action.cooperativeCancelAccepted(line 208). This ensures'cooperative-cancel'is only assigned for actual cooperative cancellations, not forAction.cancel,Action.holdInvoicePaymentCanceled, orAction.adminCancel.Optional refactor: The terminal dispute status list is duplicated. Consider extracting it:
♻️ Optional: Extract constant for terminal dispute statuses
+ static const _terminalDisputeStatuses = {'resolved', 'seller-refunded', 'closed'}; + // Auto-close dispute when order reaches terminal state by user action if (updatedDispute != null && - !const ['resolved', 'seller-refunded', 'closed'] - .contains(updatedDispute.status?.toLowerCase()) && + !_terminalDisputeStatuses.contains(updatedDispute.status?.toLowerCase()) && const [Status.success, Status.settledHoldInvoice].contains(newStatus)) { // ... } else if (updatedDispute != null && - !const ['resolved', 'seller-refunded', 'closed'] - .contains(updatedDispute.status?.toLowerCase()) && + !_terminalDisputeStatuses.contains(updatedDispute.status?.toLowerCase()) && newStatus == Status.canceled && message.action == Action.cooperativeCancelAccepted) {,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/features/order/models/order_state.dart` around lines 194 - 214, Duplicate literal list of terminal dispute statuses should be extracted to a single constant; create a top-level const like terminalDisputeStatuses = ['resolved', 'seller-refunded', 'closed'] and replace both occurrences of the inline const list in the updatedDispute guards (the first if and the else-if that check updatedDispute.status?.toLowerCase()) with terminalDisputeStatuses to remove duplication and improve readability while keeping the existing logic in the order state update flow (refer to the updatedDispute null checks and the newStatus/ message.action conditions).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/features/order/models/order_state.dart`:
- Around line 194-214: Duplicate literal list of terminal dispute statuses
should be extracted to a single constant; create a top-level const like
terminalDisputeStatuses = ['resolved', 'seller-refunded', 'closed'] and replace
both occurrences of the inline const list in the updatedDispute guards (the
first if and the else-if that check updatedDispute.status?.toLowerCase()) with
terminalDisputeStatuses to remove duplication and improve readability while
keeping the existing logic in the order state update flow (refer to the
updatedDispute null checks and the newStatus/ message.action conditions).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/architecture/ORDER_STATUS_HANDLING.mdlib/features/order/models/order_state.dart
✅ Files skipped from review due to trivial changes (1)
- docs/architecture/ORDER_STATUS_HANDLING.md
fix #494
Summary by CodeRabbit
New Features
Documentation