implement hide amounts feature

This commit is contained in:
Craig Raw
2025-11-06 10:00:07 +02:00
parent 3a5fa69fb6
commit 16e73ebc32
27 changed files with 244 additions and 35 deletions
@@ -149,6 +149,9 @@ public class AppController implements Initializable {
private CheckMenuItem hideEmptyUsedAddresses;
private static final BooleanProperty hideEmptyUsedAddressesProperty = new SimpleBooleanProperty();
@FXML
private CheckMenuItem hideAmounts;
@FXML
private CheckMenuItem useHdCameraResolution;
private static final BooleanProperty useHdCameraResolutionProperty = new SimpleBooleanProperty();
@@ -384,6 +387,7 @@ public class AppController implements Initializable {
openWalletsInNewWindows.selectedProperty().bindBidirectional(openWalletsInNewWindowsProperty);
hideEmptyUsedAddressesProperty.set(Config.get().isHideEmptyUsedAddresses());
hideEmptyUsedAddresses.selectedProperty().bindBidirectional(hideEmptyUsedAddressesProperty);
hideAmounts.setSelected(Config.get().isHideAmounts());
useHdCameraResolutionProperty.set(Config.get().getWebcamResolution() == null || Config.get().getWebcamResolution().isWidescreenAspect());
useHdCameraResolution.selectedProperty().bindBidirectional(useHdCameraResolutionProperty);
mirrorCameraImageProperty.set(Config.get().isMirrorCapture());
@@ -947,6 +951,12 @@ public class AppController implements Initializable {
EventManager.get().post(new HideEmptyUsedAddressesStatusEvent(item.isSelected()));
}
public void hideAmounts(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource();
Config.get().setHideAmounts(item.isSelected());
EventManager.get().post(new HideAmountsStatusEvent(item.isSelected()));
}
public void useHdCameraResolution(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource();
if(Config.get().getWebcamResolution().isStandardAspect() && item.isSelected()) {
@@ -3124,6 +3134,11 @@ public class AppController implements Initializable {
hideEmptyUsedAddresses.setSelected(event.isHideEmptyUsedAddresses());
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
hideAmounts.setSelected(event.isHideAmounts());
}
@Subscribe
public void requestOpenWallets(RequestOpenWalletsEvent event) {
EventManager.get().post(new OpenWalletsEvent(tabs.getScene().getWindow(), getOpenWalletTabData()));
@@ -128,4 +128,15 @@ public class BalanceChart extends LineChart<Number, Number> {
NumberAxis yaxis = (NumberAxis)getYAxis();
yaxis.setTickLabelFormatter(new CoinAxisFormatter(yaxis, format, unit));
}
public void refreshAxisLabels() {
NumberAxis yaxis = (NumberAxis)getYAxis();
// Force the axis to redraw by invalidating the upper and lower bounds
yaxis.setAutoRanging(false);
double lower = yaxis.getLowerBound();
double upper = yaxis.getUpperBound();
yaxis.setLowerBound(lower);
yaxis.setUpperBound(upper);
yaxis.setAutoRanging(true);
}
}
@@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.BitcoinUnit;
import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.io.Config;
import javafx.scene.chart.NumberAxis;
import javafx.util.StringConverter;
@@ -18,6 +19,10 @@ final class CoinAxisFormatter extends StringConverter<Number> {
@Override
public String toString(Number object) {
if(Config.get().isHideAmounts()) {
return "";
}
Double value = bitcoinUnit.getValue(object.longValue());
return new CoinTextFormatter(unitFormat).getCoinFormat().format(value);
}
@@ -58,16 +58,22 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
DecimalFormat decimalFormat = (amount.longValue() == 0L ? format.getBtcFormat() : format.getTableBtcFormat());
final String btcValue = decimalFormat.format(amount.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN);
if(unit.equals(BitcoinUnit.BTC)) {
tooltip.setValue(satsValue + " " + BitcoinUnit.SATOSHIS.getLabel());
setText(btcValue);
if(Config.get().isHideAmounts()) {
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
setTooltip(null);
setContextMenu(null);
} else {
tooltip.setValue(btcValue + " " + BitcoinUnit.BTC.getLabel());
setText(satsValue);
if(unit.equals(BitcoinUnit.BTC)) {
tooltip.setValue(satsValue + " " + BitcoinUnit.SATOSHIS.getLabel());
setText(btcValue);
} else {
tooltip.setValue(btcValue + " " + BitcoinUnit.BTC.getLabel());
setText(satsValue);
}
setTooltip(tooltip);
contextMenu.updateAmount(amount);
setContextMenu(contextMenu);
}
setTooltip(tooltip);
contextMenu.updateAmount(amount);
setContextMenu(contextMenu);
if(entry instanceof TransactionEntry transactionEntry) {
tooltip.showConfirmations(transactionEntry.confirmationsProperty(), transactionEntry.isCoinbase());
@@ -86,7 +92,7 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
}
} else if(entry instanceof UtxoEntry) {
setGraphic(null);
} else if(entry instanceof HashIndexEntry) {
} else if(entry instanceof HashIndexEntry hashIndexEntry) {
tooltip.hideConfirmations();
Region node = new Region();
@@ -94,8 +100,8 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
setGraphic(node);
setContentDisplay(ContentDisplay.RIGHT);
if(((HashIndexEntry) entry).getType() == HashIndexEntry.Type.INPUT) {
satsValue = "-" + satsValue;
if(hashIndexEntry.getType() == HashIndexEntry.Type.INPUT && !Config.get().isHideAmounts()) {
setText("-" + getText());
}
} else {
setGraphic(null);
@@ -13,6 +13,8 @@ import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
public class CoinLabel extends Label {
public static final String HIDDEN_AMOUNT_TEXT = "\u2022\u2022\u2022\u2022\u2022";
private final LongProperty valueProperty = new SimpleLongProperty(-1);
private final Tooltip tooltip;
private final CoinContextMenu contextMenu;
@@ -49,6 +51,13 @@ public class CoinLabel extends Label {
}
private void setValueAsText(Long value, BitcoinUnit bitcoinUnit) {
if(Config.get().isHideAmounts()) {
setText(HIDDEN_AMOUNT_TEXT);
setTooltip(null);
setContextMenu(null);
return;
}
setTooltip(tooltip);
setContextMenu(contextMenu);
@@ -10,9 +10,7 @@ import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.event.EventHandler;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
public class CopyableCoinLabel extends CopyableLabel {
private final LongProperty valueProperty = new SimpleLongProperty(-1);
@@ -72,6 +70,13 @@ public class CopyableCoinLabel extends CopyableLabel {
}
private void setValueAsText(Long value, UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
if(Config.get().isHideAmounts()) {
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
setTooltip(null);
setContextMenu(null);
return;
}
setTooltip(tooltip);
setContextMenu(contextMenu);
@@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.OsType;
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.sparrow.CurrencyRate;
import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.wallet.Entry;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
@@ -47,20 +48,27 @@ public class FiatCell extends TreeTableCell<Entry, Number> {
CurrencyRate currencyRate = coinTreeTable.getCurrencyRate();
if(currencyRate != null && currencyRate.isAvailable()) {
Currency currency = currencyRate.getCurrency();
double btcRate = currencyRate.getBtcRate();
if(Config.get().isHideAmounts()) {
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
setGraphic(null);
setTooltip(null);
setContextMenu(null);
} else {
Currency currency = currencyRate.getCurrency();
double btcRate = currencyRate.getBtcRate();
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(btcRate));
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(btcRate));
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
setText(label);
setGraphic(null);
setTooltip(tooltip);
setContextMenu(contextMenu);
setText(label);
setGraphic(null);
setTooltip(tooltip);
setContextMenu(contextMenu);
}
} else {
setText(null);
setGraphic(null);
@@ -90,6 +90,13 @@ public class FiatLabel extends CopyableLabel {
private void setValueAsText(long balance, UnitFormat unitFormat) {
if(getCurrency() != null && getBtcRate() > 0.0) {
if(Config.get().isHideAmounts()) {
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
setTooltip(null);
setContextMenu(null);
return;
}
BigDecimal satsBalance = BigDecimal.valueOf(balance);
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(getBtcRate()));
@@ -572,6 +572,10 @@ public class TransactionDiagram extends GridPane {
}
String getSatsValue(long amount) {
if(Config.get().isHideAmounts()) {
return CoinLabel.HIDDEN_AMOUNT_TEXT;
}
UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
return format.formatSatsValue(amount);
}
@@ -90,6 +90,10 @@ public class UtxosChart extends BarChart<String, Number> {
private void installTooltip(XYChart.Data<String, Number> item) {
Tooltip.uninstall(item.getNode(), null);
if(Config.get().isHideAmounts()) {
return;
}
String satsValue = String.format(Locale.ENGLISH, "%,d", item.getYValue());
Tooltip tooltip = new Tooltip(item.getXValue() + "\n" + satsValue + " sats");
tooltip.setShowDelay(Duration.millis(TOOLTIP_SHOW_DELAY));
@@ -129,4 +133,21 @@ public class UtxosChart extends BarChart<String, Number> {
NumberAxis yaxis = (NumberAxis)getYAxis();
yaxis.setTickLabelFormatter(new CoinAxisFormatter(yaxis, format, unit));
}
public void refreshAxisLabels() {
NumberAxis yaxis = (NumberAxis)getYAxis();
// Force the axis to redraw by invalidating the upper and lower bounds
yaxis.setAutoRanging(false);
double lower = yaxis.getLowerBound();
double upper = yaxis.getUpperBound();
yaxis.setLowerBound(lower);
yaxis.setUpperBound(upper);
yaxis.setAutoRanging(true);
}
public void refreshTooltips() {
for(XYChart.Data<String, Number> data : utxoSeries.getData()) {
installTooltip(data);
}
}
}
@@ -0,0 +1,13 @@
package com.sparrowwallet.sparrow.event;
public class HideAmountsStatusEvent {
private final boolean hideAmounts;
public HideAmountsStatusEvent(boolean hideAmounts) {
this.hideAmounts = hideAmounts;
}
public boolean isHideAmounts() {
return hideAmounts;
}
}
@@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.BitcoinUnit;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.UnitFormat;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.wallet.Entry;
import com.sparrowwallet.sparrow.wallet.HashIndexEntry;
@@ -48,6 +49,10 @@ public class NewWalletTransactionsEvent {
}
public String getValueAsText(long value) {
if(Config.get().isHideAmounts()) {
return CoinLabel.HIDDEN_AMOUNT_TEXT;
}
UnitFormat format = Config.get().getUnitFormat();
if(format == null) {
format = UnitFormat.DOT;
@@ -47,6 +47,7 @@ public class Config {
private Theme theme;
private boolean openWalletsInNewWindows = false;
private boolean hideEmptyUsedAddresses = false;
private boolean hideAmounts = false;
private boolean showTransactionHex = true;
private boolean showLoadingLog = true;
private boolean showAddressTransactionCount = false;
@@ -303,6 +304,15 @@ public class Config {
flush();
}
public boolean isHideAmounts() {
return hideAmounts;
}
public void setHideAmounts(boolean hideAmounts) {
this.hideAmounts = hideAmounts;
flush();
}
public boolean isShowTransactionHex() {
return showTransactionHex;
}
@@ -1781,6 +1781,12 @@ public class HeadersController extends TransactionFormController implements Init
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
transactionDiagram.update(transactionDiagram.getWalletTransaction());
fee.refresh();
}
private static class WalletSignComparator implements Comparator<Wallet> {
private static final List<KeystoreSource> sourceOrder = List.of(KeystoreSource.SW_WATCH, KeystoreSource.HW_AIRGAPPED, KeystoreSource.HW_USB, KeystoreSource.SW_SEED);
@@ -578,4 +578,9 @@ public class InputController extends TransactionFormController implements Initia
updateInputLegendFromWallet(inputForm.getTransactionInput(), null);
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
spends.refresh();
}
}
@@ -184,4 +184,9 @@ public class InputsController extends TransactionFormController implements Initi
updatePSBTInputs(inputsForm.getPsbt());
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
total.refresh();
}
}
@@ -228,4 +228,9 @@ public class OutputController extends TransactionFormController implements Initi
updateScriptPubKey(outputForm.getTransactionOutput());
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
value.refresh();
}
}
@@ -6,6 +6,7 @@ import com.sparrowwallet.drongo.protocol.TransactionOutput;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CopyableCoinLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.event.HideAmountsStatusEvent;
import com.sparrowwallet.sparrow.event.TransactionOutputsChangedEvent;
import com.sparrowwallet.sparrow.event.UnitFormatChangedEvent;
import javafx.fxml.FXML;
@@ -68,4 +69,9 @@ public class OutputsController extends TransactionFormController implements Init
updatePieData(outputsPie, outputsForm.getTransaction().getOutputs());
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
total.refresh();
}
}
@@ -358,6 +358,17 @@ public class TransactionController implements Initializable {
void highlightTxHex() {
txhex.applyHighlighting(getTransaction(), selectedInputIndex, selectedOutputIndex);
setTxHexHideAmounts(Config.get().isHideAmounts());
}
private void setTxHexHideAmounts(boolean hideAmounts) {
if(hideAmounts) {
if(!txhex.getStyleClass().contains("hide-amounts")) {
txhex.getStyleClass().add("hide-amounts");
}
} else {
txhex.getStyleClass().remove("hide-amounts");
}
}
private void fetchThisAndInputBlockTransactions(int indexStart, int indexEnd) {
@@ -732,4 +743,9 @@ public class TransactionController implements Initializable {
highlightTxHex();
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
setTxHexHideAmounts(event.isHideAmounts());
}
}
@@ -132,6 +132,12 @@ public class AddressesController extends WalletFormController implements Initial
changeTable.showTransactionsCount(event.isShowCount());
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
receiveTable.refresh();
changeTable.refresh();
}
public void exportReceiveAddresses(ActionEvent event) {
exportAddresses(KeyPurpose.RECEIVE);
}
@@ -923,6 +923,11 @@ public class PaymentController extends WalletFormController implements Initializ
updateOpenWallets(event.getWallets());
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
fiatAmount.refresh();
}
private static class DnsPaymentService extends Service<Optional<DnsPayment>> {
private final String hrn;
@@ -1635,6 +1635,12 @@ public class SendController extends WalletFormController implements Initializabl
}
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
updateTransaction();
fiatFeeAmount.refresh();
}
private class PrivacyAnalysisTooltip extends VBox {
private final List<Label> analysisLabels = new ArrayList<>();
@@ -195,6 +195,16 @@ public class TransactionsController extends WalletFormController implements Init
fiatMempoolBalance.refresh(event.getUnitFormat());
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
transactionsTable.refresh();
balanceChart.refreshAxisLabels();
balance.refresh();
mempoolBalance.refresh();
fiatBalance.refresh();
fiatMempoolBalance.refresh();
}
@Subscribe
public void fiatCurrencySelected(FiatCurrencySelectedEvent event) {
if(event.getExchangeSource() == ExchangeSource.NONE) {
@@ -121,18 +121,22 @@ public class UtxosController extends WalletFormController implements Initializab
long selectedTotal = selectedEntries.stream().mapToLong(Entry::getValue).sum();
if(selectedTotal > 0) {
if(format == null) {
format = UnitFormat.DOT;
}
if(unit == null || unit.equals(BitcoinUnit.AUTO)) {
unit = (selectedTotal >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS);
}
if(unit.equals(BitcoinUnit.BTC)) {
sendSelected.setText("Send Selected (" + format.formatBtcValue(selectedTotal) + " BTC)");
if(Config.get().isHideAmounts()) {
sendSelected.setText("Send Selected");
} else {
sendSelected.setText("Send Selected (" + format.formatSatsValue(selectedTotal) + " sats)");
if(format == null) {
format = UnitFormat.DOT;
}
if(unit == null || unit.equals(BitcoinUnit.AUTO)) {
unit = (selectedTotal >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS);
}
if(unit.equals(BitcoinUnit.BTC)) {
sendSelected.setText("Send Selected (" + format.formatBtcValue(selectedTotal) + " BTC)");
} else {
sendSelected.setText("Send Selected (" + format.formatSatsValue(selectedTotal) + " sats)");
}
}
} else {
sendSelected.setText("Send Selected");
@@ -270,6 +274,19 @@ public class UtxosController extends WalletFormController implements Initializab
fiatMempoolBalance.refresh(event.getUnitFormat());
}
@Subscribe
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
utxosTable.refresh();
utxosChart.update(getWalletForm().getWalletUtxosEntry());
utxosChart.refreshAxisLabels();
utxosChart.refreshTooltips();
balance.refresh();
mempoolBalance.refresh();
fiatBalance.refresh();
fiatMempoolBalance.refresh();
updateButtons(Config.get().getUnitFormat(), Config.get().getBitcoinUnit());
}
@Subscribe
public void walletHistoryStatus(WalletHistoryStatusEvent event) {
utxosTable.updateHistoryStatus(event);
@@ -120,6 +120,7 @@
<SeparatorMenuItem />
<CheckMenuItem fx:id="openWalletsInNewWindows" mnemonicParsing="false" text="Open Wallets In New Windows" onAction="#openWalletsInNewWindows"/>
<CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/>
<CheckMenuItem fx:id="hideAmounts" mnemonicParsing="false" text="Hide Amounts" accelerator="Shortcut+Shift+H" onAction="#hideAmounts"/>
<CheckMenuItem fx:id="showLoadingLog" mnemonicParsing="false" text="Show Wallet Loading Log" onAction="#showLoadingLog" />
<CheckMenuItem fx:id="showTxHex" mnemonicParsing="false" text="Show Transaction Hex" onAction="#showTxHex"/>
<SeparatorMenuItem />
@@ -220,6 +220,7 @@ HorizontalHeaderColumn > TableColumnHeader.column-header.table-column{
.root .script-pubkey { -fx-fill: #c678dd }
.root .script-redeem, .root .script-controlblock { -fx-fill: derive(#e06c75, 20%) }
.root .script-other { -fx-fill: #c8ccd4 }
.root .hide-amounts .output-value { -fx-fill: derive(-fx-control-inner-background, -50%) }
.root #txhex {
-fx-background-color: derive(-fx-control-inner-background, -50%);
@@ -11,6 +11,7 @@
.num-outputs { -fx-fill: color-0 }
.output-value { -fx-fill: color-3 }
.hide-amounts .output-value { -fx-fill: -fx-control-inner-background }
.output-pubkeyscript-length { -fx-fill: color-3 }
.output-pubkeyscript { -fx-fill: color-3 }