From a801773545a77efe662c91fa00d0f663e8945c7a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 4 Mar 2021 13:00:39 +0200 Subject: [PATCH] max button retains state to adjust amount as fee changes --- drongo | 2 +- .../event/FeeRatesSelectionChangedEvent.java | 9 +++++++- .../sparrow/wallet/PaymentController.java | 22 ++++++++++++++++--- .../sparrow/wallet/SendController.java | 13 ++++++++--- .../sparrowwallet/sparrow/wallet/payment.fxml | 2 +- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/drongo b/drongo index b84aa2e7..c084a0de 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit b84aa2e7cb0c1f78fb36d610295ade0439e0df2a +Subproject commit c084a0de7e92bbc500234e66dcec690475ac9121 diff --git a/src/main/java/com/sparrowwallet/sparrow/event/FeeRatesSelectionChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/FeeRatesSelectionChangedEvent.java index 62e4e312..96d3710d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/FeeRatesSelectionChangedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/FeeRatesSelectionChangedEvent.java @@ -1,14 +1,21 @@ package com.sparrowwallet.sparrow.event; +import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.sparrow.wallet.FeeRatesSelection; public class FeeRatesSelectionChangedEvent { + private final Wallet wallet; private final FeeRatesSelection feeRatesSelection; - public FeeRatesSelectionChangedEvent(FeeRatesSelection feeRatesSelection) { + public FeeRatesSelectionChangedEvent(Wallet wallet, FeeRatesSelection feeRatesSelection) { + this.wallet = wallet; this.feeRatesSelection = feeRatesSelection; } + public Wallet getWallet() { + return wallet; + } + public FeeRatesSelection getFeeRateSelection() { return feeRatesSelection; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index 0198c674..e7f756a0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -60,7 +60,7 @@ public class PaymentController extends WalletFormController implements Initializ private FiatLabel fiatAmount; @FXML - private Button maxButton; + private ToggleButton maxButton; @FXML private Button addPaymentButton; @@ -72,6 +72,11 @@ public class PaymentController extends WalletFormController implements Initializ sendController.utxoSelectorProperty().setValue(null); } + for(Tab tab : sendController.getPaymentTabs().getTabs()) { + PaymentController controller = (PaymentController) tab.getUserData(); + controller.setSendMax(false); + } + Long recipientValueSats = getRecipientValueSats(); if(recipientValueSats != null) { setFiatAmount(AppServices.getFiatCurrencyExchangeRate(), recipientValueSats); @@ -235,7 +240,7 @@ public class PaymentController extends WalletFormController implements Initializ } public Payment getPayment() { - return getPayment(false); + return getPayment(isSendMax()); } public Payment getPayment(boolean sendAll) { @@ -273,6 +278,7 @@ public class PaymentController extends WalletFormController implements Initializ amount.textProperty().addListener(amountListener); fiatAmount.setText(""); + setSendMax(false); } public void setMaxInput(ActionEvent event) { @@ -287,9 +293,11 @@ public class PaymentController extends WalletFormController implements Initializ for(Tab tab : sendController.getPaymentTabs().getTabs()) { PaymentController controller = (PaymentController)tab.getUserData(); if(controller != this) { + controller.setSendMax(false); payments.add(controller.getPayment()); } else { - payments.add(getPayment(true)); + setSendMax(true); + payments.add(getPayment()); } } sendController.updateTransaction(payments); @@ -333,6 +341,14 @@ public class PaymentController extends WalletFormController implements Initializ return addPaymentButton; } + public boolean isSendMax() { + return maxButton.isSelected(); + } + + public void setSendMax(boolean sendMax) { + maxButton.setSelected(sendMax); + } + @Subscribe public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) { BitcoinUnit unit = sendController.getBitcoinUnit(event.getBitcoinUnit()); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index a38a4a42..6220317b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -279,7 +279,7 @@ public class SendController extends WalletFormController implements Initializabl feeSelectionToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> { FeeRatesSelection newFeeRatesSelection = (FeeRatesSelection)newValue.getUserData(); Config.get().setFeeRatesSelection(newFeeRatesSelection); - EventManager.get().post(new FeeRatesSelectionChangedEvent(newFeeRatesSelection)); + EventManager.get().post(new FeeRatesSelectionChangedEvent(getWalletForm().getWallet(), newFeeRatesSelection)); }); fee.setTextFormatter(new CoinTextFormatter()); @@ -327,6 +327,10 @@ public class SendController extends WalletFormController implements Initializabl if(userFeeSet.get()) { setTargetBlocks(getTargetBlocks(feeRate)); setFeeRangeRate(feeRate); + + if(walletTransaction.getFee() != getFeeValueSats()) { + setFeeValueSats(walletTransaction.getFee()); + } } else { setFeeValueSats(walletTransaction.getFee()); } @@ -445,7 +449,8 @@ public class SendController extends WalletFormController implements Initializabl try { if(paymentTabs.getTabs().size() == 1) { PaymentController controller = (PaymentController)paymentTabs.getTabs().get(0).getUserData(); - updateTransaction(List.of(controller.getPayment(sendAll))); + controller.setSendMax(sendAll); + updateTransaction(List.of(controller.getPayment())); } else { updateTransaction(null); } @@ -810,7 +815,9 @@ public class SendController extends WalletFormController implements Initializabl @Subscribe public void feeRateSelectionChanged(FeeRatesSelectionChangedEvent event) { - updateFeeRateSelection(event.getFeeRateSelection()); + if(event.getWallet() == getWalletForm().getWallet()) { + updateFeeRateSelection(event.getFeeRateSelection()); + } } @Subscribe diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml index f07c3cba..0bf93efd 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml @@ -49,7 +49,7 @@