Skip to content

fix(demo): keep back stack after wallet creation; spendable Home balance with pending activity card - #127

Open
Shamsudeen12 wants to merge 18 commits into
bitcoindevkit:mainfrom
Shamsudeen12:feat/bdk-demo-home-pending-summary
Open

fix(demo): keep back stack after wallet creation; spendable Home balance with pending activity card#127
Shamsudeen12 wants to merge 18 commits into
bitcoindevkit:mainfrom
Shamsudeen12:feat/bdk-demo-home-pending-summary

Conversation

@Shamsudeen12

@Shamsudeen12 Shamsudeen12 commented Aug 23, 2026

Copy link
Copy Markdown

fix(demo): keep back stack after wallet creation; show spendable Home balance with pending activity card

Stacked on #102. This branch builds on feat/bdk-demo-real-transaction-history (PR #102), so the diff below includes #102's commits until it merges. The new work is only the last two commits (one for #122, one for #119). Happy to rebase once #102 lands.

Summary

Two bdk_demo fixes:

  1. bug: Android back button closes demo app after wallet creation #122 — Android back button closes the app after wallet creation. CreateWalletPage navigated home with context.go, which rewrites the navigation stack, so the system back button had nowhere to pop to and exited the app (while the AppBar arrow worked). Switched to context.replace, which swaps only the current entry and keeps the underlying back stack — system back now behaves like the arrow icon.

  2. bdk_demo: Home shows pending funds as balance; add pending tx summary under Send/Receive #119 — Home shows pending funds as the balance. An unconfirmed incoming transaction bumped the hero Balance (wired to BDK total) even while Trusted spendable read 0. The hero now shows trustedSpendable (confirmed + trusted pending — what can actually be spent), and pending activity gets its own surface below Send/Receive.

Changes for #119

  • Hero balance is driven by trustedSpendableSat. A Total incl. pending: X subtitle appears only when total differs from spendable, so a fully-confirmed wallet shows a single unambiguous figure.
  • Pending activity card below the Send/Receive row, visible while the balance snapshot has trusted/untrusted pending funds:
    • summed pending amount (follows the BTC/sat unit toggle),
    • up to three pending transaction rows (reusing the transactions controller, list-row conventions, and WalletStatusChip), each opening Transaction Detail,
    • a View all (N) link into Transaction History when there are more.
  • Card visibility is snapshot-driven, sharing the exact guarded snapshot the hero uses. Since SyncController applies a fresh snapshot synchronously at sync completion, the card clears the moment a post-confirmation sync lands — no stale pending UI. Rows background-refresh after every sync via the transactions controller's existing activeWalletProvider listener; no new plumbing.
  • immatureSat (coinbase maturation) is deliberately excluded from the card — it isn't mempool-pending and no sync will confirm it soon; it still surfaces via the Total incl. pending subtitle.
  • Support changes: pendingSat getter on WalletBalanceSnapshot, and a @visibleForTesting applySnapshot seam on BalanceSnapshotNotifier (widget tests previously had no way to seed non-zero pending values, since they use real zero-balance wallets).

Screenshots

#119 — unconfirmed receive:
Screenshot_20260823_003857

Acceptance criteria (#119)

  • With only an unconfirmed receive, Home hero balance stays 0 (spendable semantics).
  • Home shows a pending indicator/summary below Send/Receive for that receive.
  • After the tx confirms and the wallet syncs, pending UI clears and hero balance includes the funds.
  • Widget coverage for Home with untrusted-pending-only snapshot.

Testing

  • flutter analyze: clean.
  • flutter test: full suite green.
  • New widget tests in test/presentation/home_page_test.dart: untrusted-pending-only snapshot (hero 0, card showing +25000 sat), card hidden with no pending, card clears after confirmation + sync, three-row cap with View all (4), and unit-toggle propagation. Row-tap navigation reuses the same pushNamed('transactionDetail') call already covered by the transactions list tests.

Known limitation (accepted)

A full-sweep outgoing tx (no change output) leaves every pending bucket at 0 while a pending transaction exists, so the card stays hidden; the tx remains visible on the Transactions page. Cost of the single-source-of-truth visibility rule — a one-line change if we'd rather show it.

Closes #122
Closes #119

@Shamsudeen12
Shamsudeen12 marked this pull request as ready for review August 23, 2026 00:10

@Johnosezele Johnosezele left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shamsudeen12 you have 16 unrelated commits here, pls rebase your own commits onto main and force-push, also make sure to sign your commits. Thanks!

@Shamsudeen12

Copy link
Copy Markdown
Author

@Shamsudeen12 you have 16 unrelated commits here, pls rebase your own commits onto main and force-push, also make sure to sign your commits. Thanks!

@Johnosezele The unrelated commits are because the PR depends on #102. I can wait until that gets merged and then rebase on main, but the related commits are just the last two

Home previously displayed wallet.balance().total as the hero figure, so
an unconfirmed incoming transaction inflated the balance while Trusted
spendable stayed at 0.

- Drive the hero balance from trustedSpendableSat; show a "Total incl.
  pending" subtitle only when total differs from spendable
- Add a pending activity card below Send/Receive while the balance
  snapshot has trusted/untrusted pending funds: summed pending amount,
  up to three pending transaction rows opening Transaction Detail, and
  a View all link into Transaction History
- Keep card visibility snapshot-driven so it clears as soon as a
  post-confirmation sync applies the fresh balance
- Add a pendingSat getter on WalletBalanceSnapshot and a
  @VisibleForTesting applySnapshot seam on BalanceSnapshotNotifier
- Cover untrusted-pending-only, no-pending, clear-after-sync, row-cap,
  and unit-toggle cases in home_page_test

Closes bitcoindevkit#119
@Shamsudeen12
Shamsudeen12 force-pushed the feat/bdk-demo-home-pending-summary branch from 763a112 to 2a2a5f7 Compare August 23, 2026 11:06
@Ugarba202

Copy link
Copy Markdown
Contributor

@Shamsudeen12 tACK 2a2a5f7 on Linux.

Tested the changes locally the pending card on Home and the spendable hero balance work as expected, and pressing back after wallet creation now properly returns to the active wallets list instead of exiting the app. All demo tests passed on my end.
One thing I noticed while checking the navigation fix: recover_wallet_page.dart (lines 97 and 150) still uses context.go(AppRoutes.home). Might be worth updating those to context.replace as well so wallet recovery gets the exact same back stack fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants