wallet: invalidate stale UI actions when context changes #1046

Closed
pseudoramdom wants to merge 6 commits from wallet-context-invalidation into qt6 AGit
pseudoramdom commented 2026-10-16 06:38:29 +00:00 (Migrated from github.com)

Loading, switching, or unloading wallets while a menu or dialog is open can leave its actions pointing at the newly selected wallet. This can back up the wrong wallet, replace another wallet’s draft, or apply an action to a different request or transaction.

Key Changes

Tie each opening to the context it was opened for.

  • InteractionContext tracks that context, while ContextPopup closes the popup and rejects stale actions when it becomes invalid.
  • WalletContext adds wallet-specific checks without making generic menus and popups depend on wallets.

Each opening gets a fresh token. Switching away and back cannot revive an old opening; the user must open it again.

Apply this to wallet menus, native file dialogs, transaction reviews, signing prompts, and payment-request actions. Keep creation/import completion actions tied to the resulting wallet, reject late migration results, and switch to Activity whenever a closed wallet is loaded.

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

Loading, switching, or unloading wallets while a menu or dialog is open can leave its actions pointing at the newly selected wallet. This can back up the wrong wallet, replace another wallet’s draft, or apply an action to a different request or transaction. ### Key Changes Tie each opening to the context it was opened for. - `InteractionContext` tracks that context, while `ContextPopup` closes the popup and rejects stale actions when it becomes invalid. - `WalletContext` adds wallet-specific checks without making generic menus and popups depend on wallets. Each opening gets a fresh token. Switching away and back cannot revive an old opening; the user must open it again. Apply this to wallet menus, native file dialogs, transaction reviews, signing prompts, and payment-request actions. Keep creation/import completion actions tied to the resulting wallet, reject late migration results, and switch to Activity whenever a closed wallet is loaded. Fixes #991 Fixes #992 Fixes #999 Fixes #1012 Fixes #1013 Fixes #1026 Fixes #1027 Fixes #1028 Fixes #1030 Fixes #1037
jarolrod commented 2026-10-16 07:49:43 +00:00 (Migrated from github.com)

Opened #1048 for the same-wallet draft replacement case, reproduced on 4c085bf954. This predates this PR, and the subsequent review shows the correct payment. It could fit here as a small fix with a regression test, but a separate follow-up is fine too; I don’t think it needs to hold up this PR.

Opened #1048 for the same-wallet draft replacement case, reproduced on 4c085bf95494. This predates this PR, and the subsequent review shows the correct payment. It could fit here as a small fix with a regression test, but a separate follow-up is fine too; I don’t think it needs to hold up this PR.
johnny9 (Migrated from github.com) reviewed 2026-10-18 05:53:03 +00:00
johnny9 (Migrated from github.com) commented 2026-10-18 05:53:03 +00:00

The cancellation is too aggressive. After signing, the backend emits currentTransactionChanged while keeping the same transaction object. This cancels approval before the success signal is handled. Extend the notifications to distinguish replacing the reviewed transaction from updating its signing status, so successful signing does not cancel the current interaction.

The cancellation is too aggressive. After signing, the backend emits `currentTransactionChanged` while keeping the same transaction object. This cancels approval before the success signal is handled. Extend the notifications to distinguish replacing the reviewed transaction from updating its signing status, so successful signing does not cancel the current interaction.
johnny9 (Migrated from github.com) reviewed 2026-10-18 06:19:24 +00:00
johnny9 (Migrated from github.com) commented 2026-10-18 06:19:24 +00:00

With no wallet loaded, selectedWallet is an unavailable placeholder. This makes migrationContext.begin() return null, so clicking Update closes the dialog without starting migration. Use InteractionContext with owner: root and target: root.pendingMigrationPath to track the migration attempt without depending on a loaded or selected wallet.

As a follow-up, we might want to consider adding in the migration progress and completion feedback we had, which seems to have been lost when the flow moved to popups. Keep the dialog open during migration, show which wallet is being updated, and display a clear success or error message. Preserve the existing behaviour of opening and selecting the migrated wallet after success.

With no wallet loaded, `selectedWallet` is an unavailable placeholder. This makes `migrationContext.begin()` return `null`, so clicking Update closes the dialog without starting migration. Use `InteractionContext` with `owner: root` and `target: root.pendingMigrationPath` to track the migration attempt without depending on a loaded or selected wallet. As a follow-up, we might want to consider adding in the migration progress and completion feedback we had, which seems to have been lost when the flow moved to popups. Keep the dialog open during migration, show which wallet is being updated, and display a clear success or error message. Preserve the existing behaviour of opening and selecting the migrated wallet after success.
pseudoramdom commented 2026-10-20 17:24:52 +00:00 (Migrated from github.com)

Closing this in favor of https://github.com/bitcoin-core/gui-qml/pull/1049 which takes a different approach to the same problem.

This PR keeps one set of pages that follows the selected wallet and makes each popup check that its opening is still valid. While that works, the safety depends on every popup opting in: a missed guard reopens the bug, and new popups need the same care.

https://github.com/bitcoin-core/gui-qml/pull/1049 instead gives every open wallet its own set of pages (Activity, Send, Receive and wallet settings). A page's wallet never changes, so anything opened from it can only act on that wallet, with no per-popup guard needed. A wallet's pages close what they own when they're hidden, and actions are refused once a wallet starts unloading.

Closing this in favor of https://github.com/bitcoin-core/gui-qml/pull/1049 which takes a different approach to the same problem. This PR keeps one set of pages that follows the selected wallet and makes each popup check that its opening is still valid. While that works, the safety depends on every popup opting in: a missed guard reopens the bug, and new popups need the same care. https://github.com/bitcoin-core/gui-qml/pull/1049 instead gives every open wallet its own set of pages (Activity, Send, Receive and wallet settings). A page's wallet never changes, so anything opened from it can only act on that wallet, with no per-popup guard needed. A wallet's pages close what they own when they're hidden, and actions are refused once a wallet starts unloading.
Sign in to join this conversation.
No description provided.