mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
fix unit format switching on send tab
This commit is contained in:
parent
ee20a6980b
commit
2897f88c8b
4 changed files with 9 additions and 6 deletions
|
@ -12,7 +12,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class CoinTextFormatter extends TextFormatter<String> {
|
public class CoinTextFormatter extends TextFormatter<String> {
|
||||||
public CoinTextFormatter(UnitFormat unitFormat) {
|
public CoinTextFormatter(UnitFormat unitFormat) {
|
||||||
super(new CoinFilter(unitFormat));
|
super(new CoinFilter(unitFormat == null ? UnitFormat.DOT : unitFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnitFormat getUnitFormat() {
|
public UnitFormat getUnitFormat() {
|
||||||
|
@ -29,7 +29,7 @@ public class CoinTextFormatter extends TextFormatter<String> {
|
||||||
private final Pattern coinValidation;
|
private final Pattern coinValidation;
|
||||||
|
|
||||||
public CoinFilter(UnitFormat unitFormat) {
|
public CoinFilter(UnitFormat unitFormat) {
|
||||||
this.unitFormat = unitFormat == null ? UnitFormat.DOT : unitFormat;
|
this.unitFormat = unitFormat;
|
||||||
this.coinFormat = new DecimalFormat("###,###.########", unitFormat.getDecimalFormatSymbols());
|
this.coinFormat = new DecimalFormat("###,###.########", unitFormat.getDecimalFormatSymbols());
|
||||||
this.coinValidation = Pattern.compile("[\\d" + Pattern.quote(unitFormat.getGroupingSeparator()) + "]*(" + Pattern.quote(unitFormat.getDecimalSeparator()) + "\\d{0,8})?");
|
this.coinValidation = Pattern.compile("[\\d" + Pattern.quote(unitFormat.getGroupingSeparator()) + "]*(" + Pattern.quote(unitFormat.getDecimalSeparator()) + "\\d{0,8})?");
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,7 +535,8 @@ public class TransactionDiagram extends GridPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSatsValue(long amount) {
|
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<Map<BlockTransactionHashIndex, WalletNode>> displayedUtxoSets) {
|
private Pane getInputsLines(List<Map<BlockTransactionHashIndex, WalletNode>> displayedUtxoSets) {
|
||||||
|
|
|
@ -706,7 +706,7 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void unitFormatChanged(UnitFormatChangedEvent event) {
|
public void unitFormatChanged(UnitFormatChangedEvent event) {
|
||||||
if(amount.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) {
|
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()));
|
amount.setTextFormatter(new CoinTextFormatter(event.getUnitFormat()));
|
||||||
|
|
||||||
if(value != null) {
|
if(value != null) {
|
||||||
|
|
|
@ -896,7 +896,8 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFeeRate(Double feeRateAmt) {
|
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);
|
setFeeRatePriority(feeRateAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1597,8 +1598,9 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void unitFormatChanged(UnitFormatChangedEvent event) {
|
public void unitFormatChanged(UnitFormatChangedEvent event) {
|
||||||
|
setFeeRate(getFeeRate());
|
||||||
if(fee.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) {
|
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()));
|
fee.setTextFormatter(new CoinTextFormatter(event.getUnitFormat()));
|
||||||
|
|
||||||
if(value != null) {
|
if(value != null) {
|
||||||
|
|
Loading…
Reference in a new issue