qml, wallet: give each open wallet its own view #1049

Manually merged
pseudoramdom merged 9 commits from wallet-view into qt6 2026-11-03 17:14:44 +00:00 AGit
pseudoramdom commented 2026-10-20 17:18:19 +00:00 (Migrated from github.com)

Loading, switching, or unloading wallets while a menu, dialog, or confirmation is open can leave it acting on a different wallet than the one it was opened for. This can back up the wrong wallet, replace another wallet's draft, export another wallet's history, or sign a transaction the user never reviewed.

This is an alternative approach to #1046. Instead of guarding each popup with a context token, every open wallet gets its own set of pages. A page's wallet never changes, so anything opened from a wallet's pages can only act on that wallet.

Key Changes

  • DesktopWallets keeps one WalletView per open wallet, built from the new walletController.openWallets. A view holds Activity, Send, Receive and wallet settings, each with its own navigation stack. Only the selected wallet's view is shown; hidden views keep their tab, drafts and navigation. A wallet's view is destroyed when the wallet closes or unloads.
    • The nav bar stays in the shell. The block clock, peers and settings pages exist once and are shared; the settings page shows the active wallet's settings stack in its Wallet section.
  • Wallet pages take their wallet as an input instead of reading walletController.selectedWallet. Controller requests that concern one wallet (open Receive, open wallet settings, close a request detail) now name that wallet, and only its view reacts.

Relation to #1046

This supersedes #1046.
#1046 keeps one set of pages that follows the selected wallet and makes each popup check that its opening is still valid. That works, but safety depends on every popup opting in: a missed guard reopens the bug, and new popups need the same care. Treating any selection change as invalidation also broke legacy wallet migration when no wallet is loaded.

Here the wallet cannot change underneath a page, so wrong-wallet actions are prevented by structure and need no per-popup code. The cases per-wallet views cannot catch (replacement within the same wallet, completion screens, the window while a wallet unloads) get targeted checks instead.

Notes

  • Each kept-alive view costs about 45 MB RSS (regtest, -dbcache=100: 258/348/439 MB with 1/3/5 wallets, versus 257/314/325 MB when only the shown view exists). Idle CPU is unchanged, since hidden views do not render. Views stay alive to keep per-wallet state and as groundwork for showing wallets side by side.
  • Also fixes a few clang-only warnings (-Wcovered-switch-default, an inexact long double bound in the sync estimate).

Fixes #991
Fixes #992
Fixes #999
Fixes #1012
Fixes #1013
Fixes #1026
Fixes #1027
Fixes #1028
Fixes #1030
Fixes #1037
Fixes #1048

Loading, switching, or unloading wallets while a menu, dialog, or confirmation is open can leave it acting on a different wallet than the one it was opened for. This can back up the wrong wallet, replace another wallet's draft, export another wallet's history, or sign a transaction the user never reviewed. This is an alternative approach to #1046. Instead of guarding each popup with a context token, every open wallet gets its own set of pages. A page's wallet never changes, so anything opened from a wallet's pages can only act on that wallet. ### Key Changes - `DesktopWallets` keeps one `WalletView` per open wallet, built from the new `walletController.openWallets`. A view holds Activity, Send, Receive and wallet settings, each with its own navigation stack. Only the selected wallet's view is shown; hidden views keep their tab, drafts and navigation. A wallet's view is destroyed when the wallet closes or unloads. - The nav bar stays in the shell. The block clock, peers and settings pages exist once and are shared; the settings page shows the active wallet's settings stack in its Wallet section. - Wallet pages take their wallet as an input instead of reading `walletController.selectedWallet`. Controller requests that concern one wallet (open Receive, open wallet settings, close a request detail) now name that wallet, and only its view reacts. ### Relation to #1046 This supersedes #1046. #1046 keeps one set of pages that follows the selected wallet and makes each popup check that its opening is still valid. That works, but safety depends on every popup opting in: a missed guard reopens the bug, and new popups need the same care. Treating any selection change as invalidation also broke legacy wallet migration when no wallet is loaded. Here the wallet cannot change underneath a page, so wrong-wallet actions are prevented by structure and need no per-popup code. The cases per-wallet views cannot catch (replacement within the same wallet, completion screens, the window while a wallet unloads) get targeted checks instead. ### Notes - Each kept-alive view costs about 45 MB RSS (regtest, `-dbcache=100`: 258/348/439 MB with 1/3/5 wallets, versus 257/314/325 MB when only the shown view exists). Idle CPU is unchanged, since hidden views do not render. Views stay alive to keep per-wallet state and as groundwork for showing wallets side by side. - Also fixes a few clang-only warnings (`-Wcovered-switch-default`, an inexact `long double` bound in the sync estimate). Fixes #991 Fixes #992 Fixes #999 Fixes #1012 Fixes #1013 Fixes #1026 Fixes #1027 Fixes #1028 Fixes #1030 Fixes #1037 Fixes #1048
pseudoramdom (Migrated from github.com) reviewed 2026-10-20 21:21:48 +00:00
pseudoramdom (Migrated from github.com) left a comment

Left a review on the wrong PR. I don't know how to delete this comment.

Left a review on the wrong PR. I don't know how to delete this comment.
johnny9 (Migrated from github.com) reviewed 2026-10-21 09:14:18 +00:00
johnny9 (Migrated from github.com) commented 2026-10-21 09:14:18 +00:00

RPC loadwallet can switch to wallet B while a Send field in wallet A keeps keyboard focus. Further typing edits A’s hidden draft while B is displayed. Hiding the view does not clear focus. Disable inactive wallet views or clear their focus when switching wallets.

RPC `loadwallet` can switch to wallet B while a Send field in wallet A keeps keyboard focus. Further typing edits A’s hidden draft while B is displayed. Hiding the view does not clear focus. Disable inactive wallet views or clear their focus when switching wallets.
pseudoramdom (Migrated from github.com) reviewed 2026-10-21 18:38:00 +00:00
pseudoramdom (Migrated from github.com) commented 2026-10-21 18:38:00 +00:00

Addressed in 5e3bbb9f42

Addressed in 5e3bbb9f4263afdd4d426d0d000b56070ab0f29a
AndreaDiazCorreia (Migrated from github.com) reviewed 2026-10-25 13:18:37 +00:00
AndreaDiazCorreia (Migrated from github.com) left a comment

Tested 97868a6488 with real regtest wallets on Linux / Qt 6.12.0.

Keyboard focus can return to a hidden wallet:

  1. In wallet A, prepare a payment and open Review using Space.
  2. Run loadwallet B over RPC.
  3. After the review closes, press Space again.

This reopens A's review while B is selected. Closing the popup restores focus to A's hidden Review button.

I also reproduced a possible stale wallet-creation success page in a mocked QML test, but could not confirm it with the real backend.

Tested 97868a6488 with real regtest wallets on Linux / Qt 6.12.0. Keyboard focus can return to a hidden wallet: 1. In wallet A, prepare a payment and open Review using Space. 2. Run `loadwallet B` over RPC. 3. After the review closes, press Space again. This reopens A's review while B is selected. Closing the popup restores focus to A's hidden Review button. I also reproduced a possible stale wallet-creation success page in a mocked QML test, but could not confirm it with the real backend.
pseudoramdom commented 2026-10-27 04:00:55 +00:00 (Migrated from github.com)

Tested 97868a6 with real regtest wallets on Linux / Qt 6.12.0.

Keyboard focus can return to a hidden wallet:

  1. In wallet A, prepare a payment and open Review using Space.
  2. Run loadwallet B over RPC.
  3. After the review closes, press Space again.

This reopens A's review while B is selected. Closing the popup restores focus to A's hidden Review button.

I also reproduced a possible stale wallet-creation success page in a mocked QML test, but could not confirm it with the real backend.

Thanks for testing. I was also able to reproduce. Fixed in a07acc8dd2.

> Tested [97868a6](https://github.com/bitcoin-core/gui-qml/commit/97868a64882f82e9e554f4f7cd2d002b304bedac) with real regtest wallets on Linux / Qt 6.12.0. > > Keyboard focus can return to a hidden wallet: > > 1. In wallet A, prepare a payment and open Review using Space. > 2. Run `loadwallet B` over RPC. > 3. After the review closes, press Space again. > > This reopens A's review while B is selected. Closing the popup restores focus to A's hidden Review button. > > I also reproduced a possible stale wallet-creation success page in a mocked QML test, but could not confirm it with the real backend. Thanks for testing. I was also able to reproduce. Fixed in a07acc8dd2.
First-time contributor

🟠 Minor · Hiding Send dismisses completion without clearing the sent draft

WalletView.pageHidden(sendPage) closes transactionReviewPopup when Send hides. The popup's onClosed never calls resetSendForm, so the broadcast payment's recipients stay in the form. This is newly reachable through same-wallet navigation; reachability while the popup is open relies on native menus.

Location: qml/pages/wallet/WalletView.qml:191 (head).

🟠 Minor · MainRouting lacks the open-wallet fixture needed for focused runs

tst_mainrouting.createMain never calls setOpenWallets, and the mock's reset() leaves m_open_wallets alone. Run on their own, these tests get no WalletView, so openSend and openWallet do nothing and the tab and creation-completion routing tests fail; they rely on state left by earlier test files.

Location: test/qml/tst_mainrouting.qml:50 (head).

🔵 Suggestion · Unvisited startup wallets also load and poll their activity

Creating views eagerly loads history and starts polling for startup wallets that are never selected; creating each view on first selection and retaining it would avoid that work without losing visited-wallet state.

Location: qml/pages/wallet/DesktopWallets.qml:50 (head).

🔵 Suggestion · Per-wallet Activity preferences still share app-wide storage keys

Changing Activity grouping or density leaves other open wallets on their old values, but all views persist under the same keys, making the preferences neither consistently app-wide nor reliably per-wallet.

Location: qml/pages/wallet/WalletView.qml:186 (head).

🔵 Suggestion · Fee bumping and message signing omit the closing-wallet gate

BumpTransactionModel::confirmFeeBumpInternal and SignVerifyMessageModel::signMessageInternal check only m_wallet, not the new unload flag. Until beginShutdown detaches them, a confirmed fee bump or message signature can still go through after available() is false. This is the same as base behaviour.

Location: qml/models/bumptransactionmodel.cpp:142 (head).

Review coverage was incomplete.


Reviewed: c0aac977c710 · Full review report · Previous reports

permalink

<!-- ralph:bitcoin-core/gui-qml --> <!-- ralph-engine:current:965af1044d9e41839565702e4d9bd0a751eda81f6e8b6402747fa296ef84ebea:f7677f01bbeeeda2e9dfb365f1407384e31618edbeddff6daa5ff425bb8651e2 --> <!-- ralph-base:6cdad5344018f35e8c33c77a23f6ba996d507549 --> <!-- ralph-head:c0aac977c710fcc502147cdb0994e17bb9e6f832 --> <!-- ralph-case:f3b0a32e5708560e9698e422b28e6c5dc688bb690a4dbb3b125d0b19578140c4 --> **🟠 Minor · Hiding Send dismisses completion without clearing the sent draft** WalletView.pageHidden(sendPage) closes transactionReviewPopup when Send hides. The popup's onClosed never calls resetSendForm, so the broadcast payment's recipients stay in the form. This is newly reachable through same-wallet navigation; reachability while the popup is open relies on native menus. Location: [`qml/pages/wallet/WalletView.qml:191`](<https://git.fish.foo/bitcoin-core/gui-qml/src/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832/qml/pages/wallet/WalletView.qml#L191>) (head). **🟠 Minor · MainRouting lacks the open-wallet fixture needed for focused runs** tst_mainrouting.createMain never calls setOpenWallets, and the mock's reset() leaves m_open_wallets alone. Run on their own, these tests get no WalletView, so openSend and openWallet do nothing and the tab and creation-completion routing tests fail; they rely on state left by earlier test files. Location: [`test/qml/tst_mainrouting.qml:50`](<https://git.fish.foo/bitcoin-core/gui-qml/src/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832/test/qml/tst_mainrouting.qml#L50>) (head). **🔵 Suggestion · Unvisited startup wallets also load and poll their activity** Creating views eagerly loads history and starts polling for startup wallets that are never selected; creating each view on first selection and retaining it would avoid that work without losing visited-wallet state. Location: [`qml/pages/wallet/DesktopWallets.qml:50`](<https://git.fish.foo/bitcoin-core/gui-qml/src/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832/qml/pages/wallet/DesktopWallets.qml#L50>) (head). **🔵 Suggestion · Per-wallet Activity preferences still share app-wide storage keys** Changing Activity grouping or density leaves other open wallets on their old values, but all views persist under the same keys, making the preferences neither consistently app-wide nor reliably per-wallet. Location: [`qml/pages/wallet/WalletView.qml:186`](<https://git.fish.foo/bitcoin-core/gui-qml/src/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832/qml/pages/wallet/WalletView.qml#L186>) (head). **🔵 Suggestion · Fee bumping and message signing omit the closing-wallet gate** BumpTransactionModel::confirmFeeBumpInternal and SignVerifyMessageModel::signMessageInternal check only m_wallet, not the new unload flag. Until beginShutdown detaches them, a confirmed fee bump or message signature can still go through after available() is false. This is the same as base behaviour. Location: [`qml/models/bumptransactionmodel.cpp:142`](<https://git.fish.foo/bitcoin-core/gui-qml/src/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832/qml/models/bumptransactionmodel.cpp#L142>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`c0aac977c710`](<https://git.fish.foo/bitcoin-core/gui-qml/commit/c0aac977c710fcc502147cdb0994e17bb9e6f832>) · [Full review report](<https://review.fish.foo/traces/gui/1049-c0aac977c710fcc502147cdb0994e17bb9e6f832-1950-2.html>) · [Previous reports](<https://review.fish.foo/traces/1049/>) [permalink](<https://review.fish.foo/traces/gui/1049-c0aac977c710fcc502147cdb0994e17bb9e6f832-1950-2.html>)
rreview commented 2026-11-01 23:36:04 +00:00 (Migrated from github.com)

🔵 Suggestion · Fee bumping and message signing skip the new closing-wallet gate

The new closing-wallet refusal does not cover fee bumps or message signatures submitted before queued teardown, although those actions still require normal authorization.

Location: qml/models/walletqmlmodel.h:222 (head).

🔵 Suggestion · External signer approval on a closing wallet reports a missing signer

An approval attempted during the short unload interval reports "External signer not available." rather than explaining that the wallet is closing.

Location: qml/models/walletqmlmodel.cpp:2425 (head).

🔵 Suggestion · Unvisited startup wallets allocate full page sets

DesktopWallets.syncOpenWallets builds a WalletView for every open wallet, though startup selects only the first. Each view's ActivityList creates that wallet's TransactionActivityModel, which loads history and polls every second, even if the wallet is never shown.

Location: qml/pages/wallet/DesktopWallets.qml:50 (head).

🔵 Suggestion · Per-wallet Activity preferences still share app-wide storage keys

Each WalletView's ActivityListPage has its own AppSettings using the shared activityGrouping and activityDisplayDensity keys. Changing them in one wallet leaves other open views on the old value, while new views and restarts read the last value written, so the setting is neither global nor reliably per-wallet.

Location: qml/pages/wallet/WalletView.qml:186 (head).

Review coverage was incomplete.


Reviewed: 63346e0200e6 · Full review report

<!-- ralph-major:bitcoin-core/gui-qml --> **🔵 Suggestion · Fee bumping and message signing skip the new closing-wallet gate** The new closing-wallet refusal does not cover fee bumps or message signatures submitted before queued teardown, although those actions still require normal authorization. Location: [qml/models/walletqmlmodel.h:222](<https://github.com/bitcoin-core/gui-qml/blob/63346e0200e61f0b200dfeec5bee0645dbf75744/qml/models/walletqmlmodel.h#L222>) (head). **🔵 Suggestion · External signer approval on a closing wallet reports a missing signer** An approval attempted during the short unload interval reports "External signer not available." rather than explaining that the wallet is closing. Location: [qml/models/walletqmlmodel.cpp:2425](<https://github.com/bitcoin-core/gui-qml/blob/63346e0200e61f0b200dfeec5bee0645dbf75744/qml/models/walletqmlmodel.cpp#L2425>) (head). **🔵 Suggestion · Unvisited startup wallets allocate full page sets** DesktopWallets.syncOpenWallets builds a WalletView for every open wallet, though startup selects only the first. Each view's ActivityList creates that wallet's TransactionActivityModel, which loads history and polls every second, even if the wallet is never shown. Location: [qml/pages/wallet/DesktopWallets.qml:50](<https://github.com/bitcoin-core/gui-qml/blob/63346e0200e61f0b200dfeec5bee0645dbf75744/qml/pages/wallet/DesktopWallets.qml#L50>) (head). **🔵 Suggestion · Per-wallet Activity preferences still share app-wide storage keys** Each WalletView's ActivityListPage has its own AppSettings using the shared activityGrouping and activityDisplayDensity keys. Changing them in one wallet leaves other open views on the old value, while new views and restarts read the last value written, so the setting is neither global nor reliably per-wallet. Location: [qml/pages/wallet/WalletView.qml:186](<https://github.com/bitcoin-core/gui-qml/blob/63346e0200e61f0b200dfeec5bee0645dbf75744/qml/pages/wallet/WalletView.qml#L186>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`63346e0200e6`](<https://github.com/bitcoin-core/gui-qml/commit/63346e0200e61f0b200dfeec5bee0645dbf75744>) · [Full review report](<https://review.fish.foo/traces/gui/1049-63346e0200e61f0b200dfeec5bee0645dbf75744-2006-3.html>)
pseudoramdom commented 2026-11-02 18:46:48 +00:00 (Migrated from github.com)

Resolved the two minor bugs reported by Ralph

Resolved the two minor bugs reported by Ralph
johnny9 (Migrated from github.com) approved these changes 2026-11-03 11:37:00 +00:00
johnny9 (Migrated from github.com) left a comment

ACK 63346e0200

Tested native backup, PSBT import and CSV export dialogs during wallet switch, unload and Quit. Wallet shutdown tests passed, including shutdown while startup wallets were loading.

Memory use with many open wallets can be checked in a follow-up. Each wallet keeps its pages alive. Views are removed on unload, but I have not measured memory use over repeated load/unload cycles. I found no confirmed memory issue that blocks this PR.

ACK 63346e0200e61f0b200dfeec5bee0645dbf75744 Tested native backup, PSBT import and CSV export dialogs during wallet switch, unload and Quit. Wallet shutdown tests passed, including shutdown while startup wallets were loading. Memory use with many open wallets can be checked in a follow-up. Each wallet keeps its pages alive. Views are removed on unload, but I have not measured memory use over repeated load/unload cycles. I found no confirmed memory issue that blocks this PR.
Sign in to join this conversation.
No description provided.