mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
max button retains state to adjust amount as fee changes
This commit is contained in:
parent
ffbf4bb0db
commit
a801773545
5 changed files with 39 additions and 9 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
||||||
Subproject commit b84aa2e7cb0c1f78fb36d610295ade0439e0df2a
|
Subproject commit c084a0de7e92bbc500234e66dcec690475ac9121
|
|
@ -1,14 +1,21 @@
|
||||||
package com.sparrowwallet.sparrow.event;
|
package com.sparrowwallet.sparrow.event;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.sparrow.wallet.FeeRatesSelection;
|
import com.sparrowwallet.sparrow.wallet.FeeRatesSelection;
|
||||||
|
|
||||||
public class FeeRatesSelectionChangedEvent {
|
public class FeeRatesSelectionChangedEvent {
|
||||||
|
private final Wallet wallet;
|
||||||
private final FeeRatesSelection feeRatesSelection;
|
private final FeeRatesSelection feeRatesSelection;
|
||||||
|
|
||||||
public FeeRatesSelectionChangedEvent(FeeRatesSelection feeRatesSelection) {
|
public FeeRatesSelectionChangedEvent(Wallet wallet, FeeRatesSelection feeRatesSelection) {
|
||||||
|
this.wallet = wallet;
|
||||||
this.feeRatesSelection = feeRatesSelection;
|
this.feeRatesSelection = feeRatesSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Wallet getWallet() {
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
public FeeRatesSelection getFeeRateSelection() {
|
public FeeRatesSelection getFeeRateSelection() {
|
||||||
return feeRatesSelection;
|
return feeRatesSelection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
private FiatLabel fiatAmount;
|
private FiatLabel fiatAmount;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button maxButton;
|
private ToggleButton maxButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button addPaymentButton;
|
private Button addPaymentButton;
|
||||||
|
@ -72,6 +72,11 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
sendController.utxoSelectorProperty().setValue(null);
|
sendController.utxoSelectorProperty().setValue(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Tab tab : sendController.getPaymentTabs().getTabs()) {
|
||||||
|
PaymentController controller = (PaymentController) tab.getUserData();
|
||||||
|
controller.setSendMax(false);
|
||||||
|
}
|
||||||
|
|
||||||
Long recipientValueSats = getRecipientValueSats();
|
Long recipientValueSats = getRecipientValueSats();
|
||||||
if(recipientValueSats != null) {
|
if(recipientValueSats != null) {
|
||||||
setFiatAmount(AppServices.getFiatCurrencyExchangeRate(), recipientValueSats);
|
setFiatAmount(AppServices.getFiatCurrencyExchangeRate(), recipientValueSats);
|
||||||
|
@ -235,7 +240,7 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payment getPayment() {
|
public Payment getPayment() {
|
||||||
return getPayment(false);
|
return getPayment(isSendMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Payment getPayment(boolean sendAll) {
|
public Payment getPayment(boolean sendAll) {
|
||||||
|
@ -273,6 +278,7 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
amount.textProperty().addListener(amountListener);
|
amount.textProperty().addListener(amountListener);
|
||||||
|
|
||||||
fiatAmount.setText("");
|
fiatAmount.setText("");
|
||||||
|
setSendMax(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxInput(ActionEvent event) {
|
public void setMaxInput(ActionEvent event) {
|
||||||
|
@ -287,9 +293,11 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
for(Tab tab : sendController.getPaymentTabs().getTabs()) {
|
for(Tab tab : sendController.getPaymentTabs().getTabs()) {
|
||||||
PaymentController controller = (PaymentController)tab.getUserData();
|
PaymentController controller = (PaymentController)tab.getUserData();
|
||||||
if(controller != this) {
|
if(controller != this) {
|
||||||
|
controller.setSendMax(false);
|
||||||
payments.add(controller.getPayment());
|
payments.add(controller.getPayment());
|
||||||
} else {
|
} else {
|
||||||
payments.add(getPayment(true));
|
setSendMax(true);
|
||||||
|
payments.add(getPayment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendController.updateTransaction(payments);
|
sendController.updateTransaction(payments);
|
||||||
|
@ -333,6 +341,14 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
return addPaymentButton;
|
return addPaymentButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSendMax() {
|
||||||
|
return maxButton.isSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSendMax(boolean sendMax) {
|
||||||
|
maxButton.setSelected(sendMax);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) {
|
public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) {
|
||||||
BitcoinUnit unit = sendController.getBitcoinUnit(event.getBitcoinUnit());
|
BitcoinUnit unit = sendController.getBitcoinUnit(event.getBitcoinUnit());
|
||||||
|
|
|
@ -279,7 +279,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
feeSelectionToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
|
feeSelectionToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
FeeRatesSelection newFeeRatesSelection = (FeeRatesSelection)newValue.getUserData();
|
FeeRatesSelection newFeeRatesSelection = (FeeRatesSelection)newValue.getUserData();
|
||||||
Config.get().setFeeRatesSelection(newFeeRatesSelection);
|
Config.get().setFeeRatesSelection(newFeeRatesSelection);
|
||||||
EventManager.get().post(new FeeRatesSelectionChangedEvent(newFeeRatesSelection));
|
EventManager.get().post(new FeeRatesSelectionChangedEvent(getWalletForm().getWallet(), newFeeRatesSelection));
|
||||||
});
|
});
|
||||||
|
|
||||||
fee.setTextFormatter(new CoinTextFormatter());
|
fee.setTextFormatter(new CoinTextFormatter());
|
||||||
|
@ -327,6 +327,10 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
if(userFeeSet.get()) {
|
if(userFeeSet.get()) {
|
||||||
setTargetBlocks(getTargetBlocks(feeRate));
|
setTargetBlocks(getTargetBlocks(feeRate));
|
||||||
setFeeRangeRate(feeRate);
|
setFeeRangeRate(feeRate);
|
||||||
|
|
||||||
|
if(walletTransaction.getFee() != getFeeValueSats()) {
|
||||||
|
setFeeValueSats(walletTransaction.getFee());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setFeeValueSats(walletTransaction.getFee());
|
setFeeValueSats(walletTransaction.getFee());
|
||||||
}
|
}
|
||||||
|
@ -445,7 +449,8 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
try {
|
try {
|
||||||
if(paymentTabs.getTabs().size() == 1) {
|
if(paymentTabs.getTabs().size() == 1) {
|
||||||
PaymentController controller = (PaymentController)paymentTabs.getTabs().get(0).getUserData();
|
PaymentController controller = (PaymentController)paymentTabs.getTabs().get(0).getUserData();
|
||||||
updateTransaction(List.of(controller.getPayment(sendAll)));
|
controller.setSendMax(sendAll);
|
||||||
|
updateTransaction(List.of(controller.getPayment()));
|
||||||
} else {
|
} else {
|
||||||
updateTransaction(null);
|
updateTransaction(null);
|
||||||
}
|
}
|
||||||
|
@ -810,7 +815,9 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void feeRateSelectionChanged(FeeRatesSelectionChangedEvent event) {
|
public void feeRateSelectionChanged(FeeRatesSelectionChangedEvent event) {
|
||||||
updateFeeRateSelection(event.getFeeRateSelection());
|
if(event.getWallet() == getWalletForm().getWallet()) {
|
||||||
|
updateFeeRateSelection(event.getFeeRateSelection());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
<Label style="-fx-pref-width: 15" />
|
<Label style="-fx-pref-width: 15" />
|
||||||
<FiatLabel fx:id="fiatAmount" />
|
<FiatLabel fx:id="fiatAmount" />
|
||||||
<Region style="-fx-pref-width: 20" />
|
<Region style="-fx-pref-width: 20" />
|
||||||
<Button fx:id="maxButton" text="Max" onAction="#setMaxInput" />
|
<ToggleButton fx:id="maxButton" text="Max" onAction="#setMaxInput" />
|
||||||
</Field>
|
</Field>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
Loading…
Reference in a new issue