wallet load and dialog field improvements

This commit is contained in:
Craig Raw 2020-08-09 14:46:52 +02:00
parent b2f48a1b05
commit 37c3d573e0
5 changed files with 18 additions and 9 deletions

View file

@ -617,7 +617,7 @@ public class AppController implements Initializable {
Tab tab = addWalletTab(storage, wallet); Tab tab = addWalletTab(storage, wallet);
tabs.getSelectionModel().select(tab); tabs.getSelectionModel().select(tab);
} else if(FileType.BINARY.equals(fileType)) { } else if(FileType.BINARY.equals(fileType)) {
WalletPasswordDialog dlg = new WalletPasswordDialog(WalletPasswordDialog.PasswordRequirement.LOAD); WalletPasswordDialog dlg = new WalletPasswordDialog(file.getName(), WalletPasswordDialog.PasswordRequirement.LOAD);
Optional<SecureString> optionalPassword = dlg.showAndWait(); Optional<SecureString> optionalPassword = dlg.showAndWait();
if(optionalPassword.isEmpty()) { if(optionalPassword.isEmpty()) {
return; return;
@ -666,7 +666,7 @@ public class AppController implements Initializable {
for(Keystore copyKeystore : copy.getKeystores()) { for(Keystore copyKeystore : copy.getKeystores()) {
if(copyKeystore.hasSeed()) { if(copyKeystore.hasSeed()) {
if(copyKeystore.getSeed().needsPassphrase()) { if(copyKeystore.getSeed().needsPassphrase()) {
KeystorePassphraseDialog passphraseDialog = new KeystorePassphraseDialog(copyKeystore); KeystorePassphraseDialog passphraseDialog = new KeystorePassphraseDialog(wallet.getName(), copyKeystore);
Optional<String> optionalPassphrase = passphraseDialog.showAndWait(); Optional<String> optionalPassphrase = passphraseDialog.showAndWait();
if(optionalPassphrase.isPresent()) { if(optionalPassphrase.isPresent()) {
copyKeystore.getSeed().setPassphrase(optionalPassphrase.get()); copyKeystore.getSeed().setPassphrase(optionalPassphrase.get());

View file

@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import javafx.application.Platform;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog; import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane; import javafx.scene.control.DialogPane;
@ -15,10 +16,14 @@ public class KeystorePassphraseDialog extends Dialog<String> {
private final CustomPasswordField passphrase; private final CustomPasswordField passphrase;
public KeystorePassphraseDialog(Keystore keystore) { public KeystorePassphraseDialog(Keystore keystore) {
this(null, keystore);
}
public KeystorePassphraseDialog(String walletName, Keystore keystore) {
this.passphrase = (CustomPasswordField) TextFields.createClearablePasswordField(); this.passphrase = (CustomPasswordField) TextFields.createClearablePasswordField();
final DialogPane dialogPane = getDialogPane(); 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.setHeaderText("Please enter the passphrase for keystore: \n" + keystore.getLabel());
dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm()); dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm());
dialogPane.getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK); dialogPane.getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
@ -34,7 +39,7 @@ public class KeystorePassphraseDialog extends Dialog<String> {
content.getChildren().add(passphrase); content.getChildren().add(passphrase);
dialogPane.setContent(content); dialogPane.setContent(content);
passphrase.requestFocus(); Platform.runLater(passphrase::requestFocus);
setResultConverter(dialogButton -> dialogButton == ButtonType.OK ? passphrase.getText() : null); setResultConverter(dialogButton -> dialogButton == ButtonType.OK ? passphrase.getText() : null);
} }

View file

@ -60,7 +60,7 @@ public class TransactionIdDialog extends Dialog<Sha256Hash> {
okButton.disableProperty().bind(isInvalid); okButton.disableProperty().bind(isInvalid);
txid.setPromptText("f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"); txid.setPromptText("f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16");
txid.requestFocus(); Platform.runLater(txid::requestFocus);
setResultConverter(dialogButton -> dialogButton == okButtonType ? Sha256Hash.wrap(txid.getText()) : null); setResultConverter(dialogButton -> dialogButton == okButtonType ? Sha256Hash.wrap(txid.getText()) : null);
} }
} }

View file

@ -56,7 +56,7 @@ public class WalletNameDialog extends Dialog<String> {
okButton.disableProperty().bind(isInvalid); okButton.disableProperty().bind(isInvalid);
name.setPromptText("Wallet Name"); name.setPromptText("Wallet Name");
name.requestFocus(); Platform.runLater(name::requestFocus);
setResultConverter(dialogButton -> dialogButton == okButtonType ? name.getText() : null); setResultConverter(dialogButton -> dialogButton == okButtonType ? name.getText() : null);
} }
} }

View file

@ -23,14 +23,18 @@ public class WalletPasswordDialog extends Dialog<SecureString> {
private final CheckBox backupExisting; private final CheckBox backupExisting;
public WalletPasswordDialog(PasswordRequirement requirement) { public WalletPasswordDialog(PasswordRequirement requirement) {
this(null, requirement);
}
public WalletPasswordDialog(String walletName, PasswordRequirement requirement) {
this.requirement = requirement; this.requirement = requirement;
this.password = (CustomPasswordField)TextFields.createClearablePasswordField(); this.password = (CustomPasswordField)TextFields.createClearablePasswordField();
this.passwordConfirm = (CustomPasswordField)TextFields.createClearablePasswordField(); this.passwordConfirm = (CustomPasswordField)TextFields.createClearablePasswordField();
this.backupExisting = new CheckBox("Backup existing wallet first"); this.backupExisting = new CheckBox("Backup existing wallet first");
final DialogPane dialogPane = getDialogPane(); final DialogPane dialogPane = getDialogPane();
setTitle("Wallet Password"); setTitle("Wallet Password" + (walletName != null ? " - " + walletName : ""));
dialogPane.setHeaderText(requirement.description); 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.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm());
dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); dialogPane.getButtonTypes().addAll(ButtonType.CANCEL);
dialogPane.setPrefWidth(380); dialogPane.setPrefWidth(380);
@ -85,7 +89,7 @@ public class WalletPasswordDialog extends Dialog<SecureString> {
} }
password.setPromptText("Password"); password.setPromptText("Password");
password.requestFocus(); Platform.runLater(password::requestFocus);
passwordConfirm.setPromptText("Password Confirmation"); passwordConfirm.setPromptText("Password Confirmation");
setResultConverter(dialogButton -> dialogButton == okButtonType ? new SecureString(password.getText()) : null); setResultConverter(dialogButton -> dialogButton == okButtonType ? new SecureString(password.getText()) : null);