Search in sources :

Example 1 with StyleClassValidationDecoration

use of org.controlsfx.validation.decoration.StyleClassValidationDecoration in project sparrow by sparrowwallet.

the class XprvKeystoreImportPane method getDerivationEntry.

private Node getDerivationEntry(List<ChildNumber> derivation) {
    TextField derivationField = new TextField();
    derivationField.setPromptText("Derivation path");
    derivationField.setText(KeyDerivation.writePath(derivation));
    HBox.setHgrow(derivationField, Priority.ALWAYS);
    ValidationSupport validationSupport = new ValidationSupport();
    validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
    validationSupport.registerValidator(derivationField, Validator.combine(Validator.createEmptyValidator("Derivation is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid derivation", !KeyDerivation.isValid(newValue))));
    Button importDerivationButton = new Button("Import Custom Derivation Keystore");
    importDerivationButton.setDisable(true);
    importDerivationButton.setOnAction(event -> {
        showHideLink.setVisible(true);
        setExpanded(false);
        List<ChildNumber> importDerivation = KeyDerivation.parsePath(derivationField.getText());
        importKeystore(importDerivation);
    });
    derivationField.textProperty().addListener((observable, oldValue, newValue) -> {
        importButton.setDisable(newValue.isEmpty() || !KeyDerivation.isValid(newValue) || !KeyDerivation.parsePath(newValue).equals(derivation));
        importDerivationButton.setDisable(newValue.isEmpty() || !KeyDerivation.isValid(newValue) || KeyDerivation.parsePath(newValue).equals(derivation));
    });
    HBox contentBox = new HBox();
    contentBox.setAlignment(Pos.TOP_RIGHT);
    contentBox.setSpacing(20);
    contentBox.getChildren().add(derivationField);
    contentBox.getChildren().add(importDerivationButton);
    contentBox.setPadding(new Insets(10, 30, 10, 30));
    contentBox.setPrefHeight(60);
    return contentBox;
}
Also used : HBox(javafx.scene.layout.HBox) ValidationSupport(org.controlsfx.validation.ValidationSupport) Insets(javafx.geometry.Insets) StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration) ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber)

Example 2 with StyleClassValidationDecoration

use of org.controlsfx.validation.decoration.StyleClassValidationDecoration in project sparrow by sparrowwallet.

the class XprvKeystoreImportPane method getXprvEntry.

private Node getXprvEntry(boolean displayOnly) {
    TextArea xprvField = new TextArea();
    xprvField.setPrefRowCount(2);
    xprvField.setWrapText(true);
    xprvField.getStyleClass().add("fixed-width");
    xprvField.setPromptText(ExtendedKey.Header.fromScriptType(ScriptType.P2PKH, true).getName() + (wallet != null ? "/" + ExtendedKey.Header.fromScriptType(wallet.getScriptType(), true).getName() : "") + "...");
    HBox.setHgrow(xprvField, Priority.ALWAYS);
    if (xprv != null) {
        xprvField.setText(xprv.toString());
    }
    if (displayOnly) {
        xprvField.setEditable(false);
    }
    ValidationSupport validationSupport = new ValidationSupport();
    validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
    validationSupport.registerValidator(xprvField, Validator.combine(Validator.createEmptyValidator("xprv is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid private key", !ExtendedKey.isValid(newValue) || ExtendedKey.fromDescriptor(newValue).getKey().isPubKeyOnly())));
    Button importXprvButton = new Button("Import");
    importXprvButton.setMinWidth(80);
    importXprvButton.setDisable(true);
    importXprvButton.setOnAction(event -> {
        enterXprvButton.setVisible(false);
        importButton.setVisible(true);
        setDescription("Ready to import");
        xprv = ExtendedKey.fromDescriptor(xprvField.getText());
        setContent(getDerivationEntry(wallet.getScriptType().getDefaultDerivation()));
    });
    xprvField.textProperty().addListener((observable, oldValue, newValue) -> {
        importXprvButton.setDisable(newValue.isEmpty() || !ExtendedKey.isValid(newValue) || ExtendedKey.fromDescriptor(newValue).getKey().isPubKeyOnly());
    });
    HBox contentBox = new HBox();
    contentBox.setAlignment(Pos.TOP_RIGHT);
    contentBox.setSpacing(20);
    contentBox.getChildren().add(xprvField);
    if (!displayOnly) {
        contentBox.getChildren().add(importXprvButton);
    }
    contentBox.setPadding(new Insets(10, 30, 10, 30));
    contentBox.setPrefHeight(100);
    return contentBox;
}
Also used : HBox(javafx.scene.layout.HBox) ValidationSupport(org.controlsfx.validation.ValidationSupport) Insets(javafx.geometry.Insets) StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration)

Example 3 with StyleClassValidationDecoration

use of org.controlsfx.validation.decoration.StyleClassValidationDecoration in project sparrow by sparrowwallet.

the class ServerPreferencesController method setupValidation.

private void setupValidation() {
    validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
    validationSupport.registerValidator(publicProxyHost, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Proxy host required", publicUseProxy.isSelected() && newValue.isEmpty()), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid host name", getHost(newValue) == null)));
    validationSupport.registerValidator(publicProxyPort, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid proxy port", !newValue.isEmpty() && !isValidPort(Integer.parseInt(newValue)))));
    validationSupport.registerValidator(coreHost, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid Core host", getHost(newValue) == null)));
    validationSupport.registerValidator(corePort, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid Core port", !newValue.isEmpty() && !isValidPort(Integer.parseInt(newValue)))));
    validationSupport.registerValidator(coreDataDir, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Core Data Dir required", coreAuthToggleGroup.getSelectedToggle().getUserData() == CoreAuthType.COOKIE && (newValue.isEmpty() || getDirectory(newValue) == null))));
    validationSupport.registerValidator(coreUser, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Core user required", coreAuthToggleGroup.getSelectedToggle().getUserData() == CoreAuthType.USERPASS && newValue.isEmpty())));
    validationSupport.registerValidator(corePass, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Core pass required", coreAuthToggleGroup.getSelectedToggle().getUserData() == CoreAuthType.USERPASS && newValue.isEmpty())));
    validationSupport.registerValidator(electrumHost, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid Electrum host", getHost(newValue) == null)));
    validationSupport.registerValidator(electrumPort, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid Electrum port", !newValue.isEmpty() && !isValidPort(Integer.parseInt(newValue)))));
    validationSupport.registerValidator(proxyHost, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Proxy host required", useProxy.isSelected() && newValue.isEmpty()), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid host name", getHost(newValue) == null)));
    validationSupport.registerValidator(proxyPort, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid proxy port", !newValue.isEmpty() && !isValidPort(Integer.parseInt(newValue)))));
    validationSupport.registerValidator(electrumCertificate, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Invalid certificate file", newValue != null && !newValue.isEmpty() && getCertificate(newValue) == null)));
}
Also used : StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration)

Example 4 with StyleClassValidationDecoration

use of org.controlsfx.validation.decoration.StyleClassValidationDecoration in project sparrow by sparrowwallet.

the class SendController method addValidation.

private void addValidation() {
    validationSupport = new ValidationSupport();
    validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
    validationSupport.registerValidator(fee, Validator.combine((Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Insufficient Inputs", userFeeSet.get() && insufficientInputsProperty.get()), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Insufficient Fee", getFeeValueSats() != null && getFeeValueSats() == 0), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Insufficient Fee Rate", isInsufficientFeeRate())));
    validationSupport.setErrorDecorationEnabled(false);
}
Also used : ValidationSupport(org.controlsfx.validation.ValidationSupport) StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration) SecureString(com.sparrowwallet.drongo.SecureString)

Example 5 with StyleClassValidationDecoration

use of org.controlsfx.validation.decoration.StyleClassValidationDecoration in project sparrow by sparrowwallet.

the class KeystoreController method setupValidation.

private void setupValidation() {
    validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
    validationSupport.registerValidator(label, Validator.combine(Validator.createEmptyValidator("Label is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Label is not unique", walletForm.getWallet().getKeystores().stream().filter(k -> k != keystore).map(Keystore::getLabel).collect(Collectors.toList()).contains(newValue)), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Label is too long", newValue.replace(" ", "").length() > 16)));
    validationSupport.registerValidator(xpub, Validator.combine(Validator.createEmptyValidator(Network.get().getXpubHeader().getDisplayName() + " is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, Network.get().getXpubHeader().getDisplayName() + " is invalid", !ExtendedKey.isValid(newValue))));
    validationSupport.registerValidator(derivation, Validator.combine(Validator.createEmptyValidator("Derivation is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Derivation is invalid", !KeyDerivation.isValid(newValue)), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Derivation matches another script type", walletForm.getWallet().derivationMatchesAnotherScriptType(newValue))));
    validationSupport.registerValidator(fingerprint, Validator.combine(Validator.createEmptyValidator("Master fingerprint is required"), (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Master fingerprint is invalid", (newValue == null || newValue.length() != 8 || !Utils.isHex(newValue)))));
}
Also used : StyleClassValidationDecoration(org.controlsfx.validation.decoration.StyleClassValidationDecoration)

Aggregations

StyleClassValidationDecoration (org.controlsfx.validation.decoration.StyleClassValidationDecoration)8 ValidationSupport (org.controlsfx.validation.ValidationSupport)5 Insets (javafx.geometry.Insets)4 HBox (javafx.scene.layout.HBox)3 ChildNumber (com.sparrowwallet.drongo.crypto.ChildNumber)2 SecureString (com.sparrowwallet.drongo.SecureString)1 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 InvalidationListener (javafx.beans.InvalidationListener)1 Observable (javafx.beans.Observable)1 Node (javafx.scene.Node)1 CheckBox (javafx.scene.control.CheckBox)1 ChoiceBox (javafx.scene.control.ChoiceBox)1 ColorPicker (javafx.scene.control.ColorPicker)1 ComboBox (javafx.scene.control.ComboBox)1 Control (javafx.scene.control.Control)1 DatePicker (javafx.scene.control.DatePicker)1 Label (javafx.scene.control.Label)1 ListCell (javafx.scene.control.ListCell)1 ListView (javafx.scene.control.ListView)1