From 3b9c87abc7fde932d68011338555a7bd4dc168af Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 1 Dec 2021 14:43:48 +0200 Subject: [PATCH] improve incorrect password handling on final mix confirm --- .../sparrow/soroban/InitiatorDialog.java | 18 +++++++++++++++++- .../sparrow/soroban/initiator.fxml | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorDialog.java b/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorDialog.java index 77d1e18a..75c5e609 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorDialog.java @@ -1,6 +1,7 @@ package com.sparrowwallet.sparrow.soroban; import com.sparrowwallet.drongo.SecureString; +import com.sparrowwallet.drongo.crypto.InvalidPasswordException; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.WalletTransaction; @@ -10,14 +11,21 @@ import com.sparrowwallet.sparrow.control.WalletPasswordDialog; import com.sparrowwallet.sparrow.event.StorageEvent; import com.sparrowwallet.sparrow.event.TimedEvent; import com.sparrowwallet.sparrow.io.Storage; +import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; import javafx.scene.control.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Optional; +import static com.sparrowwallet.sparrow.AppServices.showErrorDialog; + public class InitiatorDialog extends Dialog { + private static final Logger log = LoggerFactory.getLogger(InitiatorDialog.class); + private final boolean confirmationRequired; public InitiatorDialog(String walletId, Wallet wallet, WalletTransaction walletTransaction) { @@ -34,7 +42,7 @@ public class InitiatorDialog extends Dialog { initiatorController.initializeView(walletId, wallet, walletTransaction); dialogPane.setPrefWidth(730); - dialogPane.setPrefHeight(520); + dialogPane.setPrefHeight(530); AppServices.moveToActiveWindowScreen(this); dialogPane.getStylesheets().add(AppServices.class.getResource("app.css").toExternalForm()); @@ -114,6 +122,14 @@ public class InitiatorDialog extends Dialog { }); keyDerivationService.setOnFailed(workerStateEvent -> { EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Failed")); + if(keyDerivationService.getException() instanceof InvalidPasswordException) { + Optional optResponse = showErrorDialog("Invalid Password", "The wallet password was invalid. Try again?", ButtonType.CANCEL, ButtonType.OK); + if(optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) { + Platform.runLater(() -> acceptAndBroadcast(initiatorController, walletId, wallet)); + } + } else { + log.error("Error deriving wallet key", keyDerivationService.getException()); + } }); EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.START, "Decrypting wallet...")); keyDerivationService.start(); diff --git a/src/main/resources/com/sparrowwallet/sparrow/soroban/initiator.fxml b/src/main/resources/com/sparrowwallet/sparrow/soroban/initiator.fxml index ff1b2076..2a5b9acd 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/soroban/initiator.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/soroban/initiator.fxml @@ -37,7 +37,7 @@