From 2897f88c8b24ffefa3a42686eee53282f456de26 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 21 Jun 2023 15:47:21 +0200 Subject: [PATCH] fix unit format switching on send tab --- .../sparrowwallet/sparrow/control/CoinTextFormatter.java | 4 ++-- .../sparrowwallet/sparrow/control/TransactionDiagram.java | 3 ++- .../com/sparrowwallet/sparrow/wallet/PaymentController.java | 2 +- .../com/sparrowwallet/sparrow/wallet/SendController.java | 6 ++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java b/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java index e19be1d6..601d8f3b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java @@ -12,7 +12,7 @@ import java.util.regex.Pattern; public class CoinTextFormatter extends TextFormatter { public CoinTextFormatter(UnitFormat unitFormat) { - super(new CoinFilter(unitFormat)); + super(new CoinFilter(unitFormat == null ? UnitFormat.DOT : unitFormat)); } public UnitFormat getUnitFormat() { @@ -29,7 +29,7 @@ public class CoinTextFormatter extends TextFormatter { private final Pattern coinValidation; public CoinFilter(UnitFormat unitFormat) { - this.unitFormat = unitFormat == null ? UnitFormat.DOT : unitFormat; + this.unitFormat = unitFormat; this.coinFormat = new DecimalFormat("###,###.########", unitFormat.getDecimalFormatSymbols()); this.coinValidation = Pattern.compile("[\\d" + Pattern.quote(unitFormat.getGroupingSeparator()) + "]*(" + Pattern.quote(unitFormat.getDecimalSeparator()) + "\\d{0,8})?"); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index 93cf0f2f..3a125db8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -535,7 +535,8 @@ public class TransactionDiagram extends GridPane { } private String getSatsValue(long amount) { - return String.format(Locale.ENGLISH, "%,d", amount); + UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat(); + return format.formatSatsValue(amount); } private Pane getInputsLines(List> displayedUtxoSets) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index 7bd322ad..fe68af33 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -706,7 +706,7 @@ public class PaymentController extends WalletFormController implements Initializ @Subscribe public void unitFormatChanged(UnitFormatChangedEvent event) { if(amount.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) { - Long value = getRecipientValueSats(coinTextFormatter.getUnitFormat(), event.getBitcoinUnit()); + Long value = getRecipientValueSats(coinTextFormatter.getUnitFormat(), amountUnit.getSelectionModel().getSelectedItem()); amount.setTextFormatter(new CoinTextFormatter(event.getUnitFormat())); if(value != null) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 1e2de465..4fe86dd6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -896,7 +896,8 @@ public class SendController extends WalletFormController implements Initializabl } private void setFeeRate(Double feeRateAmt) { - feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vB"); + UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat(); + feeRate.setText(format.getCurrencyFormat().format(feeRateAmt) + " sats/vB"); setFeeRatePriority(feeRateAmt); } @@ -1597,8 +1598,9 @@ public class SendController extends WalletFormController implements Initializabl @Subscribe public void unitFormatChanged(UnitFormatChangedEvent event) { + setFeeRate(getFeeRate()); if(fee.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) { - Long value = getFeeValueSats(coinTextFormatter.getUnitFormat(), event.getBitcoinUnit()); + Long value = getFeeValueSats(coinTextFormatter.getUnitFormat(), feeAmountUnit.getSelectionModel().getSelectedItem()); fee.setTextFormatter(new CoinTextFormatter(event.getUnitFormat())); if(value != null) {