enable max button for selected utxos without address and label filled

This commit is contained in:
Craig Raw 2021-07-02 12:05:38 +02:00
parent a1d2de1859
commit 1f9e37b40c

View file

@ -8,9 +8,7 @@ import com.sparrowwallet.drongo.address.P2PKHAddress;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.protocol.TransactionOutput;
import com.sparrowwallet.drongo.uri.BitcoinURI; import com.sparrowwallet.drongo.uri.BitcoinURI;
import com.sparrowwallet.drongo.wallet.MaxUtxoSelector; import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.drongo.wallet.Payment;
import com.sparrowwallet.drongo.wallet.UtxoSelector;
import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.CurrencyRate; import com.sparrowwallet.sparrow.CurrencyRate;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
@ -25,6 +23,7 @@ import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -129,7 +128,7 @@ public class PaymentController extends WalletFormController implements Initializ
} }
revalidateAmount(); revalidateAmount();
maxButton.setDisable(!isValidAddressAndLabel()); maxButton.setDisable(!isMaxButtonEnabled());
sendController.updateTransaction(); sendController.updateTransaction();
if(validationSupport != null) { if(validationSupport != null) {
@ -138,7 +137,7 @@ public class PaymentController extends WalletFormController implements Initializ
}); });
label.textProperty().addListener((observable, oldValue, newValue) -> { 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.getCreateButton().setDisable(sendController.getWalletTransaction() == null || newValue == null || newValue.isEmpty() || sendController.isInsufficientFeeRate());
sendController.updateTransaction(); 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<Tab>) c -> {
maxButton.setDisable(!isMaxButtonEnabled());
});
sendController.utxoLabelSelectionProperty().addListener((observable, oldValue, newValue) -> { sendController.utxoLabelSelectionProperty().addListener((observable, oldValue, newValue) -> {
maxButton.setText("Max" + newValue); maxButton.setText("Max" + newValue);
}); });
@ -203,6 +208,10 @@ public class PaymentController extends WalletFormController implements Initializ
return isValidRecipientAddress() && !label.getText().isEmpty(); 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 { private Address getRecipientAddress() throws InvalidAddressException {
return Address.fromString(address.getText()); return Address.fromString(address.getText());
} }
@ -325,6 +334,11 @@ public class PaymentController extends WalletFormController implements Initializ
if(utxoSelector == null) { if(utxoSelector == null) {
MaxUtxoSelector maxUtxoSelector = new MaxUtxoSelector(); MaxUtxoSelector maxUtxoSelector = new MaxUtxoSelector();
sendController.utxoSelectorProperty().set(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 { try {