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;
}
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;
}
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)));
}
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);
}
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)))));
}
Aggregations