From dcb261a6317256e22d4e32fc7082dfbb3267dc59 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 27 Jul 2022 12:27:01 +0200 Subject: [PATCH] fix issue adding accounts to multisig wallets with mixed watch-only and seed keystores --- .../sparrow/wallet/SettingsController.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 3e45efd4..7a962a7e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -471,7 +471,7 @@ public class SettingsController extends WalletFormController implements Initiali } private void addAccounts(Wallet masterWallet, List standardAccounts, boolean discoverAccounts) { - if(masterWallet.getKeystores().stream().allMatch(ks -> ks.getSource() == KeystoreSource.SW_SEED)) { + if(masterWallet.getKeystores().stream().anyMatch(ks -> ks.getSource() == KeystoreSource.SW_SEED)) { if(masterWallet.isEncrypted()) { String walletId = walletForm.getWalletId(); WalletPasswordDialog dlg = new WalletPasswordDialog(masterWallet.getName(), WalletPasswordDialog.PasswordRequirement.LOAD); @@ -485,7 +485,12 @@ public class SettingsController extends WalletFormController implements Initiali encryptionFullKey.clear(); masterWallet.decrypt(key); - if(discoverAccounts) { + if(masterWallet.getKeystores().stream().anyMatch(ks -> ks.getSource() != KeystoreSource.SW_SEED)) { + for(StandardAccount standardAccount : standardAccounts) { + Wallet childWallet = masterWallet.addChildWallet(standardAccount); + EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); + } + } else if(discoverAccounts) { ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts); accountDiscoveryService.setOnSucceeded(event -> { addAndEncryptAccounts(masterWallet, accountDiscoveryService.getValue(), key); @@ -518,7 +523,12 @@ public class SettingsController extends WalletFormController implements Initiali keyDerivationService.start(); } } else { - if(discoverAccounts) { + if(masterWallet.getKeystores().stream().anyMatch(ks -> ks.getSource() != KeystoreSource.SW_SEED)) { + for(StandardAccount standardAccount : standardAccounts) { + Wallet childWallet = masterWallet.addChildWallet(standardAccount); + EventManager.get().post(new ChildWalletsAddedEvent(getWalletForm().getStorage(), masterWallet, childWallet)); + } + } else if(discoverAccounts) { ElectrumServer.AccountDiscoveryService accountDiscoveryService = new ElectrumServer.AccountDiscoveryService(masterWallet, standardAccounts); accountDiscoveryService.setOnSucceeded(event -> { addAndSaveAccounts(masterWallet, accountDiscoveryService.getValue());