From 1f9e37b40c94ccede88af8ab9477d06e2c1fac1e Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 2 Jul 2021 12:05:38 +0200 Subject: [PATCH] enable max button for selected utxos without address and label filled --- .../sparrow/wallet/PaymentController.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index becf14b3..b89eb192 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -8,9 +8,7 @@ import com.sparrowwallet.drongo.address.P2PKHAddress; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.uri.BitcoinURI; -import com.sparrowwallet.drongo.wallet.MaxUtxoSelector; -import com.sparrowwallet.drongo.wallet.Payment; -import com.sparrowwallet.drongo.wallet.UtxoSelector; +import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.CurrencyRate; import com.sparrowwallet.sparrow.EventManager; @@ -25,6 +23,7 @@ import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.ListChangeListener; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -129,7 +128,7 @@ public class PaymentController extends WalletFormController implements Initializ } revalidateAmount(); - maxButton.setDisable(!isValidAddressAndLabel()); + maxButton.setDisable(!isMaxButtonEnabled()); sendController.updateTransaction(); if(validationSupport != null) { @@ -138,7 +137,7 @@ public class PaymentController extends WalletFormController implements Initializ }); label.textProperty().addListener((observable, oldValue, newValue) -> { - maxButton.setDisable(!isValidAddressAndLabel()); + maxButton.setDisable(!isMaxButtonEnabled()); sendController.getCreateButton().setDisable(sendController.getWalletTransaction() == null || newValue == null || newValue.isEmpty() || sendController.isInsufficientFeeRate()); sendController.updateTransaction(); }); @@ -156,7 +155,13 @@ public class PaymentController extends WalletFormController implements Initializ } }); - maxButton.setDisable(!isValidAddressAndLabel()); + maxButton.setDisable(!isMaxButtonEnabled()); + sendController.utxoSelectorProperty().addListener((observable, oldValue, newValue) -> { + maxButton.setDisable(!isMaxButtonEnabled()); + }); + sendController.getPaymentTabs().getTabs().addListener((ListChangeListener) c -> { + maxButton.setDisable(!isMaxButtonEnabled()); + }); sendController.utxoLabelSelectionProperty().addListener((observable, oldValue, newValue) -> { maxButton.setText("Max" + newValue); }); @@ -203,6 +208,10 @@ public class PaymentController extends WalletFormController implements Initializ return isValidRecipientAddress() && !label.getText().isEmpty(); } + private boolean isMaxButtonEnabled() { + return isValidAddressAndLabel() || (sendController.utxoSelectorProperty().get() instanceof PresetUtxoSelector && sendController.getPaymentTabs().getTabs().size() == 1); + } + private Address getRecipientAddress() throws InvalidAddressException { return Address.fromString(address.getText()); } @@ -325,6 +334,11 @@ public class PaymentController extends WalletFormController implements Initializ if(utxoSelector == null) { MaxUtxoSelector maxUtxoSelector = new MaxUtxoSelector(); sendController.utxoSelectorProperty().set(maxUtxoSelector); + } else if(utxoSelector instanceof PresetUtxoSelector && !isValidAddressAndLabel() && sendController.getPaymentTabs().getTabs().size() == 1) { + PresetUtxoSelector presetUtxoSelector = (PresetUtxoSelector)utxoSelector; + Payment payment = new Payment(null, null, presetUtxoSelector.getPresetUtxos().stream().mapToLong(BlockTransactionHashIndex::getValue).sum(), true); + setPayment(payment); + return; } try {