Skip to content

fix(#269): bucket My Trades filter by live status, not the stale snapshot - #299

Open
codaMW wants to merge 2 commits into
MostroP2P:mainfrom
codaMW:fix/269-filter-uses-live-status
Open

fix(#269): bucket My Trades filter by live status, not the stale snapshot#299
codaMW wants to merge 2 commits into
MostroP2P:mainfrom
codaMW:fix/269-filter-uses-live-status

Conversation

@codaMW

@codaMW codaMW commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

Each row's status chip shows the live status (tradeStatusProvider), but the filter dropdown bucketed trades using the status loaded once from the DB snapshot (rawTradesProvider -> filteredTradesWithOrderStateProvider). The snapshot only refreshes on pull-to-refresh / retry / after create-take, so changing the filter did not reload it, and status changes arriving via gift wrap / 38383 did not invalidate it.

Result: chip-vs-filter mismatches. A taken order stayed in the Pending bucket while its chip read Waiting Invoice.

Fix

Bucket the filter with the same live status the chip uses, making it the single source of truth. filteredTradesWithOrderStateProvider now reads tradeStatusProvider per trade and buckets on that, falling back to the snapshot status only until the live status has loaded (so nothing briefly escapes the active filter).

Because the provider watches each trade's live status, the list re-buckets in real time: a trade moving Pending to Waiting Invoice leaves the Pending filter immediately, matching its chip. _tradeInfoToItem gained an optional statusOverride so the provider can supply the live bucket without duplicating the mapping.

Testing

  • A trade whose snapshot is Pending but whose live status is Waiting Invoice is excluded from the Pending bucket and included in the Waiting Invoice bucket.
  • The snapshot fallback (live status not yet loaded) is covered.
  • flutter analyze clean; verified on a physical device (Nokia C31): whatever a trade's chip shows, selecting that status in the filter shows it and selecting a different status hides it.

Note on the DB layer

For own orders the 38383 ingest skips syncing Pending back (orders.rs:2873), so the persisted row can remain stale. This change fixes the user-visible mismatch regardless (the live status bypasses the stale snapshot). The persisted-status write-back is a separate data-correctness item and would be a good follow-up; happy to take it on if you'd like it in-scope.

Closes #269.

Summary by CodeRabbit

  • Bug Fixes

    • Trade filtering now reflects the latest live trade status.
    • Trades continue using their saved status until live status information is available.
    • Trade lists now remain consistent with the statuses displayed in trade rows.
  • Tests

    • Added coverage for live-status filtering and fallback behavior.

…tale snapshot

The status filter bucketed each trade using the status loaded once from the DB
snapshot (rawTradesProvider), while the row chip shows the live status from
tradeStatusProvider. The snapshot only refreshes on pull-to-refresh / retry /
after create-take, so status changes arriving via gift wrap / 38383 left the
filter stale: a taken order stayed in the Pending bucket while its chip read
Waiting Invoice.

Bucket the filter with the same live status the chip uses, making it the single
source of truth. filteredTradesWithOrderStateProvider now reads
tradeStatusProvider per trade and buckets on that, falling back to the snapshot
status only until the live status has loaded (so nothing briefly escapes the
active filter). The list re-buckets live, so a trade moving Pending to Waiting
Invoice leaves the Pending filter in real time, matching its chip.

Tests: a trade whose snapshot is Pending but whose live status is Waiting
Invoice is excluded from the Pending bucket and included in the Waiting Invoice
bucket; the snapshot fallback is covered too. Verified on a physical device
(Nokia C31).

Note: the persisted DB row can still be stale for own orders (the 38383 ingest
skips syncing Pending back, orders.rs:2873). This change fixes the user-visible
mismatch regardless; the DB write-back is a separate data-correctness follow-up.

Closes MostroP2P#269.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 45 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: a5b9d11a-a39b-4ae6-af35-3a6e31d1789f

📥 Commits

Reviewing files that changed from the base of the PR and between 7ac86aa and a30e62b.

📒 Files selected for processing (1)
  • test/features/trades/filtered_trades_provider_test.dart

Walkthrough

Trade filtering now uses each trade’s live status when available. It falls back to the persisted snapshot status while live status loads. Tests cover stale snapshots, waiting-invoice classification, and fallback behavior.

Changes

Live status filtering

Layer / File(s) Summary
Status override mapping
lib/features/trades/providers/trades_providers.dart
_tradeInfoToItem accepts an optional status override and uses it instead of the persisted order status when provided.
Live status filtering and validation
lib/features/trades/providers/trades_providers.dart, test/features/trades/filtered_trades_provider_test.dart
Filtered trades use live status values and retain persisted snapshot status until live status is available. Tests cover the live-status buckets and fallback behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FilteredTradesProvider
  participant tradeStatusProvider
  participant _tradeInfoToItem
  FilteredTradesProvider->>tradeStatusProvider: Read live trade status
  tradeStatusProvider-->>FilteredTradesProvider: Return live status or loading state
  FilteredTradesProvider->>_tradeInfoToItem: Pass live or persisted status bucket
  _tradeInfoToItem-->>FilteredTradesProvider: Return filtered trade item
Loading

Suggested reviewers: andreadiazcorreia, grunch

Poem

A rabbit checks the status light,
Live trades hop into the right.
If live data takes its time,
Snapshots keep the bucket line.
“No stale hops!” the rabbit sings.

🚥 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 change: My Trades filters now use live status instead of stale snapshots.
Linked Issues check ✅ Passed The PR implements the live-status filtering fix and snapshot fallback required by [#269].
Out of Scope Changes check ✅ Passed The provider change and related tests directly support [#269] without introducing unrelated scope.
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

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

🤖 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 `@test/features/trades/filtered_trades_provider_test.dart`:
- Around line 100-154: Extend the live-status tests around
staleSnapshotContainer and primeLiveStatus with a controllable status stream.
Assert the trade initially appears in its first live-status bucket, emit a
second status, then verify it is removed from the old bucket and appears in the
new bucket, covering re-bucketing after a live transition.
🪄 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: 873404f7-36a0-4805-aa6c-c4b15707920b

📥 Commits

Reviewing files that changed from the base of the PR and between 7625b24 and 7ac86aa.

📒 Files selected for processing (2)
  • lib/features/trades/providers/trades_providers.dart
  • test/features/trades/filtered_trades_provider_test.dart

Comment thread test/features/trades/filtered_trades_provider_test.dart
Add a test that drives a trade's live status with a controllable stream: assert
it sits in the Pending bucket, emit waitingBuyerInvoice, then assert it leaves
Pending and enters the Waiting Invoice bucket. Covers the live re-bucketing the
filter fix relies on, beyond the initial-status and snapshot-fallback cases.
@codaMW

codaMW commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

@Catrya this is ready for review.

What it does: filteredTradesWithOrderStateProvider now buckets each trade by the live status from tradeStatusProvider (the same source the row chip uses) instead of the DB snapshot, so the chip and the filter share one source of truth. _tradeInfoToItem takes an optional statusOverride so the provider supplies the live bucket without duplicating the mapping. Because it watches each trade's live status, the list re-buckets in real time, and it falls back to the snapshot bucket only until the live status has loaded.

Tests: stale-snapshot excluded from the old bucket, present in the live bucket, snapshot fallback before first poll, and a live-transition test (Pending -> Waiting Invoice) covering the re-bucketing. Verified on a physical device (Nokia C31).

Scope note: I kept the orders.rs:2873 write-back out of this PR. The persisted row can still be stale for own orders, but the UI is correct either way now since it reads live status. I think that write-back is worth doing for data correctness, but it's a distinct Rust change with its own testing (taker-timeout republish), so it felt cleaner as a follow-up. Happy to pick it up next or file it separately, whichever you prefer.

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(trades): My Trades status filter classifies with stale status (snapshot cache + DB row never synced back to Pending)

1 participant