From 37c3d573e0c1881fe453ac9a4dbca808a4546176 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sun, 9 Aug 2020 14:46:52 +0200 Subject: [PATCH] wallet load and dialog field improvements --- .../java/com/sparrowwallet/sparrow/AppController.java | 4 ++-- .../sparrow/control/KeystorePassphraseDialog.java | 9 +++++++-- .../sparrow/control/TransactionIdDialog.java | 2 +- .../sparrow/control/WalletNameDialog.java | 2 +- .../sparrow/control/WalletPasswordDialog.java | 10 +++++++--- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 66e86172..bd2f9ec1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -617,7 +617,7 @@ public class AppController implements Initializable { Tab tab = addWalletTab(storage, wallet); tabs.getSelectionModel().select(tab); } else if(FileType.BINARY.equals(fileType)) { - WalletPasswordDialog dlg = new WalletPasswordDialog(WalletPasswordDialog.PasswordRequirement.LOAD); + WalletPasswordDialog dlg = new WalletPasswordDialog(file.getName(), WalletPasswordDialog.PasswordRequirement.LOAD); Optional optionalPassword = dlg.showAndWait(); if(optionalPassword.isEmpty()) { return; @@ -666,7 +666,7 @@ public class AppController implements Initializable { for(Keystore copyKeystore : copy.getKeystores()) { if(copyKeystore.hasSeed()) { if(copyKeystore.getSeed().needsPassphrase()) { - KeystorePassphraseDialog passphraseDialog = new KeystorePassphraseDialog(copyKeystore); + KeystorePassphraseDialog passphraseDialog = new KeystorePassphraseDialog(wallet.getName(), copyKeystore); Optional optionalPassphrase = passphraseDialog.showAndWait(); if(optionalPassphrase.isPresent()) { copyKeystore.getSeed().setPassphrase(optionalPassphrase.get()); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java index 43ba9558..9a44e6b6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java @@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control; import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; +import javafx.application.Platform; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.scene.control.DialogPane; @@ -15,10 +16,14 @@ public class KeystorePassphraseDialog extends Dialog { private final CustomPasswordField passphrase; public KeystorePassphraseDialog(Keystore keystore) { + this(null, keystore); + } + + public KeystorePassphraseDialog(String walletName, Keystore keystore) { this.passphrase = (CustomPasswordField) TextFields.createClearablePasswordField(); final DialogPane dialogPane = getDialogPane(); - setTitle("Keystore Passphrase"); + setTitle("Keystore Passphrase" + (walletName != null ? " - " + walletName : "")); dialogPane.setHeaderText("Please enter the passphrase for keystore: \n" + keystore.getLabel()); dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm()); dialogPane.getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK); @@ -34,7 +39,7 @@ public class KeystorePassphraseDialog extends Dialog { content.getChildren().add(passphrase); dialogPane.setContent(content); - passphrase.requestFocus(); + Platform.runLater(passphrase::requestFocus); setResultConverter(dialogButton -> dialogButton == ButtonType.OK ? passphrase.getText() : null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java index 587cc4b7..eb3cb051 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java @@ -60,7 +60,7 @@ public class TransactionIdDialog extends Dialog { okButton.disableProperty().bind(isInvalid); txid.setPromptText("f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"); - txid.requestFocus(); + Platform.runLater(txid::requestFocus); setResultConverter(dialogButton -> dialogButton == okButtonType ? Sha256Hash.wrap(txid.getText()) : null); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java index f55199ec..e5186bcf 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java @@ -56,7 +56,7 @@ public class WalletNameDialog extends Dialog { okButton.disableProperty().bind(isInvalid); name.setPromptText("Wallet Name"); - name.requestFocus(); + Platform.runLater(name::requestFocus); setResultConverter(dialogButton -> dialogButton == okButtonType ? name.getText() : null); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java index 3d806611..c81ab31f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java @@ -23,14 +23,18 @@ public class WalletPasswordDialog extends Dialog { private final CheckBox backupExisting; public WalletPasswordDialog(PasswordRequirement requirement) { + this(null, requirement); + } + + public WalletPasswordDialog(String walletName, PasswordRequirement requirement) { this.requirement = requirement; this.password = (CustomPasswordField)TextFields.createClearablePasswordField(); this.passwordConfirm = (CustomPasswordField)TextFields.createClearablePasswordField(); this.backupExisting = new CheckBox("Backup existing wallet first"); final DialogPane dialogPane = getDialogPane(); - setTitle("Wallet Password"); - dialogPane.setHeaderText(requirement.description); + setTitle("Wallet Password" + (walletName != null ? " - " + walletName : "")); + dialogPane.setHeaderText(walletName != null ? requirement.description.substring(0, requirement.description.length() - 1) + " for " + walletName + ":" : requirement.description); dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm()); dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); dialogPane.setPrefWidth(380); @@ -85,7 +89,7 @@ public class WalletPasswordDialog extends Dialog { } password.setPromptText("Password"); - password.requestFocus(); + Platform.runLater(password::requestFocus); passwordConfirm.setPromptText("Password Confirmation"); setResultConverter(dialogButton -> dialogButton == okButtonType ? new SecureString(password.getText()) : null);