Search in sources :

Example 6 with MnemonicException

use of org.bitcoinj.crypto.MnemonicException in project bisq-desktop by bisq-network.

the class WalletPasswordWindow method showRestoreScreen.

private void showRestoreScreen() {
    Label headLine2Label = new AutoTooltipLabel(Res.get("seed.restore.title"));
    headLine2Label.setId("popup-headline");
    headLine2Label.setMouseTransparent(true);
    GridPane.setHalignment(headLine2Label, HPos.LEFT);
    GridPane.setRowIndex(headLine2Label, ++rowIndex);
    GridPane.setColumnSpan(headLine2Label, 2);
    GridPane.setMargin(headLine2Label, new Insets(30, 0, 0, 0));
    gridPane.getChildren().add(headLine2Label);
    Separator separator = new Separator();
    separator.setMouseTransparent(true);
    separator.setOrientation(Orientation.HORIZONTAL);
    separator.getStyleClass().add("separator");
    GridPane.setHalignment(separator, HPos.CENTER);
    GridPane.setRowIndex(separator, ++rowIndex);
    GridPane.setColumnSpan(separator, 2);
    gridPane.getChildren().add(separator);
    Tuple2<Label, TextArea> tuple = addLabelTextArea(gridPane, ++rowIndex, Res.get("seed.seedWords"), "", 5);
    seedWordsTextArea = tuple.second;
    seedWordsTextArea.setPrefHeight(60);
    seedWordsTextArea.getStyleClass().add("text-area");
    Tuple2<Label, DatePicker> labelDatePickerTuple2 = addLabelDatePicker(gridPane, ++rowIndex, Res.get("seed.creationDate"));
    datePicker = labelDatePickerTuple2.second;
    restoreButton = addButton(gridPane, ++rowIndex, Res.get("seed.restore"));
    restoreButton.setDefaultButton(true);
    stage.setHeight(340);
    // wallet creation date is not encrypted
    walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
    log.info("walletCreationDate " + walletCreationDate);
    datePicker.setValue(walletCreationDate);
    restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(), seedWordsValid, seedWordsEdited));
    seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
        if (newValue) {
            seedWordsTextArea.getStyleClass().remove("validation-error");
        } else {
            seedWordsTextArea.getStyleClass().add("validation-error");
        }
    };
    wordsTextAreaChangeListener = (observable, oldValue, newValue) -> {
        seedWordsEdited.set(true);
        try {
            MnemonicCode codec = new MnemonicCode();
            codec.check(Splitter.on(" ").splitToList(newValue));
            seedWordsValid.set(true);
        } catch (IOException | MnemonicException e) {
            seedWordsValid.set(false);
        }
    };
    seedWordsValid.addListener(seedWordsValidChangeListener);
    seedWordsTextArea.textProperty().addListener(wordsTextAreaChangeListener);
    restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(), seedWordsValid, seedWordsEdited));
    restoreButton.setOnAction(e -> onRestore());
    seedWordsTextArea.getStyleClass().remove("validation-error");
    datePicker.getStyleClass().remove("validation-error");
    layout();
}
Also used : MnemonicException(org.bitcoinj.crypto.MnemonicException) Insets(javafx.geometry.Insets) FormBuilder.addLabelTextArea(bisq.desktop.util.FormBuilder.addLabelTextArea) TextArea(javafx.scene.control.TextArea) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) DatePicker(javafx.scene.control.DatePicker) FormBuilder.addLabelDatePicker(bisq.desktop.util.FormBuilder.addLabelDatePicker) IOException(java.io.IOException) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Separator(javafx.scene.control.Separator) MnemonicCode(org.bitcoinj.crypto.MnemonicCode)

Aggregations

MnemonicException (org.bitcoinj.crypto.MnemonicException)6 IOException (java.io.IOException)4 MnemonicCode (org.bitcoinj.crypto.MnemonicCode)4 DeterministicSeed (org.bitcoinj.wallet.DeterministicSeed)3 Insets (javafx.geometry.Insets)2 UnreadableWalletException (org.bitcoinj.wallet.UnreadableWalletException)2 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)1 FormBuilder.addLabelDatePicker (bisq.desktop.util.FormBuilder.addLabelDatePicker)1 FormBuilder.addLabelTextArea (bisq.desktop.util.FormBuilder.addLabelTextArea)1 InvalidMasterSeedException (com.toshi.exception.InvalidMasterSeedException)1 DatePicker (javafx.scene.control.DatePicker)1 Label (javafx.scene.control.Label)1 Separator (javafx.scene.control.Separator)1 TextArea (javafx.scene.control.TextArea)1 Wallet (org.bitcoinj.wallet.Wallet)1