mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 00:04:55 +00:00
max button retains state to adjust amount as fee changes
This commit is contained in:
+1
-1
Submodule drongo updated: b84aa2e7cb...c084a0de7e
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<Label style="-fx-pref-width: 15" />
|
||||
<FiatLabel fx:id="fiatAmount" />
|
||||
<Region style="-fx-pref-width: 20" />
|
||||
<Button fx:id="maxButton" text="Max" onAction="#setMaxInput" />
|
||||
<ToggleButton fx:id="maxButton" text="Max" onAction="#setMaxInput" />
|
||||
</Field>
|
||||
</Fieldset>
|
||||
</Form>
|
||||
|
||||
Reference in New Issue
Block a user