Search in sources :

Example 1 with KeystoreImportEvent

use of com.sparrowwallet.sparrow.event.KeystoreImportEvent in project sparrow by sparrowwallet.

the class MnemonicKeystoreImportPane method importKeystore.

private boolean importKeystore(List<ChildNumber> derivation, boolean dryrun) {
    importButton.setDisable(true);
    try {
        Keystore keystore = importer.getKeystore(derivation, wordEntriesProperty.get(), passphraseProperty.get());
        if (!dryrun) {
            if (passphraseProperty.get() != null && !passphraseProperty.get().isEmpty()) {
                KeystorePassphraseDialog keystorePassphraseDialog = new KeystorePassphraseDialog(null, keystore, true);
                Optional<String> optPassphrase = keystorePassphraseDialog.showAndWait();
                if (optPassphrase.isEmpty() || !optPassphrase.get().equals(passphraseProperty.get())) {
                    throw new ImportException("Re-entered passphrase did not match");
                }
            }
            EventManager.get().post(new KeystoreImportEvent(keystore));
        }
        return true;
    } catch (ImportException e) {
        String errorMessage = e.getMessage();
        if (e.getCause() instanceof MnemonicException.MnemonicChecksumException) {
            errorMessage = "Invalid word list - checksum incorrect";
        } else if (e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) {
            errorMessage = e.getCause().getMessage();
        }
        setError("Import Error", errorMessage + ".");
        importButton.setDisable(false);
        return false;
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) ImportException(com.sparrowwallet.sparrow.io.ImportException) MnemonicException(com.sparrowwallet.drongo.wallet.MnemonicException) KeystoreImportEvent(com.sparrowwallet.sparrow.event.KeystoreImportEvent)

Example 2 with KeystoreImportEvent

use of com.sparrowwallet.sparrow.event.KeystoreImportEvent in project sparrow by sparrowwallet.

the class XprvKeystoreImportPane method importKeystore.

private void importKeystore(List<ChildNumber> derivation) {
    importButton.setDisable(true);
    try {
        Keystore keystore = importer.getKeystore(derivation, xprv);
        EventManager.get().post(new KeystoreImportEvent(keystore));
    } catch (ImportException e) {
        String errorMessage = e.getMessage();
        if (e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) {
            errorMessage = e.getCause().getMessage();
        }
        setError("Import Error", errorMessage);
        importButton.setDisable(false);
    }
}
Also used : Keystore(com.sparrowwallet.drongo.wallet.Keystore) ImportException(com.sparrowwallet.sparrow.io.ImportException) KeystoreImportEvent(com.sparrowwallet.sparrow.event.KeystoreImportEvent)

Aggregations

Keystore (com.sparrowwallet.drongo.wallet.Keystore)2 KeystoreImportEvent (com.sparrowwallet.sparrow.event.KeystoreImportEvent)2 ImportException (com.sparrowwallet.sparrow.io.ImportException)2 MnemonicException (com.sparrowwallet.drongo.wallet.MnemonicException)1