Skip to content

fix(order): back from invoice screens lands on trade detail - #278

Merged
Catrya merged 2 commits into
mainfrom
fix/take-order-back-navigation
Aug 5, 2026
Merged

fix(order): back from invoice screens lands on trade detail#278
Catrya merged 2 commits into
mainfrom
fix/take-order-back-navigation

Conversation

@Catrya

@Catrya Catrya commented Aug 5, 2026

Copy link
Copy Markdown
Member

fix #268

  • After a successful take, trade detail becomes the base of the stack and the invoice screen is pushed on top, so back/close never returns to Take Order offering an already-taken order.
  • The Cancel buttons on add-invoice and pay-invoice now confirm via dialog and send the protocol cancel (same flow and strings as trade detail), then go home.
  • Defense in depth: Take Order redirects to trade detail when a persisted trade role shows the user already participates in the order.

Summary by CodeRabbit

  • New Features
    • Added confirmation and processing when canceling lightning invoice orders, including status feedback and navigation to the home screen.
    • Automatically redirects users who are already participating in an order to its trade details.
    • Updated order-taking navigation to prevent returning to the order selection screen after proceeding to invoice payment or creation.

…ancels the trade

- After a successful take, trade detail becomes the base of the stack and the
  invoice screen is pushed on top, so back/close never returns to Take Order
  offering an already-taken order.
- The Cancel buttons on add-invoice and pay-invoice now confirm via dialog and
  send the protocol cancel (same flow and strings as trade detail), then go home.
- Defense in depth: Take Order redirects to trade detail when a persisted trade
  role shows the user already participates in the order.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 27 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: 6132544c-1bd3-457d-9011-e339ff27a08f

📥 Commits

Reviewing files that changed from the base of the PR and between 554427d and 7063984.

📒 Files selected for processing (3)
  • lib/features/order/screens/add_lightning_invoice_screen.dart
  • lib/features/order/screens/pay_lightning_invoice_screen.dart
  • lib/features/order/screens/take_order_screen.dart

Walkthrough

Changes

Order flow

Layer / File(s) Summary
Participant detection and post-take routing
lib/features/order/screens/take_order_screen.dart
The screen checks the user’s trade role during initialization. Existing participants are redirected to trade detail. Successful order taking replaces the current route before opening invoice screens.
Confirmed invoice cancellation
lib/features/order/screens/add_lightning_invoice_screen.dart, lib/features/order/screens/pay_lightning_invoice_screen.dart
Cancel actions now confirm, call the cancellation API, refresh trades, show localized feedback, and navigate home.

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

Sequence Diagram(s)

sequenceDiagram
  participant TakeOrderScreen
  participant TradeRoleAPI
  participant TradeDetailScreen
  participant InvoiceScreen
  TakeOrderScreen->>TradeRoleAPI: retrieve user trade role
  TradeRoleAPI-->>TakeOrderScreen: return role
  TakeOrderScreen->>TradeDetailScreen: redirect existing participant
  TakeOrderScreen->>TradeDetailScreen: replace route after taking order
  TradeDetailScreen->>InvoiceScreen: open add or pay invoice
Loading
sequenceDiagram
  participant InvoiceScreen
  participant OrderCancellationAPI
  participant Trades
  participant Home
  InvoiceScreen->>InvoiceScreen: confirm cancellation
  InvoiceScreen->>OrderCancellationAPI: cancel order
  OrderCancellationAPI-->>InvoiceScreen: return success or error
  InvoiceScreen->>Trades: refresh trades
  InvoiceScreen->>Home: navigate after cancellation
Loading

Possibly related PRs

Suggested reviewers: grunch

Poem

A rabbit checks the trade with care,
Then guides each order to its lair.
Cancel clicks now ask before they flee,
APIs refresh trades properly.
Home awaits when work is done. 🐇

🚥 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 primary navigation fix from invoice screens to Trade Detail.
Linked Issues check ✅ Passed The changes implement issue #268 by making Trade Detail the base route and redirecting existing participants away from Take Order.
Out of Scope Changes check ✅ Passed The cancellation and navigation changes support the stated order-flow objectives and are not unrelated to issue #268.
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
  • Commit unit tests in branch fix/take-order-back-navigation

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/features/order/screens/take_order_screen.dart (1)

52-68: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Block Take Order until the participant check completes.

_redirectIfParticipant() starts asynchronously while _onTakeOrder() remains reachable. If getTradeRole is slow, an existing participant can call takeOrder first; the Rust path returns OrderAlreadyTaken, and this catch block navigates to AppRoute.home instead of tradeDetailPath. Track the pending participant lookup and disable the submit button until getTradeRole returns no role. Handle lookup errors explicitly. Add a widget test that delays getTradeRole and asserts that takeOrder does not run.

🤖 Prompt for 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.

In `@lib/features/order/screens/take_order_screen.dart` around lines 52 - 68,
Track the in-flight participant lookup started by _redirectIfParticipant and
keep the Take Order submit action disabled until getTradeRole completes; if a
role exists, navigate to tradeDetailPath and prevent _onTakeOrder from running.
Handle lookup failures explicitly without leaving the screen permanently
blocked, and add a widget test that delays getTradeRole and verifies takeOrder
is not invoked.

Source: Coding guidelines

🤖 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 `@lib/features/order/screens/add_lightning_invoice_screen.dart`:
- Around line 71-109: The order screens allow cancellation to race with
submission or another cancellation. In _cancelOrder and the corresponding
pay-invoice cancellation flow, add cancellation busy-state guards that reject
new state-changing requests while submission or cancellation is active, set and
clear the state around the awaited API call, and disable each related Cancel
button while busy; update the specified add-invoice and pay-invoice widget tests
to cover repeated confirmations and cancellation during invoice submission.

---

Outside diff comments:
In `@lib/features/order/screens/take_order_screen.dart`:
- Around line 52-68: Track the in-flight participant lookup started by
_redirectIfParticipant and keep the Take Order submit action disabled until
getTradeRole completes; if a role exists, navigate to tradeDetailPath and
prevent _onTakeOrder from running. Handle lookup failures explicitly without
leaving the screen permanently blocked, and add a widget test that delays
getTradeRole and verifies takeOrder is not invoked.
🪄 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: 2a8c9411-25a2-44a8-883d-f7297580a0bc

📥 Commits

Reviewing files that changed from the base of the PR and between 4cc4219 and 554427d.

📒 Files selected for processing (3)
  • lib/features/order/screens/add_lightning_invoice_screen.dart
  • lib/features/order/screens/pay_lightning_invoice_screen.dart
  • lib/features/order/screens/take_order_screen.dart

Comment thread lib/features/order/screens/add_lightning_invoice_screen.dart

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

Approved — reviewed at head 70639844.

Verification

  • CI green on this head: Rust (build/test/clippy/wasm), Flutter (analyze/test), Web (wasm build). Dart-only change, so Flutter analyze/test is the meaningful gate and it passes; git diff --check clean.
  • Reviewed against both CodeRabbit round-1 findings: the inline thread is resolved on this head, and the outside-diff take-order race is functionally closed (see below).

Review

  • The stack rebuild (context.go(tradeDetailPath) + context.push(invoicePath)) is the right fix for #268: back/close from either invoice screen now lands on trade detail, and the Take Order screen is gone from the stack entirely. Matches what the issue proposed.
  • The participant re-check inside _onTakeOrder closes CodeRabbit's race: even if the initState redirect lookup is still in flight, a participant can no longer dispatch a second takeOrder — they are redirected to their trade instead. That was the correct layer to fix it (disabling the button would still leave the window).
  • _cancelOrder on both screens serializes properly (_submitting || _canceling guards, buttons disabled while busy, finally resets) and cooperates correctly with the push listener from #274 via the _navigated one-shot guard. Cancel-from-invoice-screen now sends the protocol cancel instead of a bare pop, which also fixes the "form sits here dying with NoDaemonResponse" failure mode.
  • All dialog/snackbar strings reuse the existing trade-detail l10n keys — no new untranslated strings.

Non-blocking nits

  • _onTakeOrder: the new getTradeRole await widens the pre-_submitting window slightly — a double-tap during the role lookup can still reach takeOrder twice (second one gets OrderAlreadyTaken → home). A one-line if (_submitting) return; re-check after the await would close it. Pre-existing pattern, not a regression.
  • Both getTradeRole call sites (_redirectIfParticipant, _onTakeOrder) sit outside any try/catch — an FFI/DB error there would surface as an unhandled async error rather than a snackbar.
  • The cancel dialog copy ("The other party must also agree") is the cooperative-cancel text; in the waiting states these screens live in, the cancel is actually unilateral. Harmless, slightly misleading — fine to leave for a copy pass.

@Catrya
Catrya merged commit e579360 into main Aug 5, 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.

fix(order): back navigation from add-invoice returns to Take Order screen offering "Take this order" again

1 participant