Skip to content

Commit 16e73eb

Browse files
committed
implement hide amounts feature
1 parent 3a5fa69 commit 16e73eb

27 files changed

+243
-34
lines changed

src/main/java/com/sparrowwallet/sparrow/AppController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public class AppController implements Initializable {
149149
private CheckMenuItem hideEmptyUsedAddresses;
150150
private static final BooleanProperty hideEmptyUsedAddressesProperty = new SimpleBooleanProperty();
151151

152+
@FXML
153+
private CheckMenuItem hideAmounts;
154+
152155
@FXML
153156
private CheckMenuItem useHdCameraResolution;
154157
private static final BooleanProperty useHdCameraResolutionProperty = new SimpleBooleanProperty();
@@ -384,6 +387,7 @@ void initializeView() {
384387
openWalletsInNewWindows.selectedProperty().bindBidirectional(openWalletsInNewWindowsProperty);
385388
hideEmptyUsedAddressesProperty.set(Config.get().isHideEmptyUsedAddresses());
386389
hideEmptyUsedAddresses.selectedProperty().bindBidirectional(hideEmptyUsedAddressesProperty);
390+
hideAmounts.setSelected(Config.get().isHideAmounts());
387391
useHdCameraResolutionProperty.set(Config.get().getWebcamResolution() == null || Config.get().getWebcamResolution().isWidescreenAspect());
388392
useHdCameraResolution.selectedProperty().bindBidirectional(useHdCameraResolutionProperty);
389393
mirrorCameraImageProperty.set(Config.get().isMirrorCapture());
@@ -947,6 +951,12 @@ public void hideEmptyUsedAddresses(ActionEvent event) {
947951
EventManager.get().post(new HideEmptyUsedAddressesStatusEvent(item.isSelected()));
948952
}
949953

954+
public void hideAmounts(ActionEvent event) {
955+
CheckMenuItem item = (CheckMenuItem)event.getSource();
956+
Config.get().setHideAmounts(item.isSelected());
957+
EventManager.get().post(new HideAmountsStatusEvent(item.isSelected()));
958+
}
959+
950960
public void useHdCameraResolution(ActionEvent event) {
951961
CheckMenuItem item = (CheckMenuItem)event.getSource();
952962
if(Config.get().getWebcamResolution().isStandardAspect() && item.isSelected()) {
@@ -3124,6 +3134,11 @@ public void hideEmptyUsedAddressesStatusChanged(HideEmptyUsedAddressesStatusEven
31243134
hideEmptyUsedAddresses.setSelected(event.isHideEmptyUsedAddresses());
31253135
}
31263136

3137+
@Subscribe
3138+
public void hideAmountsStatusChanged(HideAmountsStatusEvent event) {
3139+
hideAmounts.setSelected(event.isHideAmounts());
3140+
}
3141+
31273142
@Subscribe
31283143
public void requestOpenWallets(RequestOpenWalletsEvent event) {
31293144
EventManager.get().post(new OpenWalletsEvent(tabs.getScene().getWindow(), getOpenWalletTabData()));

src/main/java/com/sparrowwallet/sparrow/control/BalanceChart.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,15 @@ public void setUnitFormat(Wallet wallet, UnitFormat format, BitcoinUnit unit) {
128128
NumberAxis yaxis = (NumberAxis)getYAxis();
129129
yaxis.setTickLabelFormatter(new CoinAxisFormatter(yaxis, format, unit));
130130
}
131+
132+
public void refreshAxisLabels() {
133+
NumberAxis yaxis = (NumberAxis)getYAxis();
134+
// Force the axis to redraw by invalidating the upper and lower bounds
135+
yaxis.setAutoRanging(false);
136+
double lower = yaxis.getLowerBound();
137+
double upper = yaxis.getUpperBound();
138+
yaxis.setLowerBound(lower);
139+
yaxis.setUpperBound(upper);
140+
yaxis.setAutoRanging(true);
141+
}
131142
}

src/main/java/com/sparrowwallet/sparrow/control/CoinAxisFormatter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.sparrowwallet.drongo.BitcoinUnit;
44
import com.sparrowwallet.sparrow.UnitFormat;
5+
import com.sparrowwallet.sparrow.io.Config;
56
import javafx.scene.chart.NumberAxis;
67
import javafx.util.StringConverter;
78

@@ -18,6 +19,10 @@ public CoinAxisFormatter(NumberAxis axis, UnitFormat format, BitcoinUnit unit) {
1819

1920
@Override
2021
public String toString(Number object) {
22+
if(Config.get().isHideAmounts()) {
23+
return "";
24+
}
25+
2126
Double value = bitcoinUnit.getValue(object.longValue());
2227
return new CoinTextFormatter(unitFormat).getCoinFormat().format(value);
2328
}

src/main/java/com/sparrowwallet/sparrow/control/CoinCell.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ protected void updateItem(Number amount, boolean empty) {
5858
DecimalFormat decimalFormat = (amount.longValue() == 0L ? format.getBtcFormat() : format.getTableBtcFormat());
5959
final String btcValue = decimalFormat.format(amount.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN);
6060

61-
if(unit.equals(BitcoinUnit.BTC)) {
62-
tooltip.setValue(satsValue + " " + BitcoinUnit.SATOSHIS.getLabel());
63-
setText(btcValue);
61+
if(Config.get().isHideAmounts()) {
62+
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
63+
setTooltip(null);
64+
setContextMenu(null);
6465
} else {
65-
tooltip.setValue(btcValue + " " + BitcoinUnit.BTC.getLabel());
66-
setText(satsValue);
66+
if(unit.equals(BitcoinUnit.BTC)) {
67+
tooltip.setValue(satsValue + " " + BitcoinUnit.SATOSHIS.getLabel());
68+
setText(btcValue);
69+
} else {
70+
tooltip.setValue(btcValue + " " + BitcoinUnit.BTC.getLabel());
71+
setText(satsValue);
72+
}
73+
setTooltip(tooltip);
74+
contextMenu.updateAmount(amount);
75+
setContextMenu(contextMenu);
6776
}
68-
setTooltip(tooltip);
69-
contextMenu.updateAmount(amount);
70-
setContextMenu(contextMenu);
7177

7278
if(entry instanceof TransactionEntry transactionEntry) {
7379
tooltip.showConfirmations(transactionEntry.confirmationsProperty(), transactionEntry.isCoinbase());
@@ -86,16 +92,16 @@ protected void updateItem(Number amount, boolean empty) {
8692
}
8793
} else if(entry instanceof UtxoEntry) {
8894
setGraphic(null);
89-
} else if(entry instanceof HashIndexEntry) {
95+
} else if(entry instanceof HashIndexEntry hashIndexEntry) {
9096
tooltip.hideConfirmations();
9197

9298
Region node = new Region();
9399
node.setPrefWidth(10);
94100
setGraphic(node);
95101
setContentDisplay(ContentDisplay.RIGHT);
96102

97-
if(((HashIndexEntry) entry).getType() == HashIndexEntry.Type.INPUT) {
98-
satsValue = "-" + satsValue;
103+
if(hashIndexEntry.getType() == HashIndexEntry.Type.INPUT && !Config.get().isHideAmounts()) {
104+
setText("-" + getText());
99105
}
100106
} else {
101107
setGraphic(null);

src/main/java/com/sparrowwallet/sparrow/control/CoinLabel.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import javafx.scene.input.ClipboardContent;
1414

1515
public class CoinLabel extends Label {
16+
public static final String HIDDEN_AMOUNT_TEXT = "\u2022\u2022\u2022\u2022\u2022";
17+
1618
private final LongProperty valueProperty = new SimpleLongProperty(-1);
1719
private final Tooltip tooltip;
1820
private final CoinContextMenu contextMenu;
@@ -49,6 +51,13 @@ public void refresh(BitcoinUnit bitcoinUnit) {
4951
}
5052

5153
private void setValueAsText(Long value, BitcoinUnit bitcoinUnit) {
54+
if(Config.get().isHideAmounts()) {
55+
setText(HIDDEN_AMOUNT_TEXT);
56+
setTooltip(null);
57+
setContextMenu(null);
58+
return;
59+
}
60+
5261
setTooltip(tooltip);
5362
setContextMenu(contextMenu);
5463

src/main/java/com/sparrowwallet/sparrow/control/CopyableCoinLabel.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import javafx.scene.control.Tooltip;
1111
import javafx.scene.input.Clipboard;
1212
import javafx.scene.input.ClipboardContent;
13-
import javafx.event.EventHandler;
1413
import javafx.scene.input.MouseButton;
15-
import javafx.scene.input.MouseEvent;
1614

1715
public class CopyableCoinLabel extends CopyableLabel {
1816
private final LongProperty valueProperty = new SimpleLongProperty(-1);
@@ -72,6 +70,13 @@ public void refresh(UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
7270
}
7371

7472
private void setValueAsText(Long value, UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
73+
if(Config.get().isHideAmounts()) {
74+
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
75+
setTooltip(null);
76+
setContextMenu(null);
77+
return;
78+
}
79+
7580
setTooltip(tooltip);
7681
setContextMenu(contextMenu);
7782

src/main/java/com/sparrowwallet/sparrow/control/FiatCell.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.sparrowwallet.drongo.protocol.Transaction;
55
import com.sparrowwallet.sparrow.CurrencyRate;
66
import com.sparrowwallet.sparrow.UnitFormat;
7+
import com.sparrowwallet.sparrow.io.Config;
78
import com.sparrowwallet.sparrow.wallet.Entry;
89
import javafx.scene.control.ContextMenu;
910
import javafx.scene.control.MenuItem;
@@ -47,20 +48,27 @@ protected void updateItem(Number amount, boolean empty) {
4748
CurrencyRate currencyRate = coinTreeTable.getCurrencyRate();
4849

4950
if(currencyRate != null && currencyRate.isAvailable()) {
50-
Currency currency = currencyRate.getCurrency();
51-
double btcRate = currencyRate.getBtcRate();
51+
if(Config.get().isHideAmounts()) {
52+
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
53+
setGraphic(null);
54+
setTooltip(null);
55+
setContextMenu(null);
56+
} else {
57+
Currency currency = currencyRate.getCurrency();
58+
double btcRate = currencyRate.getBtcRate();
5259

53-
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
54-
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
55-
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(btcRate));
60+
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
61+
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
62+
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(btcRate));
5663

57-
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
58-
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
64+
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
65+
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
5966

60-
setText(label);
61-
setGraphic(null);
62-
setTooltip(tooltip);
63-
setContextMenu(contextMenu);
67+
setText(label);
68+
setGraphic(null);
69+
setTooltip(tooltip);
70+
setContextMenu(contextMenu);
71+
}
6472
} else {
6573
setText(null);
6674
setGraphic(null);

src/main/java/com/sparrowwallet/sparrow/control/FiatLabel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public void refresh(UnitFormat unitFormat) {
9090

9191
private void setValueAsText(long balance, UnitFormat unitFormat) {
9292
if(getCurrency() != null && getBtcRate() > 0.0) {
93+
if(Config.get().isHideAmounts()) {
94+
setText(CoinLabel.HIDDEN_AMOUNT_TEXT);
95+
setTooltip(null);
96+
setContextMenu(null);
97+
return;
98+
}
99+
93100
BigDecimal satsBalance = BigDecimal.valueOf(balance);
94101
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
95102
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(getBtcRate()));

src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ private String getInputDescription(BlockTransactionHashIndex input) {
572572
}
573573

574574
String getSatsValue(long amount) {
575+
if(Config.get().isHideAmounts()) {
576+
return CoinLabel.HIDDEN_AMOUNT_TEXT;
577+
}
578+
575579
UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
576580
return format.formatSatsValue(amount);
577581
}

src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ private String getCategoryName(Entry entry) {
9090
private void installTooltip(XYChart.Data<String, Number> item) {
9191
Tooltip.uninstall(item.getNode(), null);
9292

93+
if(Config.get().isHideAmounts()) {
94+
return;
95+
}
96+
9397
String satsValue = String.format(Locale.ENGLISH, "%,d", item.getYValue());
9498
Tooltip tooltip = new Tooltip(item.getXValue() + "\n" + satsValue + " sats");
9599
tooltip.setShowDelay(Duration.millis(TOOLTIP_SHOW_DELAY));
@@ -129,4 +133,21 @@ public void setUnitFormat(Wallet wallet, UnitFormat format, BitcoinUnit unit) {
129133
NumberAxis yaxis = (NumberAxis)getYAxis();
130134
yaxis.setTickLabelFormatter(new CoinAxisFormatter(yaxis, format, unit));
131135
}
136+
137+
public void refreshAxisLabels() {
138+
NumberAxis yaxis = (NumberAxis)getYAxis();
139+
// Force the axis to redraw by invalidating the upper and lower bounds
140+
yaxis.setAutoRanging(false);
141+
double lower = yaxis.getLowerBound();
142+
double upper = yaxis.getUpperBound();
143+
yaxis.setLowerBound(lower);
144+
yaxis.setUpperBound(upper);
145+
yaxis.setAutoRanging(true);
146+
}
147+
148+
public void refreshTooltips() {
149+
for(XYChart.Data<String, Number> data : utxoSeries.getData()) {
150+
installTooltip(data);
151+
}
152+
}
132153
}

0 commit comments

Comments
 (0)