Search in sources :

Example 1 with WalletPasswordDialog

use of com.sparrowwallet.sparrow.control.WalletPasswordDialog in project sparrow by sparrowwallet.

the class InitiatorDialog method acceptAndBroadcast.

private void acceptAndBroadcast(InitiatorController initiatorController, String walletId, Wallet wallet) {
    if (confirmationRequired && wallet.isEncrypted()) {
        WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getMasterName(), WalletPasswordDialog.PasswordRequirement.LOAD);
        Optional<SecureString> password = dlg.showAndWait();
        if (password.isPresent()) {
            Storage storage = AppServices.get().getOpenWallets().get(wallet);
            Storage.KeyDerivationService keyDerivationService = new Storage.KeyDerivationService(storage, password.get(), true);
            keyDerivationService.setOnSucceeded(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Done"));
                initiatorController.accept();
                password.get().clear();
            });
            keyDerivationService.setOnFailed(workerStateEvent -> {
                EventManager.get().post(new StorageEvent(walletId, TimedEvent.Action.END, "Failed"));
                if (keyDerivationService.getException() instanceof InvalidPasswordException) {
                    Optional<ButtonType> 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();
        }
    } else {
        initiatorController.accept();
    }
}
Also used : WalletPasswordDialog(com.sparrowwallet.sparrow.control.WalletPasswordDialog) Storage(com.sparrowwallet.sparrow.io.Storage) StorageEvent(com.sparrowwallet.sparrow.event.StorageEvent) InvalidPasswordException(com.sparrowwallet.drongo.crypto.InvalidPasswordException) SecureString(com.sparrowwallet.drongo.SecureString)

Aggregations

SecureString (com.sparrowwallet.drongo.SecureString)1 InvalidPasswordException (com.sparrowwallet.drongo.crypto.InvalidPasswordException)1 WalletPasswordDialog (com.sparrowwallet.sparrow.control.WalletPasswordDialog)1 StorageEvent (com.sparrowwallet.sparrow.event.StorageEvent)1 Storage (com.sparrowwallet.sparrow.io.Storage)1