From b0877d94bf855e02d0be26827ac008fedd05d094 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 16 Aug 2021 13:33:05 +0200 Subject: [PATCH] make all wallet addresses non-editable once child wallets are added --- .../sparrow/control/TextAreaDialog.java | 16 ++++++--- .../sparrow/wallet/KeystoreController.java | 17 ++++++++++ .../sparrow/wallet/SettingsController.java | 34 +++++++++++++++++++ .../sparrow/wallet/settings.fxml | 3 +- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java index aeb5e8de..3d1fa20f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java @@ -27,7 +27,11 @@ public class TextAreaDialog extends Dialog { this(""); } - public TextAreaDialog(@NamedArg("defaultValue") String defaultValue) { + public TextAreaDialog(String defaultValue) { + this(defaultValue, true); + } + + public TextAreaDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable) { final DialogPane dialogPane = new TextAreaDialogPane(); setDialogPane(dialogPane); @@ -39,6 +43,7 @@ public class TextAreaDialog extends Dialog { this.textArea.setMaxWidth(Double.MAX_VALUE); this.textArea.setWrapText(true); this.textArea.getStyleClass().add("fixed-width"); + this.textArea.setEditable(editable); hbox.getChildren().add(textArea); HBox.setHgrow(this.textArea, Priority.ALWAYS); @@ -49,10 +54,13 @@ public class TextAreaDialog extends Dialog { AppServices.setStageIcon(dialogPane.getScene().getWindow()); dialogPane.getStyleClass().add("text-input-dialog"); - dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); + dialogPane.getButtonTypes().add(ButtonType.OK); + if(editable) { + dialogPane.getButtonTypes().add(ButtonType.CANCEL); - final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.LEFT); - dialogPane.getButtonTypes().add(scanButtonType); + final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.LEFT); + dialogPane.getButtonTypes().add(scanButtonType); + } Platform.runLater(textArea::requestFocus); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index 9c0ec651..92ec4c97 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -8,6 +8,7 @@ import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.control.*; +import com.sparrowwallet.sparrow.event.ChildWalletAddedEvent; import com.sparrowwallet.sparrow.event.StorageEvent; import com.sparrowwallet.sparrow.event.TimedEvent; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; @@ -161,6 +162,8 @@ public class KeystoreController extends WalletFormController implements Initiali } scanXpubQR.setVisible(!valid); }); + + setInputFieldsDisabled(!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty()); } private void setXpubContext(ExtendedKey extendedKey) { @@ -408,6 +411,20 @@ public class KeystoreController extends WalletFormController implements Initiali } } + private void setInputFieldsDisabled(boolean disabled) { + setEditable(fingerprint, !disabled); + setEditable(derivation, !disabled); + setEditable(xpub, !disabled); + importButton.setDisable(disabled); + } + + @Subscribe + public void childWalletAdded(ChildWalletAddedEvent event) { + if(event.getMasterWalletId().equals(walletForm.getWalletId())) { + setInputFieldsDisabled(true); + } + } + @Subscribe public void update(SettingsChangedEvent event) { if(walletForm.getWallet().equals(event.getWallet()) && event.getType().equals(SettingsChangedEvent.Type.SCRIPT_TYPE)) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 57ec0dca..8c008c0f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -53,6 +53,12 @@ public class SettingsController extends WalletFormController implements Initiali @FXML private Button showDescriptorQR; + @FXML + private Button editDescriptor; + + @FXML + private Button showDescriptor; + @FXML private ComboBox scriptType; @@ -190,6 +196,9 @@ public class SettingsController extends WalletFormController implements Initiali showDescriptorQR.managedProperty().bind(showDescriptorQR.visibleProperty()); showDescriptorQR.prefHeightProperty().bind(descriptor.prefHeightProperty()); showDescriptorQR.visibleProperty().bind(scanDescriptorQR.visibleProperty().not()); + editDescriptor.managedProperty().bind(editDescriptor.visibleProperty()); + showDescriptor.managedProperty().bind(showDescriptor.visibleProperty()); + showDescriptor.visibleProperty().bind(editDescriptor.visibleProperty().not()); revert.setOnAction(event -> { keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs()); @@ -207,6 +216,7 @@ public class SettingsController extends WalletFormController implements Initiali }); setFieldsFromWallet(walletForm.getWallet()); + setInputFieldsDisabled(!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty()); } private void clearKeystoreTabs() { @@ -389,6 +399,16 @@ public class SettingsController extends WalletFormController implements Initiali } } + public void showDescriptor(ActionEvent event) { + OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet()); + String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid()); + + TextAreaDialog dialog = new TextAreaDialog(outputDescriptorString, false); + dialog.setTitle("Show wallet output descriptor"); + dialog.getDialogPane().setHeaderText("The wallet configuration is specified in the output descriptor.\nThis wallet is no longer editable - create a new wallet to change the descriptor."); + dialog.showAndWait(); + } + public void showAdvanced(ActionEvent event) { AdvancedDialog advancedDialog = new AdvancedDialog(walletForm); Optional optApply = advancedDialog.showAndWait(); @@ -422,6 +442,13 @@ public class SettingsController extends WalletFormController implements Initiali } } + private void setInputFieldsDisabled(boolean disabled) { + policyType.setDisable(disabled); + scriptType.setDisable(disabled); + multisigControl.setDisable(disabled); + editDescriptor.setVisible(!disabled); + } + @Override protected String describeKeystore(Keystore keystore) { if(!keystore.isValid()) { @@ -484,6 +511,13 @@ public class SettingsController extends WalletFormController implements Initiali } } + @Subscribe + public void childWalletAdded(ChildWalletAddedEvent event) { + if(event.getMasterWalletId().equals(walletForm.getWalletId())) { + setInputFieldsDisabled(true); + } + } + private void saveWallet(boolean changePassword, boolean suggestChangePassword) { ECKey existingPubKey = walletForm.getStorage().getEncryptionPubKey(); diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml index d8d2e293..5a8c3fe9 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml @@ -99,7 +99,8 @@ -