From 5860a6e49f595400ef3e30c498cfd04cafea5a8a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sun, 5 Jul 2020 15:23:33 +0200 Subject: [PATCH] validate too large fee --- .../sparrow/wallet/SendController.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 204f8219..f150512e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -80,6 +80,13 @@ public class SendController extends WalletFormController implements Initializabl private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false); + private final ChangeListener amountListener = new ChangeListener() { + @Override + public void changed(ObservableValue observable, String oldValue, String newValue) { + updateTransaction(); + } + }; + private final ChangeListener feeListener = new ChangeListener<>() { @Override public void changed(ObservableValue observable, String oldValue, String newValue) { @@ -124,9 +131,7 @@ public class SendController extends WalletFormController implements Initializabl }); amount.setTextFormatter(new TextFieldValidator(TextFieldValidator.ValidationModus.MAX_FRACTION_DIGITS, 8).getFormatter()); - amount.textProperty().addListener((observable, oldValue, newValue) -> { - updateTransaction(); - }); + amount.textProperty().addListener(amountListener); amountUnit.getSelectionModel().select(1); amountUnit.valueProperty().addListener((observable, oldValue, newValue) -> { @@ -139,9 +144,16 @@ public class SendController extends WalletFormController implements Initializabl }); insufficientInputsProperty.addListener((observable, oldValue, newValue) -> { + amount.textProperty().removeListener(amountListener); String amt = amount.getText(); - amount.setText(amt + " "); + amount.setText(amt + "0"); amount.setText(amt); + amount.textProperty().addListener(amountListener); + fee.textProperty().removeListener(feeListener); + String feeAmt = fee.getText(); + fee.setText(feeAmt + "0"); + fee.setText(feeAmt); + fee.textProperty().addListener(feeListener); }); targetBlocks.setMin(0); @@ -224,6 +236,7 @@ public class SendController extends WalletFormController implements Initializabl (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Insufficient Value", getRecipientValueSats() != null && getRecipientValueSats() == 0) )); 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) ));