From 7d7c5e5064a10792894c0bc0c814cfc94564057e Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 4 Sep 2020 13:00:40 +0200 Subject: [PATCH] Support replacing existing keystore with watch only keystore --- .../keystoreimport/KeystoreImportDialog.java | 20 +++++++++++++------ .../sparrow/wallet/KeystoreController.java | 9 +++++++-- .../sparrow/wallet/keystore.fxml | 5 +++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java index 63af695a..bffda415 100644 --- a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java @@ -1,17 +1,16 @@ package com.sparrowwallet.sparrow.keystoreimport; import com.google.common.eventbus.Subscribe; +import com.sparrowwallet.drongo.KeyDerivation; import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.KeystoreSource; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletModel; import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.event.KeystoreImportEvent; import javafx.fxml.FXMLLoader; -import javafx.scene.control.ButtonBar; -import javafx.scene.control.ButtonType; -import javafx.scene.control.Dialog; -import javafx.scene.control.DialogPane; +import javafx.scene.control.*; import org.controlsfx.tools.Borders; import java.io.IOException; @@ -41,12 +40,13 @@ public class KeystoreImportDialog extends Dialog { keystoreImportController.initializeView(wallet); keystoreImportController.selectSource(initialSource); + final ButtonType watchOnlyButtonType = new javafx.scene.control.ButtonType("xPub / Watch Only Wallet", ButtonBar.ButtonData.LEFT); final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); - dialogPane.getButtonTypes().addAll(cancelButtonType); + dialogPane.getButtonTypes().addAll(watchOnlyButtonType, cancelButtonType); dialogPane.setPrefWidth(650); dialogPane.setPrefHeight(620); - setResultConverter(dialogButton -> dialogButton != cancelButtonType ? keystore : null); + setResultConverter(dialogButton -> dialogButton != cancelButtonType ? getWatchOnlyKeystore() : null); } catch(IOException e) { throw new RuntimeException(e); } @@ -56,6 +56,14 @@ public class KeystoreImportDialog extends Dialog { return List.of(KeystoreSource.HW_USB, KeystoreSource.HW_AIRGAPPED, KeystoreSource.SW_SEED); } + private Keystore getWatchOnlyKeystore() { + this.keystore = new Keystore(); + keystore.setSource(KeystoreSource.SW_WATCH); + keystore.setWalletModel(WalletModel.SPARROW); + keystore.setKeyDerivation(new KeyDerivation("","")); + return keystore; + } + @Subscribe public void keystoreImported(KeystoreImportEvent event) { this.keystore = event.getKeystore(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index 29b049ed..3b4ca43c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -243,7 +243,7 @@ public class KeystoreController extends WalletFormController implements Initiali private void launchImportDialog(KeystoreSource initialSource) { KeystoreImportDialog dlg = new KeystoreImportDialog(getWalletForm().getWallet(), initialSource); Optional result = dlg.showAndWait(); - if (result.isPresent()) { + if(result.isPresent()) { selectSourcePane.setVisible(false); Keystore importedKeystore = result.get(); @@ -259,7 +259,12 @@ public class KeystoreController extends WalletFormController implements Initiali label.setText(keystore.getLabel()); fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint()); derivation.setText(keystore.getKeyDerivation().getDerivationPath()); - xpub.setText(keystore.getExtendedPublicKey().toString()); + + if(keystore.getExtendedPublicKey() != null) { + xpub.setText(keystore.getExtendedPublicKey().toString()); + } else { + xpub.setText(""); + } } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml index bbf11500..16702565 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/keystore.fxml @@ -13,6 +13,7 @@ + @@ -40,7 +41,7 @@ - + @@ -80,7 +81,7 @@ - +