add 1 234,56 unit format and use the unit format rather than the system locale for fee rates, sizes, percentages and chart labels
What changed, and why it matters
This commit adds a new number format option ('1 234,56') to the Sparrow Wallet and makes the wallet consistently use the user's chosen number format for fee rates, transaction sizes, percentages, and chart labels instead of relying on the computer's system locale. It also fixes a few places where the wrong decimal separator was hardcoded when reading user-entered amounts. There is no direct evidence this commit fixes an active security vulnerability, but inconsistent number parsing can in principle lead to user mistakes or display confusion.
Treat as a regular functional/correctness improvement. Review the updated drongo and lark submodule commits for any related changes, since the diff only shows pointer updates. No urgent security action is indicated, but wallet teams should ensure amount-parsing tests cover all three unit formats (DOT, COMMA, SPACE) and edge cases such as no-break spaces.
Security signals we found
Locale-independent formatting now uses Locale.ROOT to avoid locale-specific digit characters
User-entered amount parsing fixed to use configured decimal separator instead of hardcoded comma replacement
New unit format option added with space grouping separator and normalisation of no-break/narrow spaces
Subproject dependencies drongo and lark updated to new commits
No vendor security disclosure, CVE, or researcher attribution present in commit or references
Evidence from the diff
The change extends the UnitFormat enum with a SPACE variant (decimal separator ‘,’, grouping separator ’ ‘) and introduces a locale-independent DecimalFormatSymbols based on Locale.ROOT. It adds formatDecimalValue() and normaliseGroupingSeparators() helpers, then replaces String.format(Locale.ENGLISH, …) and hardcoded comma/dot handling across UI controllers, charts, dialogs, and payjoin error messages. Two notable correctness fixes are in PaymentController and SendController, where the previous code always replaced ‘,’ with ‘.’, which would misparse COMMA-format fields; they now use the configured decimal separator. Subproject pointers for drongo and lark are also updated, and two new local-only config/test files (-n/config, -n/lark/trezor.json) are added; these appear to be developer/test artifacts and are not shipped code.
Changed components
UnitFormat formatting/parsing corePaymentController amount parsingSendController fee parsingTransactionDiagram / TransactionDiagramLabel fee/size displayHeadersController size/fee rate displayFeeRangeSlider tick labelsBlockTargetFeeRatesChart / MempoolSizeFeeRatesChart / UtxosChart axis and tooltip labelsEntryCell mempool tooltipPayjoin fee-rate error messageMnemonicGridDialog / PdfUtils / KeycardApi locale-specific String.format callsTerminal GeneralDialog unit format selectiondrongo and lark submodulesInspect captured patch +254 / −45
### -n/config
@@ -0,0 +1,41 @@
+{
+ "mode": "OFFLINE",
+ "bitcoinUnit": "AUTO",
+ "unitFormat": "DOT",
+ "loadRecentWallets": true,
+ "validateDerivationPaths": true,
+ "groupByAddress": true,
+ "includeMempoolOutputs": true,
+ "notifyNewTransactions": true,
+ "checkNewVersions": true,
+ "theme": "SYSTEM",
+ "openWalletsInNewWindows": false,
+ "chunkAddresses": true,
+ "hideEmptyUsedAddresses": false,
+ "hideAmounts": false,
+ "showTransactionHex": true,
+ "showLoadingLog": true,
+ "showAddressTransactionCount": false,
+ "showDeprecatedImportExport": false,
+ "signBsmsExports": false,
+ "preventSleep": false,
+ "verifyTransactions": true,
+ "dustAttackThreshold": 1000,
+ "dustAttackThresholdSp": 5000,
+ "enumerateHwPeriod": 30,
+ "mirrorCapture": true,
+ "useZbar": true,
+ "serverType": "PUBLIC_ELECTRUM_SERVER",
+ "publicElectrumServer": "ssl://electrum.blockstream.info:50002|electrum.blockstream.info",
+ "useLegacyCoreWallet": false,
+ "legacyServer": false,
+ "useProxy": false,
+ "autoSwitchProxy": true,
+ "maxServerTimeout": 34,
+ "maxPageSize": 100,
+ "usePayNym": false,
+ "mempoolFullRbf": false,
+ "minRelayFeeRate": 1.0,
+ "appWidth": 1070.0,
+ "appHeight": 798.0
+}
\ No newline at end of file
### -n/lark/trezor.json
@@ -0,0 +1,11 @@
+{
+ "hostStaticKeypair" : {
+ "private" : "vg5sMEFPwUcZua/iydp9Rj70IXlxdfm42NGJ8VCwkes="
+ },
+ "credentials" : {
+ "G0AAyAOLBOzoox7w3hXP0GfMb5r36TZ959mPU2ZYDD0=" : {
+ "credential" : "ChwKD2lkb21lbmV1cy5sb2NhbBAAGgdTcGFycm93EiAou9S+dnsu3Bx7Yus0QfXaS5ZIRmZVFV59SxHEkvhGHw==",
+ "createdAt" : 1794469292480
+ }
+ }
+}
\ No newline at end of file
### drongo
@@ -1 +1 @@
-Subproject commit 0656034362e7aa6b184ea73d51d08a8f9dfcf6cf
+Subproject commit 3ce42353d76323f1d8c36c32d87e342fdd21572c
### lark
@@ -1 +1 @@
-Subproject commit 5fc7c4516d07499d44ca96921f423997a253ec59
+Subproject commit 4eaaf9d2ef242164c801ab21247e616e5c4ef8f7
### src/main/java/com/sparrowwallet/sparrow/UnitFormat.java
@@ -2,12 +2,15 @@
import com.sparrowwallet.drongo.protocol.Transaction;
+import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
+import java.util.Locale;
public enum UnitFormat {
DOT('.', ','),
- COMMA(',', '.');
+ COMMA(',', '.'),
+ SPACE(',', ' ');
private final char decimalSeparator;
private final char groupingSeparator;
@@ -21,7 +24,8 @@ public enum UnitFormat {
}
public DecimalFormatSymbols getDecimalFormatSymbols() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols();
+ //Some system locales write numbers with their own digits, which amount fields could neither show consistently nor read back
+ DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ROOT);
symbols.setDecimalSeparator(decimalSeparator);
symbols.setGroupingSeparator(groupingSeparator);
return symbols;
@@ -67,6 +71,18 @@ public String tableFormatCurrencyValue(double amount) {
return getTableCurrencyFormat().format(amount);
}
+ public String formatDecimalValue(double value, int fractionDigits) {
+ return formatDecimalValue(value, fractionDigits, fractionDigits);
+ }
+
+ public String formatDecimalValue(double value, int minimumFractionDigits, int maximumFractionDigits) {
+ DecimalFormat decimalFormat = new DecimalFormat("#,##0", getDecimalFormatSymbols());
+ decimalFormat.setMinimumFractionDigits(minimumFractionDigits);
+ decimalFormat.setMaximumFractionDigits(maximumFractionDigits);
+ decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+ return decimalFormat.format(value);
+ }
+
public String getGroupingSeparator() {
return Character.toString(groupingSeparator);
}
@@ -75,6 +91,11 @@ public String getDecimalSeparator() {
return Character.toString(decimalSeparator);
}
+ //Locales that group digits with a space mostly write it as a no-break, narrow no-break or thin space, so an amount copied from a spreadsheet or bank reads the same
+ public String normaliseGroupingSeparators(String text) {
+ return groupingSeparator == ' ' && text != null ? text.replaceAll("[\\u00A0\\u2007\\u2009\\u202F]", " ") : text;
+ }
+
private static class Formats {
private final DecimalFormat btcFormat;
private final DecimalFormat satsFormat;
### src/main/java/com/sparrowwallet/sparrow/control/BlockTargetFeeRatesChart.java
@@ -10,8 +10,11 @@
import javafx.scene.Node;
import javafx.scene.chart.Axis;
import javafx.scene.chart.LineChart;
+import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
+import javafx.util.StringConverter;
+import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -38,6 +41,29 @@ public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object...
public void initialize() {
feeRateSeries = new XYChart.Series<>();
getData().add(feeRateSeries);
+ setUnitFormat(Config.get().getUnitFormat());
+ }
+
+ public void setUnitFormat(UnitFormat unitFormat) {
+ UnitFormat format = unitFormat == null ? UnitFormat.DOT : unitFormat;
+ NumberAxis yAxis = (NumberAxis)getYAxis();
+ yAxis.setTickLabelFormatter(new StringConverter<>() {
+ @Override
+ public String toString(Number object) {
+ //Show as many fraction digits as the tick unit has, so ticks of 0.5 read 1.0 and 1.5 rather than 1 and 1.5
+ int fractionDigits = Math.max(0, BigDecimal.valueOf(yAxis.getTickUnit()).stripTrailingZeros().scale());
+ return format.formatDecimalValue(object.doubleValue(), fractionDigits);
+ }
+
+ @Override
+ public Number fromString(String string) {
+ throw new UnsupportedOperationException();
+ }
+ });
+
+ if(feeRateSeries != null) {
+ setAccessibleText(getSummary());
+ }
}
public void update(Map<Integer, Double> targetBlocksFeeRates) {
### src/main/java/com/sparrowwallet/sparrow/control/CoinTextFormatter.java
@@ -42,6 +42,11 @@ public CoinFilter(UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
@Override
public Change apply(Change change) {
+ String text = unitFormat.normaliseGroupingSeparators(change.getText());
+ if(!text.equals(change.getText())) {
+ change.setText(text);
+ }
+
String oldText = change.getControlText();
String newText = change.getControlNewText();
String deleted = null;
### src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java
@@ -11,6 +11,7 @@
import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.EventManager;
+import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.io.Config;
@@ -514,23 +515,24 @@ private static void unfreezeUtxo(TreeTableView<Entry> treeTableView, HashIndexEn
private String getTooltip(TransactionEntry transactionEntry) {
String tooltip = transactionEntry.getBlockTransaction().getHash().toString();
if(transactionEntry.getBlockTransaction().getHeight() <= 0) {
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
Double feeRate = transactionEntry.getBlockTransaction().getFeeRate();
Long vSizefromTip = transactionEntry.getVSizeFromTip();
if(feeRate != null && vSizefromTip != null) {
long blocksFromTip = (long)Math.ceil((double)vSizefromTip / Transaction.MAX_BLOCK_SIZE_VBYTES);
- String amount = vSizefromTip + " vB";
+ String amount = format.formatSatsValue(vSizefromTip) + " vB";
if(vSizefromTip > 1000 * 1000) {
- amount = String.format("%.2f", (double)vSizefromTip / (1000 * 1000)) + " MvB";
+ amount = format.formatDecimalValue((double)vSizefromTip / (1000 * 1000), 2) + " MvB";
} else if(vSizefromTip > 1000) {
- amount = String.format("%.2f", (double)vSizefromTip / 1000) + " kvB";
+ amount = format.formatDecimalValue((double)vSizefromTip / 1000, 2) + " kvB";
}
tooltip += "\nConfirms in: " + (blocksFromTip > 1 ? blocksFromTip + "+ blocks" : "1 block") + " (" + amount + " from tip)";
}
if(feeRate != null) {
- tooltip += "\nFee rate: " + String.format("%.2f", feeRate) + " sats/vB";
+ tooltip += "\nFee rate: " + format.formatDecimalValue(feeRate, 2) + " sats/vB";
}
tooltip += "\nRBF: " + (canRBF(transactionEntry.getBlockTransaction(), transactionEntry.getWallet()) ? "Enabled" : "Disabled");
### src/main/java/com/sparrowwallet/sparrow/control/FeeRangeSlider.java
@@ -10,16 +10,13 @@
import javafx.scene.control.Slider;
import javafx.util.StringConverter;
-import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
import static com.sparrowwallet.sparrow.AppServices.*;
public class FeeRangeSlider extends Slider {
private static final double FEE_RATE_SCROLL_INCREMENT = 0.01;
- private static final DecimalFormat INTEGER_FEE_RATE_FORMAT = new DecimalFormat("0");
- private static final DecimalFormat FRACTIONAL_FEE_RATE_FORMAT = new DecimalFormat("0.###");
public FeeRangeSlider() {
super(0, AppServices.getFeeRatesRange().size() - 1, 0);
@@ -35,10 +32,11 @@ public FeeRangeSlider() {
@Override
public String toString(Double object) {
Double feeRate = AppServices.getLongFeeRatesRange().get(object.intValue());
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
if(isLongFeeRange() && feeRate >= 1000) {
- return INTEGER_FEE_RATE_FORMAT.format(feeRate / 1000) + "k";
+ return format.formatDecimalValue(feeRate / 1000, 0) + "k";
}
- return feeRate > 0d && feeRate < Transaction.DEFAULT_MIN_RELAY_FEE ? FRACTIONAL_FEE_RATE_FORMAT.format(feeRate) : INTEGER_FEE_RATE_FORMAT.format(feeRate);
+ return feeRate > 0d && feeRate < Transaction.DEFAULT_MIN_RELAY_FEE ? format.formatDecimalValue(feeRate, 0, 3) : format.formatDecimalValue(feeRate, 0);
}
@Override
@@ -121,8 +119,13 @@ public void updateFeeRange(Double minRelayFeeRate, Double previousMinRelayFeeRat
if(minRelayFeeRate != null && previousMinRelayFeeRate != null) {
setFeeRate(getFeeRate(previousMinRelayFeeRate), minRelayFeeRate);
}
+ refreshTickLabels();
+ }
+
+ public void refreshTickLabels() {
setMinorTickCount(1);
setMinorTickCount(0);
+ updateAccessibleText();
}
private void updateMaxFeeRange(double value) {
### src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java
@@ -2,7 +2,9 @@
import com.sparrowwallet.drongo.OsType;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
+import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.net.MempoolRateSize;
import javafx.application.Platform;
import javafx.beans.NamedArg;
@@ -233,10 +235,11 @@ public void update(Map<Date, Set<MempoolRateSize>> mempoolRateSizes) {
@Override
public String toString(Number object) {
long vSizeBytes = object.longValue();
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
if(maxMvB > Y_VALUE_BREAK_MVB) {
- return (vSizeBytes / (1000 * 1000)) + " MvB";
+ return format.formatSatsValue(vSizeBytes / (1000 * 1000)) + " MvB";
} else {
- return (vSizeBytes / (1000)) + " kvB";
+ return format.formatSatsValue(vSizeBytes / 1000) + " kvB";
}
}
@@ -266,8 +269,9 @@ private String getSummary(Map<Date, Set<MempoolRateSize>> periodRateSizes) {
Optional<Set<MempoolRateSize>> latest = periodRateSizes.values().stream().reduce((first, second) -> second);
if(latest.isPresent()) {
long vSize = latest.get().stream().mapToLong(MempoolRateSize::getVSize).sum();
- summary += vSize >= 1_000_000 ? String.format(Locale.ENGLISH, ", currently %.1f MvB", vSize / 1_000_000d)
- : String.format(Locale.ENGLISH, ", currently %,d kvB", vSize / 1000);
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ summary += vSize >= 1_000_000 ? ", currently " + format.formatDecimalValue(vSize / 1_000_000d, 1) + " MvB"
+ : ", currently " + format.formatSatsValue(vSize / 1000) + " kvB";
}
return summary;
@@ -331,6 +335,7 @@ public ChartTooltip(String category, String time, List<Series<String, Number>> s
title.setStyle("-fx-alignment: center; -fx-font-size: 12px; -fx-padding: 0 0 5 0;");
getChildren().add(titleBox);
double maxMvB = getMaxMvB(seriesList);
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
for(int i = seriesList.size() - 1; i >= 0; i--) {
Series<String, Number> series = seriesList.get(i);
@@ -339,7 +344,7 @@ public ChartTooltip(String category, String time, List<Series<String, Number>> s
double kvb = data.getYValue().doubleValue() / 1000;
double mvb = kvb / 1000;
if(mvb >= 0.01 || (maxMvB < Y_VALUE_BREAK_MVB && mvb > 0.001)) {
- String amount = (maxMvB < Y_VALUE_BREAK_MVB ? (int)kvb + " kvB" : String.format("%.2f", mvb) + " MvB");
+ String amount = (maxMvB < Y_VALUE_BREAK_MVB ? format.formatSatsValue((long)kvb) + " kvB" : format.formatDecimalValue(mvb, 2) + " MvB");
Label label = new Label(series.getName() + " sats/vB: " + amount);
Glyph circle = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CIRCLE);
circle.setStyle("-fx-text-fill: VSIZE" + series.getName() + "_COLOR; -fx-opacity: 0.7;");
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicGridDialog.java
@@ -28,6 +28,7 @@
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;
@@ -156,7 +157,7 @@ private Grid getGrid(String[][] wordGrid) {
list.add(createCell(i, j, wordGrid[i][j]));
}
rows.add(list);
- grid.getRowHeaders().add(String.format("%03d", i + 1));
+ grid.getRowHeaders().add(String.format(Locale.ROOT, "%03d", i + 1));
}
grid.setRows(rows);
### src/main/java/com/sparrowwallet/sparrow/control/SendToManyDialog.java
@@ -476,7 +476,7 @@ public Double fromString(String str) {
if(str == null || str.isEmpty()) {
return null;
}
- String normalised = str.trim().replaceAll(Pattern.quote(unitFormat.getGroupingSeparator()), "").replaceAll(Pattern.quote(unitFormat.getDecimalSeparator()), ".");
+ String normalised = unitFormat.normaliseGroupingSeparators(str).trim().replaceAll(Pattern.quote(unitFormat.getGroupingSeparator()), "").replaceAll(Pattern.quote(unitFormat.getDecimalSeparator()), ".");
try {
//Read as an exact decimal, which takes the exponent a script writes a small amount with, but not the hexadecimal, NaN or Infinity a double parses
BigDecimal sats = new BigDecimal(normalised).scaleByPowerOfTen(bitcoinUnit == BitcoinUnit.BTC ? 8 : 0);
### src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java
@@ -772,7 +772,8 @@ private Pane getOutputsLabels(List<WalletTransaction.Output> displayedOutputs) {
boolean highFee = (walletTx.getFeePercentage() > 0.1);
Label feeLabel = highFee ? new Label("High Fee", getFeeWarningGlyph()) : new Label("Fee", getFeeGlyph());
feeLabel.getStyleClass().addAll("output-label", "fee-label");
- String percentage = walletTx.getFeePercentage() < 0.0001d ? "<0.01" : String.format("%.2f", walletTx.getFeePercentage() * 100.0);
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ String percentage = walletTx.getFeePercentage() < 0.0001d ? "<" + format.formatDecimalValue(0.01, 2) : format.formatDecimalValue(walletTx.getFeePercentage() * 100.0, 2);
Tooltip feeTooltip = new Tooltip(walletTx.getFee() < 0 ? "Unknown fee" : "Fee of " + getCoinValue(walletTx.getFee()) + " (" + percentage + "%)");
feeTooltip.getStyleClass().add("fee-tooltip");
feeTooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY));
@@ -950,9 +951,10 @@ private Pane getTransactionPane() {
String txDesc = "Transaction";
Label txLabel = new Label(txDesc);
boolean isFinalized = walletTx.getTransaction().hasScriptSigs() || walletTx.getTransaction().hasWitnesses();
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
Tooltip tooltip = new Tooltip(walletTx.getTransaction().getLength() + " bytes\n"
- + String.format("%.2f", walletTx.getVirtualSize()) + " vBytes"
- + (walletTx.getFee() < 0 ? "" : "\n" + String.format("%.2f", walletTx.getFee() / walletTx.getVirtualSize()) + " sats/vB" + (isFinalized ? "" : " (non-final)")));
+ + format.formatDecimalValue(walletTx.getVirtualSize(), 2) + " vBytes"
+ + (walletTx.getFee() < 0 ? "" : "\n" + format.formatDecimalValue(walletTx.getFee() / walletTx.getVirtualSize(), 2) + " sats/vB" + (isFinalized ? "" : " (non-final)")));
tooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY));
tooltip.setShowDuration(Duration.INDEFINITE);
tooltip.getStyleClass().add("transaction-tooltip");
### src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagramLabel.java
@@ -2,8 +2,10 @@
import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.glyphfont.GlyphUtils;
+import com.sparrowwallet.sparrow.io.Config;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.Pos;
@@ -185,7 +187,8 @@ private OutputLabel getWhirlpoolFeeOutputLabel(TransactionDiagram transactionDia
long total = premixOutputs.stream().mapToLong(Payment::getAmount).sum();
double feePercentage = (double)whirlpoolFee.getAmount() / (total - whirlpoolFee.getAmount());
Glyph glyph = GlyphUtils.getOutputGlyph(transactionDiagram.getWalletTransaction(), whirlpoolFee);
- String text = "Whirlpool fee of " + transactionDiagram.getCoinValue(whirlpoolFee.getAmount()) + " (" + String.format("%.2f", feePercentage * 100.0) + "% of total premix value)";
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ String text = "Whirlpool fee of " + transactionDiagram.getCoinValue(whirlpoolFee.getAmount()) + " (" + format.formatDecimalValue(feePercentage * 100.0, 2) + "% of total premix value)";
return getOutputLabel(glyph, text);
}
@@ -254,7 +257,8 @@ private OutputLabel getFeeOutputLabel(TransactionDiagram transactionDiagram) {
}
Glyph glyph = GlyphUtils.getFeeGlyph();
- String percentage = walletTx.getFeePercentage() < 0.0001d ? "<0.01" : String.format("%.2f", walletTx.getFeePercentage() * 100.0);
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ String percentage = walletTx.getFeePercentage() < 0.0001d ? "<" + format.formatDecimalValue(0.01, 2) : format.formatDecimalValue(walletTx.getFeePercentage() * 100.0, 2);
String text = "Fee of " + transactionDiagram.getCoinValue(walletTx.getFee()) + " (" + percentage + "%)";
return getOutputLabel(glyph, text);
### src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java
@@ -18,7 +18,6 @@
import javafx.util.Duration;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
@@ -110,7 +109,8 @@ private void installTooltip(XYChart.Data<String, Number> item) {
return;
}
- String satsValue = String.format(Locale.ENGLISH, "%,d", item.getYValue());
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ String satsValue = format.formatSatsValue(item.getYValue().longValue());
Tooltip tooltip = new Tooltip(item.getXValue() + "\n" + satsValue + " sats");
tooltip.setShowDelay(Duration.millis(TOOLTIP_SHOW_DELAY));
Tooltip.install(item.getNode(), tooltip);
@@ -148,6 +148,10 @@ public void setUnitFormat(Wallet wallet, UnitFormat format, BitcoinUnit unit) {
NumberAxis yaxis = (NumberAxis)getYAxis();
yaxis.setTickLabelFormatter(new CoinAxisFormatter(yaxis, format, unit));
+
+ if(utxoSeries != null) {
+ refreshTooltips();
+ }
}
public void refreshAxisLabels() {
### src/main/java/com/sparrowwallet/sparrow/io/PdfUtils.java
@@ -209,7 +209,7 @@ public static void saveWordGrid(String[][] wordGrid, List<String> mnemonicWords)
for(int j = 0; j < columnCount + 2; j++) {
Cell cell;
if(j == 0 || j == columnCount + 1) {
- cell = new Cell(new Paragraph(String.format("%03d", i + 1), headerFont));
+ cell = new Cell(new Paragraph(String.format(Locale.ROOT, "%03d", i + 1), headerFont));
cell.setBackgroundColor(new Color(218, 218, 218));
} else {
cell = new Cell(new Paragraph(wordGrid[i][j-1], font));
### src/main/java/com/sparrowwallet/sparrow/io/keycard/KeycardApi.java
@@ -27,6 +27,7 @@
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
public class KeycardApi extends CardApi {
@@ -64,7 +65,7 @@ public void initialize(int slot, byte[] seedBytes) throws CardException {
if(!cardStatus.isInitializedCard()) {
try {
- String puk = String.format("%012d", new SecureRandom().nextLong(999999999999L));
+ String puk = String.format(Locale.ROOT, "%012d", new SecureRandom().nextLong(999999999999L));
this.cardProtocol.init(pin, puk, "KeycardDefaultPairing").checkOK();
this.cardProtocol.select().checkOK();
} catch(IOException | APDUException e) {
### src/main/java/com/sparrowwallet/sparrow/payjoin/Payjoin.java
@@ -13,6 +13,8 @@
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletNode;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.sparrow.UnitFormat;
+import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.net.HttpClientService;
import com.sparrowwallet.sparrow.net.Protocol;
import com.sparrowwallet.tern.http.client.HttpResponseException;
@@ -310,7 +312,9 @@ void checkProposal(PSBT original, PSBT proposal, int changeOutputIndex, long max
// Once signed, the fee rate of the payjoin transaction must not be less than the minfeerate we requested
double proposalFeeRate = getProposalFeeRate(original, proposal);
if(proposalFeeRate < minFeeRate) {
- throw new PayjoinReceiverException("The fee rate of the payjoin transaction of " + String.format("%.2f", proposalFeeRate) + " sats/vB is less than the requested minimum of " + String.format("%.2f", minFeeRate) + " sats/vB");
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ throw new PayjoinReceiverException("The fee rate of the payjoin transaction of " + format.formatDecimalValue(proposalFeeRate, 2) + " sats/vB is less than the requested minimum of "
+ + format.formatDecimalValue(minFeeRate, 2) + " sats/vB");
}
//Add global pubkey map for signing
### src/main/java/com/sparrowwallet/sparrow/terminal/settings/GeneralDialog.java
@@ -16,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Arrays;
import java.util.Currency;
import java.util.List;
@@ -54,7 +55,7 @@ public GeneralDialog() {
mainPanel.addComponent(bitcoinUnit);
mainPanel.addComponent(new Label("Unit Format"));
- unitFormat = new ComboBox<>("1,234.56", "1.235,56");
+ unitFormat = new ComboBox<>(Arrays.stream(UnitFormat.values()).map(format -> format.formatCurrencyValue(1234.56)).toList());
mainPanel.addComponent(unitFormat);
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
@@ -69,7 +70,7 @@ public GeneralDialog() {
mainPanel.addComponent(exchangeSource);
bitcoinUnit.setSelectedItem(Config.get().getBitcoinUnit() == null ? BitcoinUnit.AUTO : Config.get().getBitcoinUnit());
- unitFormat.setSelectedIndex(Config.get().getUnitFormat() == UnitFormat.COMMA ? 1 : 0);
+ unitFormat.setSelectedIndex(Config.get().getUnitFormat() == null ? 0 : Config.get().getUnitFormat().ordinal());
if(Config.get().getExchangeSource() == null) {
Config.get().setExchangeSource(ExchangeSource.COINGECKO);
@@ -85,7 +86,7 @@ public GeneralDialog() {
});
unitFormat.addListener((int selectedIndex, int previousSelection, boolean changedByUserInteraction) -> {
- UnitFormat format = selectedIndex == 1 ? UnitFormat.COMMA : UnitFormat.DOT;
+ UnitFormat format = UnitFormat.values()[selectedIndex];
Config.get().setUnitFormat(format);
Platform.runLater(() -> {
EventManager.get().post(new UnitFormatChangedEvent(format));
### src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
@@ -629,7 +629,8 @@ private void updateType() {
private void updateSize() {
size.setText(headersForm.getTransaction().getSize() + " B");
- virtualSize.setText(String.format("%.2f", getVirtualSize()) + " vB");
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ virtualSize.setText(format.formatDecimalValue(getVirtualSize(), 2) + " vB");
}
/**
@@ -692,7 +693,8 @@ private Long calculateFee(Map<Sha256Hash, BlockTransaction> inputTransactions) {
private void updateFee(Long feeAmt) {
fee.setValue(feeAmt);
double feeRateAmt = feeAmt.doubleValue() / getVirtualSize();
- feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vB" + (headersForm.isTransactionFinalized() ? "" : " (non-final)"));
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ feeRate.setText(format.formatDecimalValue(feeRateAmt, 2) + " sats/vB" + (headersForm.isTransactionFinalized() ? "" : " (non-final)"));
}
private WalletTransaction getWalletTransaction(Map<Sha256Hash, BlockTransaction> inputTransactions) {
@@ -1423,8 +1425,9 @@ public void broadcastTransaction(ActionEvent event) {
if(fee.getValue() > 0) {
double feeRateAmt = fee.getValue() / getVirtualSize();
if(feeRateAmt > AppServices.getLongFeeRatesRange().getLast() || (AppServices.getTargetBlockFeeRates() != null && feeRateAmt > AppServices.getDefaultFeeRate() * FEE_MULTIPLE_LIMIT)) {
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
Optional<ButtonType> optType = AppServices.showWarningDialog("Very high fee rate!",
- "This transaction pays a very high fee rate of " + String.format("%.0f", feeRateAmt) + " sats/vB.\n\nBroadcast this transaction?", ButtonType.YES, ButtonType.NO);
+ "This transaction pays a very high fee rate of " + format.formatDecimalValue(feeRateAmt, 0) + " sats/vB.\n\nBroadcast this transaction?", ButtonType.YES, ButtonType.NO);
if(optType.isPresent() && optType.get() == ButtonType.NO) {
broadcastButton.setDisable(false);
broadcastButton.requestFocus();
@@ -1769,6 +1772,10 @@ public void transactionFetchFailed(TransactionFetchFailedEvent event) {
public void unitFormatChanged(UnitFormatChangedEvent event) {
transactionDiagram.update(transactionDiagram.getWalletTransaction());
fee.refresh(event.getUnitFormat(), event.getBitcoinUnit());
+ updateSize();
+ if(fee.getValue() >= 0) {
+ updateFee(fee.getValue());
+ }
}
@Subscribe
### src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java
@@ -174,6 +174,7 @@ public void blockTransactionFetched(BlockTransactionFetchedEvent event) {
@Subscribe
public void unitFormatChanged(UnitFormatChangedEvent event) {
total.refresh(event.getUnitFormat(), event.getBitcoinUnit());
+ refreshPieTooltips(inputsPie);
}
@Subscribe
### src/main/java/com/sparrowwallet/sparrow/transaction/OutputsController.java
@@ -61,6 +61,7 @@ protected TransactionForm getTransactionForm() {
@Subscribe
public void unitFormatChanged(UnitFormatChangedEvent event) {
total.refresh(event.getUnitFormat(), event.getBitcoinUnit());
+ refreshPieTooltips(outputsPie);
}
@Subscribe
### src/main/java/com/sparrowwallet/sparrow/transaction/TransactionFormController.java
@@ -84,22 +84,34 @@ private void addPieData(PieChart pie, ObservableList<PieChart.Data> outputsPieDa
return;
}
- UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
pie.setData(outputsPieData);
- final double totalSum = outputsPieData.stream().map(PieChart.Data::getPieValue).mapToDouble(Double::doubleValue).sum();
+ final double totalSum = getPieTotal(pie);
pie.getData().forEach(data -> {
- Tooltip tooltip = new Tooltip();
- double percent = 100.0 * (data.getPieValue() / totalSum);
- String satsValue = format.formatSatsValue((long)data.getPieValue()) + " sats";
- String btcValue = format.formatBtcValue((long)data.getPieValue()) + " BTC";
- tooltip.setText(data.getName() + "\n" + (Config.get().getBitcoinUnit() == BitcoinUnit.BTC ? btcValue : satsValue) + " (" + String.format("%.1f", percent) + "%)");
+ Tooltip tooltip = new Tooltip(getPieTooltipText(data, totalSum));
Tooltip.install(data.getNode(), tooltip);
data.pieValueProperty().addListener((observable, oldValue, newValue) -> tooltip.setText(newValue + "%"));
});
Platform.runLater(() -> applyAddressLabelSkinToLegend(pie));
}
+ protected void refreshPieTooltips(PieChart pie) {
+ final double totalSum = getPieTotal(pie);
+ pie.getData().stream().filter(data -> data.getNode() != null).forEach(data -> Tooltip.install(data.getNode(), new Tooltip(getPieTooltipText(data, totalSum))));
+ }
+
+ private double getPieTotal(PieChart pie) {
+ return pie.getData().stream().map(PieChart.Data::getPieValue).mapToDouble(Double::doubleValue).sum();
+ }
+
+ private String getPieTooltipText(PieChart.Data data, double totalSum) {
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ double percent = 100.0 * (data.getPieValue() / totalSum);
+ String satsValue = format.formatSatsValue((long)data.getPieValue()) + " sats";
+ String btcValue = format.formatBtcValue((long)data.getPieValue()) + " BTC";
+ return data.getName() + "\n" + (Config.get().getBitcoinUnit() == BitcoinUnit.BTC ? btcValue : satsValue) + " (" + format.formatDecimalValue(percent, 1) + "%)";
+ }
+
private void applyAddressLabelSkinToLegend(PieChart pie) {
pie.lookupAll(".chart-legend-item").forEach(node -> {
if(node instanceof Label label) {
### src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java
@@ -631,7 +631,7 @@ private Long getRecipientValueSats(BitcoinUnit bitcoinUnit) {
private Long getRecipientValueSats(UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
if(amount.getText() != null && !amount.getText().isEmpty()) {
UnitFormat format = unitFormat == null ? UnitFormat.DOT : unitFormat;
- double fieldValue = Double.parseDouble(amount.getText().replaceAll(Pattern.quote(format.getGroupingSeparator()), "").replaceAll(",", "."));
+ double fieldValue = Double.parseDouble(amount.getText().replaceAll(Pattern.quote(format.getGroupingSeparator()), "").replaceAll(Pattern.quote(format.getDecimalSeparator()), "."));
return bitcoinUnit.getSatsValue(fieldValue);
}
### src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java
@@ -797,7 +797,7 @@ private Long getFeeValueSats(BitcoinUnit bitcoinUnit) {
private Long getFeeValueSats(UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
if(fee.getText() != null && !fee.getText().isEmpty()) {
UnitFormat format = unitFormat == null ? UnitFormat.DOT : unitFormat;
- double fieldValue = Double.parseDouble(fee.getText().replaceAll(Pattern.quote(format.getGroupingSeparator()), "").replaceAll(",", "."));
+ double fieldValue = Double.parseDouble(fee.getText().replaceAll(Pattern.quote(format.getGroupingSeparator()), "").replaceAll(Pattern.quote(format.getDecimalSeparator()), "."));
return bitcoinUnit.getSatsValue(fieldValue);
}
@@ -1576,6 +1576,9 @@ public void unitFormatChanged(UnitFormatChangedEvent event) {
transactionDiagram.update(transactionDiagram.getWalletTransaction());
setEffectiveFeeRate(getWalletTransaction());
setFeeRate(getFeeRate());
+ blockTargetFeeRatesChart.setUnitFormat(event.getUnitFormat());
+ mempoolSizeFeeRatesChart.update(getMempoolHistogram());
+ feeRange.refreshTickLabels();
if(fee.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) {
Long value = getFeeValueSats(coinTextFormatter.getUnitFormat(), feeAmountUnit.getSelectionModel().getSelectedItem());
fee.setTextFormatter(new CoinTextFormatter(event.getUnitFormat(), feeAmountUnit.getValue()));
### src/main/resources/com/sparrowwallet/sparrow/app.fxml
@@ -97,6 +97,11 @@
<UnitFormat fx:constant="COMMA" />
</userData>
</RadioMenuItem>
+ <RadioMenuItem mnemonicParsing="false" text="1 234,56" toggleGroup="$unitFormat" onAction="#setUnitFormat">
+ <userData>
+ <UnitFormat fx:constant="SPACE" />
+ </userData>
+ </RadioMenuItem>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Bitcoin Addresses">
### src/test/java/com/sparrowwallet/sparrow/UnitFormatTest.java
@@ -0,0 +1,49 @@
+package com.sparrowwallet.sparrow;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.text.DecimalFormat;
+import java.util.Locale;
+
+public class UnitFormatTest {
+ @Test
+ public void testFormatOutput() {
+ Assertions.assertEquals("1,234,567", UnitFormat.DOT.formatSatsValue(1234567L));
+ Assertions.assertEquals("1,234,567.89", UnitFormat.DOT.formatCurrencyValue(1234567.89));
+ Assertions.assertEquals("1.234.567", UnitFormat.COMMA.formatSatsValue(1234567L));
+ Assertions.assertEquals("1.234.567,89", UnitFormat.COMMA.formatCurrencyValue(1234567.89));
+ Assertions.assertEquals("1 234 567", UnitFormat.SPACE.formatSatsValue(1234567L));
+ Assertions.assertEquals("1 234 567,89", UnitFormat.SPACE.formatCurrencyValue(1234567.89));
+ Assertions.assertEquals("0,12345678", UnitFormat.SPACE.formatBtcValue(12345678L));
+ }
+
+ @Test
+ public void testFormatIgnoresDefaultLocale() {
+ Locale defaultLocale = Locale.getDefault();
+ try {
+ Locale.setDefault(Locale.forLanguageTag("fa-IR"));
+ Assertions.assertEquals("1 234 567,89", UnitFormat.SPACE.getCurrencyFormat().format(1234567.89));
+ Assertions.assertEquals("1,234.5", new DecimalFormat("#,##0.##", UnitFormat.DOT.getDecimalFormatSymbols()).format(1234.5));
+ Assertions.assertEquals("-1.234,50", UnitFormat.COMMA.formatDecimalValue(-1234.5, 2));
+ } finally {
+ Locale.setDefault(defaultLocale);
+ }
+ }
+
+ @Test
+ public void testFormatDecimalValue() {
+ Assertions.assertEquals("0.13", UnitFormat.DOT.formatDecimalValue(0.125, 2));
+ Assertions.assertEquals("1 234,6", UnitFormat.SPACE.formatDecimalValue(1234.56, 1));
+ Assertions.assertEquals("0,125", UnitFormat.COMMA.formatDecimalValue(0.125, 0, 3));
+ Assertions.assertEquals("8", UnitFormat.COMMA.formatDecimalValue(8.0, 0, 3));
+ }
+
+ @Test
+ public void testNormaliseGroupingSeparators() {
+ Assertions.assertEquals("1 234 567,89", UnitFormat.SPACE.normaliseGroupingSeparators("1 234 567,89"));
+ Assertions.assertEquals("1 234,5", UnitFormat.SPACE.normaliseGroupingSeparators("1 234,5"));
+ Assertions.assertEquals("1 234.5", UnitFormat.DOT.normaliseGroupingSeparators("1 234.5"));
+ Assertions.assertEquals("1 234,5", UnitFormat.COMMA.normaliseGroupingSeparators("1 234,5"));
+ }
+}Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.