Watch-only wallet, wallet loading status #727

Manually merged
pseudoramdom merged 26 commits from wallet-loading-status into qt6 2026-06-02 19:13:29 +00:00 AGit
pseudoramdom commented 2026-05-26 18:41:53 +00:00 (Migrated from github.com)

This PR consolidates watch-only wallet creation and tracks per-wallet load states. It also bundles in small improvements to wallet picker view.

  • Watch-only wallet - Supersedes https://github.com/bitcoin-core/gui-qml/pull/565 fixes #617
  • Other wallet creation improvements
    • Move wallet creation off UI thread and show loading indicator (fixes #616)
    • ScreenshotScreenshot 2026-05-26 at 11 33 20 AM
    • Validate wallet name availability before creation - supersedes #686 which fixes #571, fixes #711
    • Show inline password mismatch error in wallet creation flow (fixes #573)
    • Screenshot Screenshot 2026-05-26 at 9 53 47 AM

Wallet picker improvements

  • Introduce per-wallet loading state in the wallet picker
  • Each wallet entry in the picker will show the icon reflecting the wallet key scheme and load status. It shows the balance if loaded. (fixes #621 )
  • ScreenshotScreenshot 2026-05-26 at 11 40 35 AM
  • Show an error if a wallet failed to load (fixes #618)
  • ScreenshotScreenshot 2026-05-13 at 1 40 37 PM
  • Show confirmation popup before closing wallet (fixes #574)
  • ScreenshotScreenshot 2026-05-26 at 9 52 35 AM
  • Truncate long wallet names and show tooltip on hover and handle long wallets list (fixes #699, fixes #700)
  • ScreenshotScreenshot 2026-05-26 at 11 12 58 AM
This PR consolidates watch-only wallet creation and tracks per-wallet load states. It also bundles in small improvements to wallet picker view. - Watch-only wallet - Supersedes https://github.com/bitcoin-core/gui-qml/pull/565 fixes #617 - Other wallet creation improvements - Move wallet creation off UI thread and show loading indicator (fixes #616) - <details> <summary>Screenshot</summary><img width="719" height="729" alt="Screenshot 2026-05-26 at 11 33 20 AM" src="https://git.fish.foo/attachments/a6cc3aa0-6554-4d1a-8e24-89556d43b07b" /></details> - Validate wallet name availability before creation - supersedes #686 which fixes #571, fixes #711 - Show inline password mismatch error in wallet creation flow (fixes #573) - <details> <summary>Screenshot</summary> <img width="1503" height="1098" alt="Screenshot 2026-05-26 at 9 53 47 AM" src="https://git.fish.foo/attachments/d39ddac8-1979-4956-86cd-bfaa87aa9240" /></details> Wallet picker improvements - Introduce per-wallet loading state in the wallet picker - Each wallet entry in the picker will show the icon reflecting the wallet key scheme and load status. It shows the balance if loaded. (fixes #621 ) - <details> <summary>Screenshot</summary><img width="261" height="456" alt="Screenshot 2026-05-26 at 11 40 35 AM" src="https://git.fish.foo/attachments/dafc291c-2e9b-404f-8e91-620ca4edef20" /></details> - Show an error if a wallet failed to load (fixes #618) - <details><summary>Screenshot</summary><img width="1331" height="1014" alt="Screenshot 2026-05-13 at 1 40 37 PM" src="https://git.fish.foo/attachments/c54287df-8a14-47d4-a666-1951d84403ac" /></details> - Show confirmation popup before closing wallet (fixes #574) - <details><summary>Screenshot</summary><img width="1503" height="1098" alt="Screenshot 2026-05-26 at 9 52 35 AM" src="https://git.fish.foo/attachments/77e5a158-be20-4911-a9c5-f73ec33db79c" /></details> - Truncate long wallet names and show tooltip on hover and handle long wallets list (fixes #699, fixes #700) - <details><summary>Screenshot</summary><img width="315" height="469" alt="Screenshot 2026-05-26 at 11 12 58 AM" src="https://git.fish.foo/attachments/265b6ad8-1d99-4a7d-ba72-9043a9ee87be" /></details>
johnny9 (Migrated from github.com) reviewed 2026-05-27 03:20:42 +00:00
johnny9 (Migrated from github.com) commented 2026-05-27 03:20:37 +00:00

add create_wallet_name functional test as well as the wallet selector functional test to the workflow

add create_wallet_name functional test as well as the wallet selector functional test to the workflow
johnny9 (Migrated from github.com) reviewed 2026-05-27 04:04:07 +00:00
johnny9 (Migrated from github.com) left a comment

Be sure to update unittest to cover needed changes.

Be sure to update unittest to cover needed changes.
johnny9 (Migrated from github.com) commented 2026-05-27 03:44:43 +00:00

this property seems redundant

this property seems redundant
johnny9 (Migrated from github.com) commented 2026-05-27 03:54:12 +00:00

this should probably be based on a different condition. If another wallet is already loaded and watch-only creation fails at qml/walletqmlcontroller.cpp (line 456) or qml/walletqmlcontroller.cpp (line 502), the wizard can still push the success screen.

this should probably be based on a different condition. If another wallet is already loaded and watch-only creation fails at qml/walletqmlcontroller.cpp (line 456) or qml/walletqmlcontroller.cpp (line 502), the wizard can still push the success screen.
johnny9 (Migrated from github.com) commented 2026-05-27 03:54:59 +00:00
property bool creatingWatchOnly: false

Connections {
    target: walletController

    function onWalletCreateSucceeded() {
        if (!root.creatingWatchOnly) return
        root.creatingWatchOnly = false
        root.push(watchOnlyConfirm)
    }

    function onWalletCreateErrorChanged() {
        if (root.creatingWatchOnly && walletController.walletCreateError.length > 0) {
            root.creatingWatchOnly = false
        }
    }

    function onWalletLoadErrorChanged() {
        if (root.creatingWatchOnly && walletController.walletLoadError.length > 0) {
            root.creatingWatchOnly = false
        }
    }
}
``` property bool creatingWatchOnly: false Connections { target: walletController function onWalletCreateSucceeded() { if (!root.creatingWatchOnly) return root.creatingWatchOnly = false root.push(watchOnlyConfirm) } function onWalletCreateErrorChanged() { if (root.creatingWatchOnly && walletController.walletCreateError.length > 0) { root.creatingWatchOnly = false } } function onWalletLoadErrorChanged() { if (root.creatingWatchOnly && walletController.walletLoadError.length > 0) { root.creatingWatchOnly = false } } } ```
johnny9 (Migrated from github.com) commented 2026-05-27 03:49:27 +00:00

we should let the wallet loader notification handler create the wallet model. doing it this way creates a duplicate model in the list and closing the wallet will have issues.

we should let the wallet loader notification handler create the wallet model. doing it this way creates a duplicate model in the list and closing the wallet will have issues.
johnny9 (Migrated from github.com) commented 2026-05-27 03:51:44 +00:00

something like

  1. In createWatchOnlyWallet(), validate name/xpub, set loading state, and mark the expected wallet name as “defer adoption”.
  2. Let createWallet() fire NotifyWalletLoaded().
  3. In handleLoadWallet(), if the loaded wallet name matches the deferred watch-only create, stash the interfaces::Wallet and return without registering a model.
  4. Import both descriptors into the returned wallet.
  5. If descriptor import fails, unload/remove the just-created wallet and report create error.
  6. If descriptor import succeeds, call handleLoadWallet(std::move(deferred_wallet)) once, with m_pending_wallet_load_action = WalletLoadAction::Create, so the normal path registers the model and emits walletCreateSucceeded().
something like 1. In createWatchOnlyWallet(), validate name/xpub, set loading state, and mark the expected wallet name as “defer adoption”. 2. Let createWallet() fire NotifyWalletLoaded(). 3. In handleLoadWallet(), if the loaded wallet name matches the deferred watch-only create, stash the interfaces::Wallet and return without registering a model. 4. Import both descriptors into the returned wallet. 5. If descriptor import fails, unload/remove the just-created wallet and report create error. 6. If descriptor import succeeds, call handleLoadWallet(std::move(deferred_wallet)) once, with m_pending_wallet_load_action = WalletLoadAction::Create, so the normal path registers the model and emits walletCreateSucceeded().
johnny9 (Migrated from github.com) commented 2026-05-27 04:00:29 +00:00

We should fill in these values for the descriptor. This can be a followup issue as it likely requires designing the wizard to include these choices and maybe a date picker

We should fill in these values for the descriptor. This can be a followup issue as it likely requires designing the wizard to include these choices and maybe a date picker
johnny9 (Migrated from github.com) commented 2026-05-27 04:03:32 +00:00

i think you need to trim the string as

QDir::cleanPath(" ") -> " "
QDir::cleanPath(" foo ") -> " foo "
QDir::cleanPath("./foo//bar") -> "foo/bar"
QDir::cleanPath("foo/../bar") -> "bar"

cleanPath can still get " " through this condition

i think you need to trim the string as QDir::cleanPath(" ") -> " " QDir::cleanPath(" foo ") -> " foo " QDir::cleanPath("./foo//bar") -> "foo/bar" QDir::cleanPath("foo/../bar") -> "bar" cleanPath can still get " " through this condition
johnny9 (Migrated from github.com) reviewed 2026-05-27 04:17:41 +00:00
johnny9 (Migrated from github.com) commented 2026-05-27 04:17:08 +00:00

The CreateIntro page can be removed now

The CreateIntro page can be removed now
johnny9 (Migrated from github.com) commented 2026-05-27 04:17:37 +00:00

We should include external signer walets in this list if it is configured

We should include external signer walets in this list if it is configured
pseudoramdom (Migrated from github.com) reviewed 2026-05-27 04:35:53 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-27 04:35:53 +00:00

That's embarrassing I didn't check the line above

That's embarrassing I didn't check the line above
johnny9 (Migrated from github.com) reviewed 2026-05-28 18:11:54 +00:00
johnny9 (Migrated from github.com) commented 2026-05-28 18:11:54 +00:00

we're moving fast, its going to happen and we're going to find more once things settle

we're moving fast, its going to happen and we're going to find more once things settle
pseudoramdom (Migrated from github.com) reviewed 2026-05-28 19:55:40 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-28 19:55:40 +00:00

You mean this page is to be removed? Sure? I see it on Figma and the core-app website
Screenshot 2026-05-28 at 12 53 54 PM

You mean this page is to be removed? Sure? I see it on [Figma](https://www.figma.com/design/ek8w3n3upbluw5UL2lGhRx/Bitcoin-Core-App-Design?node-id=7705-669020&t=H1DSZVkpr6RiFiNT-0) and the [core-app website](https://bitcoincore.app/milestones/1-4-create/) <img width="1222" height="947" alt="Screenshot 2026-05-28 at 12 53 54 PM" src="https://git.fish.foo/attachments/67e56c5e-8826-4d42-bde9-5b7ca3c84838" />
pseudoramdom (Migrated from github.com) reviewed 2026-05-29 16:44:01 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-29 16:44:01 +00:00

Added in 48d0575

Added in [48d0575](https://github.com/bitcoin-core/gui-qml/pull/727/commits/48d057518da4d53cdf692a00c03b4d241f80f33c)
pseudoramdom (Migrated from github.com) reviewed 2026-05-29 17:54:22 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-29 17:54:22 +00:00

This took a bit more time than I anticipated. Updated now.

This took a bit more time than I anticipated. Updated now.
pseudoramdom (Migrated from github.com) reviewed 2026-05-29 18:01:40 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-29 18:01:40 +00:00
https://github.com/bitcoin-core/gui-qml/issues/735
johnny9 (Migrated from github.com) reviewed 2026-05-29 18:47:11 +00:00
johnny9 (Migrated from github.com) commented 2026-05-29 18:47:11 +00:00

I meant the create wallet wizard page should just be the create type selector page

I meant the create wallet wizard page should just be the create type selector page
jarolrod (Migrated from github.com) reviewed 2026-05-29 18:56:28 +00:00
jarolrod (Migrated from github.com) commented 2026-05-29 18:56:29 +00:00

this is running synchronously on the qml controller thread.

The updated defer logic handles the model duplication problem, which is good. But the heavy wallet work is still happening inline here.

  • WalletLoader::createWallet() calls into CreateWallet(), which can create or open wallet db storage, initialize wallet state, emit the load notification, add the wallet to the wallet context, run init processing, and update wallet settings.
  • AddWalletDescriptor() persists descriptors and tops up descriptor script caches. Even if this is normally fast, it is still filesystem and wallet setup work being run from a QML invoked method.

That differs from the rest of the controller methods we have implemented:

  • createSingleSigWallet(), createExternalSignerWallet(), startWalletLoad(), and startWalletImport() all post the wallet operation to m_worker and then marshal back to the controller thread for QML state updates.

I think the correct model we should maintain is wallet & db work runs outside of the UI thread; model adoption and signal emission stay on the QML thread.

this is running synchronously on the qml controller thread. The updated defer logic handles the model duplication problem, which is good. But the heavy wallet work is still happening inline here. - `WalletLoader::createWallet()` calls into `CreateWallet()`, which can create or open wallet db storage, initialize wallet state, emit the load notification, add the wallet to the wallet context, run init processing, and update wallet settings. - `AddWalletDescriptor()` persists descriptors and tops up descriptor script caches. Even if this is normally fast, it is still filesystem and wallet setup work being run from a QML invoked method. That differs from the rest of the controller methods we have implemented: - `createSingleSigWallet()`, `createExternalSignerWallet()`, `startWalletLoad()`, and `startWalletImport()` all post the wallet operation to `m_worker` and then marshal back to the controller thread for QML state updates. I think the correct model we should maintain is wallet & db work runs _outside_ of the UI thread; model adoption and signal emission stay on the QML thread.
jarolrod (Migrated from github.com) reviewed 2026-05-29 20:17:49 +00:00
jarolrod (Migrated from github.com) commented 2026-05-29 20:17:49 +00:00

This part intrigued me, so I dug into whether the pending wallet operation is actually tied to the wallet that just loaded. I think there is still a very real lifecycle bug here; that might be worthwhile to address in this PR.

The QML controller currently tracks “some wallet operation is pending” with m_wallet_load_requested and m_pending_wallet_load_action, but it does not track the target wallet name/path for that pending operation. handleLoadWallet() is registered as the global Core wallet-loaded callback, so it can be called for any wallet load notification, not only the wallet caused by the current QML action.

That matters because this function reads m_pending_wallet_load_action, clears it, and later emits walletCreateSucceeded(), walletLoadSucceeded(), or walletImportSucceeded() without first proving that the loaded wallet is the pending target. So an unrelated wallet notification can consume the active pending operation.

Comparing with Qt Widgets, it avoids this specific issue by keeping global wallet adoption separate from operation completion:

  • WalletController::handleLoadWallet() only calls getOrCreateWallet() to adopt the loaded wallet model.
  • CreateWalletActivity, OpenWalletActivity, and RestoreWalletActivity complete from the WalletLoader::createWallet/loadWallet/restoreWallet result returned by their own worker operation.
  • The activity emits created() / opened() / restored() only if that specific operation set its own m_wallet_model.

So in Widgets, an unrelated wallet loaded notification may adopt another wallet model globally, but it does not complete the active create or open activity. In QML, handleLoadWallet() currently does both adoption and pending operation completion, which makes the global notification able to satisfy the wrong operation.

I wrote two local unit tests to check this:

  • start creating created_wallet, then deliver a load notification for unrelated_wallet;
  • start loading target_wallet, then deliver a load notification for unrelated_wallet.

Both fail on current HEAD. The unrelated notification emits the pending success signal:

FAIL! initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification()
Actual create_spy.count(): 1
Expected: 0

FAIL! initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification()
Actual load_spy.count(): 1
Expected: 0

Here are the tests I wrote

commit 0e7040ce0680ee7f88b4960489723ba4b6814008
Author: jarolrod <[email protected]>
Date:   Fri May 29 16:17:05 2026 -0400

    test

diff --git a/test/test_walletqmlcontroller.cpp b/test/test_walletqmlcontroller.cpp
index 4917ccddc..50938302e 100644
--- a/test/test_walletqmlcontroller.cpp
+++ b/test/test_walletqmlcontroller.cpp
@@ -64,6 +64,10 @@ public:
         create_wallet_fn = [](const std::string&, const SecureString&, uint64_t, std::vector<bilingual_str>&) {
             return util::Error{Untranslated("Unexpected createWallet call")};
         };
+    std::function<util::Result<std::unique_ptr<interfaces::Wallet>>(const std::string&, std::vector<bilingual_str>&)>
+        load_wallet_fn = [](const std::string&, std::vector<bilingual_str>&) {
+            return util::Error{Untranslated("Unexpected loadWallet call")};
+        };
     std::function<util::Result<interfaces::WalletMigrationResult>(const std::string&, const SecureString&)>
         migrate_wallet_fn = [](const std::string&, const SecureString&) {
             return util::Error{Untranslated("Unexpected migrateWallet call")};
@@ -93,10 +97,10 @@ public:
         ++create_wallet_calls;
         return create_wallet_fn(name, passphrase, wallet_creation_flags, warnings);
     }
-    util::Result<std::unique_ptr<interfaces::Wallet>> loadWallet(const std::string&, std::vector<bilingual_str>&) override
+    util::Result<std::unique_ptr<interfaces::Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) override
     {
         ++load_wallet_calls;
-        return util::Error{Untranslated("Unexpected loadWallet call")};
+        return load_wallet_fn(name, warnings);
     }
     std::string getWalletDir() override { return {}; }
     util::Result<std::unique_ptr<interfaces::Wallet>> restoreWallet(const fs::path&, const std::string&, std::vector<bilingual_str>&) override
@@ -294,6 +298,8 @@ private Q_SLOTS:
     void initializedControllerForwardsMigrationPassphrase();
     void initializedControllerForwardsUtf8CreatePassphrase();
     void initializedControllerEmitsWalletCreateSucceeded();
+    void initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification();
+    void initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification();
     void initializedControllerReportsCreateWarnings();
     void initializedControllerIgnoresDuplicateCreateWhileInProgress();
     void initializedControllerRequestsPassphraseBeforeEncryptedMigration();
@@ -672,6 +678,78 @@ void WalletQmlControllerTests::initializedControllerEmitsWalletCreateSucceeded()
     QCOMPARE(controller.walletCreateError(), QString{});
 }
 
+void WalletQmlControllerTests::initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification()
+{
+    using ::testing::StrictMock;
+
+    StrictMock<MockNode> node;
+    FakeWalletLoader loader;
+    ExpectControllerInitialization(node, loader);
+
+    WalletQmlController controller(node);
+    controller.initialize();
+    QVERIFY(loader.captured_load_wallet_fn);
+
+    FakeWallet::State created_state;
+    FakeWallet::State unrelated_state;
+    loader.create_wallet_fn = [&](const std::string& name,
+                                  const SecureString&,
+                                  uint64_t,
+                                  std::vector<bilingual_str>&) {
+        return util::Result<std::unique_ptr<interfaces::Wallet>>{
+            std::make_unique<FakeWallet>(name, &created_state)};
+    };
+
+    QSignalSpy create_spy(&controller, &WalletQmlController::walletCreateSucceeded);
+
+    controller.createSingleSigWallet("created_wallet", "");
+    QVERIFY(controller.walletLoadInProgress());
+
+    loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("unrelated_wallet", &unrelated_state));
+
+    QCOMPARE(create_spy.count(), 0);
+    QVERIFY(controller.walletLoadInProgress());
+
+    loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("created_wallet", &created_state));
+    QTRY_COMPARE_WITH_TIMEOUT(create_spy.count(), 1, 5000);
+    QVERIFY(!controller.walletLoadInProgress());
+}
+
+void WalletQmlControllerTests::initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification()
+{
+    using ::testing::StrictMock;
+
+    StrictMock<MockNode> node;
+    FakeWalletLoader loader;
+    ExpectControllerInitialization(node, loader);
+
+    WalletQmlController controller(node);
+    controller.initialize();
+    QVERIFY(loader.captured_load_wallet_fn);
+
+    FakeWallet::State loaded_state;
+    FakeWallet::State unrelated_state;
+    loader.load_wallet_fn = [&](const std::string& name,
+                                std::vector<bilingual_str>&) {
+        return util::Result<std::unique_ptr<interfaces::Wallet>>{
+            std::make_unique<FakeWallet>(name, &loaded_state)};
+    };
+
+    QSignalSpy load_spy(&controller, &WalletQmlController::walletLoadSucceeded);
+
+    controller.setSelectedWallet("target_wallet", "sqlite");
+    QVERIFY(controller.walletLoadInProgress());
+
+    loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("unrelated_wallet", &unrelated_state));
+
+    QCOMPARE(load_spy.count(), 0);
+    QVERIFY(controller.walletLoadInProgress());
+
+    loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("target_wallet", &loaded_state));
+    QTRY_COMPARE_WITH_TIMEOUT(load_spy.count(), 1, 5000);
+    QVERIFY(!controller.walletLoadInProgress());
+}
+
 void WalletQmlControllerTests::initializedControllerReportsCreateWarnings()
 {
     using ::testing::StrictMock;
This part intrigued me, so I dug into whether the pending wallet operation is actually tied to the wallet that just loaded. I think there is still a very real lifecycle bug here; that might be worthwhile to address in this PR. The QML controller currently tracks “some wallet operation is pending” with `m_wallet_load_requested` and `m_pending_wallet_load_action`, but it does not track the target wallet name/path for that pending operation. `handleLoadWallet()` is registered as the global Core wallet-loaded callback, so it can be called for any wallet load notification, not only the wallet caused by the current QML action. That matters because this function reads `m_pending_wallet_load_action`, clears it, and later emits `walletCreateSucceeded()`, `walletLoadSucceeded()`, or `walletImportSucceeded()` without first proving that the loaded wallet is the pending target. So an unrelated wallet notification can consume the active pending operation. Comparing with Qt Widgets, it avoids this specific issue by keeping global wallet adoption separate from operation completion: - `WalletController::handleLoadWallet()` only calls `getOrCreateWallet()` to adopt the loaded wallet model. - `CreateWalletActivity`, `OpenWalletActivity`, and `RestoreWalletActivity` complete from the `WalletLoader::createWallet/loadWallet/restoreWallet` result returned by their own worker operation. - The activity emits `created()` / `opened()` / `restored()` only if that specific operation set its own `m_wallet_model`. So in Widgets, an unrelated wallet loaded notification may adopt another wallet model globally, but it does not complete the active create or open activity. In QML, `handleLoadWallet()` currently does **both** adoption and pending operation completion, which makes the global notification able to satisfy the wrong operation. I wrote two local unit tests to check this: - start creating `created_wallet`, then deliver a load notification for `unrelated_wallet`; - start loading `target_wallet`, then deliver a load notification for `unrelated_wallet`. Both fail on current HEAD. The unrelated notification emits the pending success signal: ```text FAIL! initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification() Actual create_spy.count(): 1 Expected: 0 FAIL! initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification() Actual load_spy.count(): 1 Expected: 0 ``` Here are the tests I wrote <details> ```diff commit 0e7040ce0680ee7f88b4960489723ba4b6814008 Author: jarolrod <[email protected]> Date: Fri May 29 16:17:05 2026 -0400 test diff --git a/test/test_walletqmlcontroller.cpp b/test/test_walletqmlcontroller.cpp index 4917ccddc..50938302e 100644 --- a/test/test_walletqmlcontroller.cpp +++ b/test/test_walletqmlcontroller.cpp @@ -64,6 +64,10 @@ public: create_wallet_fn = [](const std::string&, const SecureString&, uint64_t, std::vector<bilingual_str>&) { return util::Error{Untranslated("Unexpected createWallet call")}; }; + std::function<util::Result<std::unique_ptr<interfaces::Wallet>>(const std::string&, std::vector<bilingual_str>&)> + load_wallet_fn = [](const std::string&, std::vector<bilingual_str>&) { + return util::Error{Untranslated("Unexpected loadWallet call")}; + }; std::function<util::Result<interfaces::WalletMigrationResult>(const std::string&, const SecureString&)> migrate_wallet_fn = [](const std::string&, const SecureString&) { return util::Error{Untranslated("Unexpected migrateWallet call")}; @@ -93,10 +97,10 @@ public: ++create_wallet_calls; return create_wallet_fn(name, passphrase, wallet_creation_flags, warnings); } - util::Result<std::unique_ptr<interfaces::Wallet>> loadWallet(const std::string&, std::vector<bilingual_str>&) override + util::Result<std::unique_ptr<interfaces::Wallet>> loadWallet(const std::string& name, std::vector<bilingual_str>& warnings) override { ++load_wallet_calls; - return util::Error{Untranslated("Unexpected loadWallet call")}; + return load_wallet_fn(name, warnings); } std::string getWalletDir() override { return {}; } util::Result<std::unique_ptr<interfaces::Wallet>> restoreWallet(const fs::path&, const std::string&, std::vector<bilingual_str>&) override @@ -294,6 +298,8 @@ private Q_SLOTS: void initializedControllerForwardsMigrationPassphrase(); void initializedControllerForwardsUtf8CreatePassphrase(); void initializedControllerEmitsWalletCreateSucceeded(); + void initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification(); + void initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification(); void initializedControllerReportsCreateWarnings(); void initializedControllerIgnoresDuplicateCreateWhileInProgress(); void initializedControllerRequestsPassphraseBeforeEncryptedMigration(); @@ -672,6 +678,78 @@ void WalletQmlControllerTests::initializedControllerEmitsWalletCreateSucceeded() QCOMPARE(controller.walletCreateError(), QString{}); } +void WalletQmlControllerTests::initializedControllerDoesNotCompleteCreateForUnrelatedLoadNotification() +{ + using ::testing::StrictMock; + + StrictMock<MockNode> node; + FakeWalletLoader loader; + ExpectControllerInitialization(node, loader); + + WalletQmlController controller(node); + controller.initialize(); + QVERIFY(loader.captured_load_wallet_fn); + + FakeWallet::State created_state; + FakeWallet::State unrelated_state; + loader.create_wallet_fn = [&](const std::string& name, + const SecureString&, + uint64_t, + std::vector<bilingual_str>&) { + return util::Result<std::unique_ptr<interfaces::Wallet>>{ + std::make_unique<FakeWallet>(name, &created_state)}; + }; + + QSignalSpy create_spy(&controller, &WalletQmlController::walletCreateSucceeded); + + controller.createSingleSigWallet("created_wallet", ""); + QVERIFY(controller.walletLoadInProgress()); + + loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("unrelated_wallet", &unrelated_state)); + + QCOMPARE(create_spy.count(), 0); + QVERIFY(controller.walletLoadInProgress()); + + loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("created_wallet", &created_state)); + QTRY_COMPARE_WITH_TIMEOUT(create_spy.count(), 1, 5000); + QVERIFY(!controller.walletLoadInProgress()); +} + +void WalletQmlControllerTests::initializedControllerDoesNotCompleteLoadForUnrelatedLoadNotification() +{ + using ::testing::StrictMock; + + StrictMock<MockNode> node; + FakeWalletLoader loader; + ExpectControllerInitialization(node, loader); + + WalletQmlController controller(node); + controller.initialize(); + QVERIFY(loader.captured_load_wallet_fn); + + FakeWallet::State loaded_state; + FakeWallet::State unrelated_state; + loader.load_wallet_fn = [&](const std::string& name, + std::vector<bilingual_str>&) { + return util::Result<std::unique_ptr<interfaces::Wallet>>{ + std::make_unique<FakeWallet>(name, &loaded_state)}; + }; + + QSignalSpy load_spy(&controller, &WalletQmlController::walletLoadSucceeded); + + controller.setSelectedWallet("target_wallet", "sqlite"); + QVERIFY(controller.walletLoadInProgress()); + + loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("unrelated_wallet", &unrelated_state)); + + QCOMPARE(load_spy.count(), 0); + QVERIFY(controller.walletLoadInProgress()); + + loader.captured_load_wallet_fn(std::make_unique<FakeWallet>("target_wallet", &loaded_state)); + QTRY_COMPARE_WITH_TIMEOUT(load_spy.count(), 1, 5000); + QVERIFY(!controller.walletLoadInProgress()); +} + void WalletQmlControllerTests::initializedControllerReportsCreateWarnings() { using ::testing::StrictMock; ``` </details>
jarolrod (Migrated from github.com) reviewed 2026-05-29 20:38:51 +00:00
jarolrod (Migrated from github.com) commented 2026-05-29 20:38:51 +00:00

Right now, it seems to me, this path can run before initialize(), and it can also run while another wallet load or create is already in progress. In the second case, clearWalletLoadStatus() clears the existing in-progress state, then the function continues into WalletLoader::createWallet().

Maybe we add the same basic guards used by createSingleSigWallet() here: return if m_wallet_load_in_progress is true, and return with the “wallets still loading” error if !m_initialized?

Overall, I think we need more unit tests around all these load and create functions

Right now, it seems to me, this path can run before `initialize()`, and it can also run while another wallet load or create is already in progress. In the second case, `clearWalletLoadStatus()` clears the existing in-progress state, then the function continues into `WalletLoader::createWallet()`. Maybe we add the same basic guards used by `createSingleSigWallet()` here: return if `m_wallet_load_in_progress` is true, and return with the “wallets still loading” error if `!m_initialized`? Overall, I think we need more unit tests around all these load and create functions
johnny9 (Migrated from github.com) reviewed 2026-05-29 21:36:14 +00:00
johnny9 (Migrated from github.com) commented 2026-05-29 21:36:14 +00:00

we've had other instances of calls that need to be protected with an initialization check

we've had other instances of calls that need to be protected with an initialization check
pseudoramdom (Migrated from github.com) reviewed 2026-05-29 22:09:11 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-29 22:09:11 +00:00

Good catch. I’m going to rework this so watch-only creation follows the same threading model as the other wallet operations. Validation will stay on the QML thread, but createWallet() and descriptor import can run on m_worker

Probably create a helper method

void createWalletAsync(
         QString wallet_name,
         SecureString passphrase,
         uint64_t flags,
         WalletLoadAction action,
         std::function<util::Result<void>(interfaces::Wallet&)> setup = {});
Good catch. I’m going to rework this so watch-only creation follows the same threading model as the other wallet operations. Validation will stay on the QML thread, but `createWallet()` and descriptor import can run on `m_worker` Probably create a helper method ```cpp void createWalletAsync( QString wallet_name, SecureString passphrase, uint64_t flags, WalletLoadAction action, std::function<util::Result<void>(interfaces::Wallet&)> setup = {}); ```
johnny9 (Migrated from github.com) reviewed 2026-05-30 03:47:28 +00:00
johnny9 (Migrated from github.com) commented 2026-05-30 03:47:28 +00:00

I think that means the fix should be:

  • handleLoadWallet() should only addOrSelectWalletModel(...).
  • createSingleSigWallet(), createWatchOnlyWallet(), startWalletLoad(), and startWalletImport() should emit success from their own worker result after addOrSelectWalletModel(...) returns a model.
  • Watch-only needs one extra guard versus Qt widgets: because descriptor import happens after createWallet(), the NotifyWalletLoaded callback must defer that wallet before publishing it, otherwise QML can briefly expose a half-created wallet.
I think that means the fix should be: - handleLoadWallet() should only addOrSelectWalletModel(...). - createSingleSigWallet(), createWatchOnlyWallet(), startWalletLoad(), and startWalletImport() should emit success from their own worker result after addOrSelectWalletModel(...) returns a model. - Watch-only needs one extra guard versus Qt widgets: because descriptor import happens after createWallet(), the NotifyWalletLoaded callback must defer that wallet before publishing it, otherwise QML can briefly expose a half-created wallet.
pseudoramdom (Migrated from github.com) reviewed 2026-05-30 17:24:11 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-30 17:24:11 +00:00

thanks both for the suggestion! I reworked this along the same lines as Qt Widgets. The global handleLoadWallet() path now only adopts/selects the wallet, and each create/load/import operation emits success from its own worker.
I also removed the pending m_wallet_load_requested / m_pending_wallet_load_action states.

thanks both for the suggestion! I reworked this along the same lines as Qt Widgets. The global `handleLoadWallet()` path now only adopts/selects the wallet, and each create/load/import operation emits success from its own worker. I also removed the pending `m_wallet_load_requested` / `m_pending_wallet_load_action` states.
pseudoramdom commented 2026-05-31 16:34:54 +00:00 (Migrated from github.com)

317e42f
Rebased on top of qt6 branch and added a commit to repurpose AlertPopup

[317e42f](https://github.com/bitcoin-core/gui-qml/commit/317e42fc071b0cfe077e32c9830206227e7adcf0) Rebased on top of `qt6` branch and added a commit to repurpose AlertPopup
jarolrod (Migrated from github.com) reviewed 2026-06-01 18:13:11 +00:00
jarolrod (Migrated from github.com) commented 2026-06-01 18:13:11 +00:00

Are we intentionally wanting to leave a newly created and blank wallet on disk here? even though the real wallet creation work failed?

I can see why remove() would avoid deleting wallets in general. But in this flow the UI reports watch-only creation as failed, so then retrying with the same name can be blocked because the wallet directory exists.

Are we intentionally wanting to leave a newly created and blank wallet on disk here? even though the real wallet creation work failed? I can see why `remove()` would avoid deleting wallets in general. But in this flow the UI reports watch-only creation as failed, so then retrying with the same name can be blocked because the wallet directory exists.
johnny9 (Migrated from github.com) reviewed 2026-06-01 18:39:24 +00:00
johnny9 (Migrated from github.com) commented 2026-06-01 18:39:24 +00:00

I think we might need to define a flow to add keys to a wallet in the wallet settings. If we have this, we can re-order the watch-only onboarding to create the wallet first and then treat the xpub as adding keys to it. This better matches the actual interface and lets us have the create wallet stage be separate from the xpub failure so we don't have a left over wallet

I think we might need to define a flow to add keys to a wallet in the wallet settings. If we have this, we can re-order the watch-only onboarding to create the wallet first and then treat the xpub as adding keys to it. This better matches the actual interface and lets us have the create wallet stage be separate from the xpub failure so we don't have a left over wallet
johnny9 (Migrated from github.com) commented 2026-06-01 18:42:03 +00:00

My suggestion is to leave these as the follow follow-up issues.

  1. Watch-only wallet creation leaves a blank wallet on disc if adding keys fails
  2. Create a path in wallet settings to add xpubs to a watch only wallet

Build 2 and then use that to close 1 by making it ok that the xpub path isn't filled in during onboard

My suggestion is to leave these as the follow follow-up issues. 1. Watch-only wallet creation leaves a blank wallet on disc if adding keys fails 2. Create a path in wallet settings to add xpubs to a watch only wallet Build 2 and then use that to close 1 by making it ok that the xpub path isn't filled in during onboard
jarolrod commented 2026-06-01 20:11:10 +00:00 (Migrated from github.com)

ACK a8527f13c6

I agree this is ready to merge, we have documented several follow-ups to be done.

ACK a8527f13c67cf9fbee0e6b6da2b8af1bc32068bd I agree this is ready to merge, we have documented several follow-ups to be done.
johnny9 (Migrated from github.com) reviewed 2026-06-01 20:23:07 +00:00
johnny9 (Migrated from github.com) commented 2026-06-01 20:23:07 +00:00
#737
johnny9 (Migrated from github.com) approved these changes 2026-06-01 21:02:45 +00:00
johnny9 (Migrated from github.com) left a comment
ACK a8527f13c67cf9fbee0e6b6da2b8af1bc32068bd
Sign in to join this conversation.
No description provided.