mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
feat: implement hide amounts in coin and fiat controls
This commit is contained in:
parent
8008980f5f
commit
8b1fc0149c
7 changed files with 70 additions and 28 deletions
|
|
@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.control;
|
||||||
|
|
||||||
import com.sparrowwallet.drongo.BitcoinUnit;
|
import com.sparrowwallet.drongo.BitcoinUnit;
|
||||||
import com.sparrowwallet.sparrow.UnitFormat;
|
import com.sparrowwallet.sparrow.UnitFormat;
|
||||||
|
import com.sparrowwallet.sparrow.io.Config;
|
||||||
import javafx.scene.chart.NumberAxis;
|
import javafx.scene.chart.NumberAxis;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
|
@ -18,6 +19,9 @@ final class CoinAxisFormatter extends StringConverter<Number> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Number object) {
|
public String toString(Number object) {
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
Double value = bitcoinUnit.getValue(object.longValue());
|
Double value = bitcoinUnit.getValue(object.longValue());
|
||||||
return new CoinTextFormatter(unitFormat).getCoinFormat().format(value);
|
return new CoinTextFormatter(unitFormat).getCoinFormat().format(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||||
Entry entry = getTreeTableView().getTreeItem(getIndex()).getValue();
|
Entry entry = getTreeTableView().getTreeItem(getIndex()).getValue();
|
||||||
EntryCell.applyRowStyles(this, entry);
|
EntryCell.applyRowStyles(this, entry);
|
||||||
|
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
setText("*****");
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
} else {
|
||||||
CoinTreeTable coinTreeTable = (CoinTreeTable)getTreeTableView();
|
CoinTreeTable coinTreeTable = (CoinTreeTable)getTreeTableView();
|
||||||
UnitFormat format = coinTreeTable.getUnitFormat();
|
UnitFormat format = coinTreeTable.getUnitFormat();
|
||||||
BitcoinUnit unit = coinTreeTable.getBitcoinUnit();
|
BitcoinUnit unit = coinTreeTable.getBitcoinUnit();
|
||||||
|
|
@ -68,6 +73,7 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||||
setTooltip(tooltip);
|
setTooltip(tooltip);
|
||||||
contextMenu.updateAmount(amount);
|
contextMenu.updateAmount(amount);
|
||||||
setContextMenu(contextMenu);
|
setContextMenu(contextMenu);
|
||||||
|
}
|
||||||
|
|
||||||
if(entry instanceof TransactionEntry transactionEntry) {
|
if(entry instanceof TransactionEntry transactionEntry) {
|
||||||
tooltip.showConfirmations(transactionEntry.confirmationsProperty(), transactionEntry.isCoinbase());
|
tooltip.showConfirmations(transactionEntry.confirmationsProperty(), transactionEntry.isCoinbase());
|
||||||
|
|
@ -95,7 +101,7 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||||
setContentDisplay(ContentDisplay.RIGHT);
|
setContentDisplay(ContentDisplay.RIGHT);
|
||||||
|
|
||||||
if(((HashIndexEntry) entry).getType() == HashIndexEntry.Type.INPUT) {
|
if(((HashIndexEntry) entry).getType() == HashIndexEntry.Type.INPUT) {
|
||||||
satsValue = "-" + satsValue;
|
setText("-" + getText());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,13 @@ public class CoinLabel extends Label {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setValueAsText(Long value, BitcoinUnit bitcoinUnit) {
|
private void setValueAsText(Long value, BitcoinUnit bitcoinUnit) {
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
setText("*****");
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTooltip(tooltip);
|
setTooltip(tooltip);
|
||||||
setContextMenu(contextMenu);
|
setContextMenu(contextMenu);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,13 @@ public class CopyableCoinLabel extends CopyableLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setValueAsText(Long value, UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
|
private void setValueAsText(Long value, UnitFormat unitFormat, BitcoinUnit bitcoinUnit) {
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
setText("*****");
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTooltip(tooltip);
|
setTooltip(tooltip);
|
||||||
setContextMenu(contextMenu);
|
setContextMenu(contextMenu);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.OsType;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||||
import com.sparrowwallet.sparrow.UnitFormat;
|
import com.sparrowwallet.sparrow.UnitFormat;
|
||||||
|
import com.sparrowwallet.sparrow.io.Config;
|
||||||
import com.sparrowwallet.sparrow.wallet.Entry;
|
import com.sparrowwallet.sparrow.wallet.Entry;
|
||||||
import javafx.scene.control.ContextMenu;
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
|
|
@ -47,6 +48,12 @@ public class FiatCell extends TreeTableCell<Entry, Number> {
|
||||||
CurrencyRate currencyRate = coinTreeTable.getCurrencyRate();
|
CurrencyRate currencyRate = coinTreeTable.getCurrencyRate();
|
||||||
|
|
||||||
if(currencyRate != null && currencyRate.isAvailable()) {
|
if(currencyRate != null && currencyRate.isAvailable()) {
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
setText("*****");
|
||||||
|
setGraphic(null);
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
} else {
|
||||||
Currency currency = currencyRate.getCurrency();
|
Currency currency = currencyRate.getCurrency();
|
||||||
double btcRate = currencyRate.getBtcRate();
|
double btcRate = currencyRate.getBtcRate();
|
||||||
|
|
||||||
|
|
@ -61,6 +68,7 @@ public class FiatCell extends TreeTableCell<Entry, Number> {
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
setTooltip(tooltip);
|
setTooltip(tooltip);
|
||||||
setContextMenu(contextMenu);
|
setContextMenu(contextMenu);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,12 @@ public class FiatLabel extends CopyableLabel {
|
||||||
|
|
||||||
private void setValueAsText(long balance, UnitFormat unitFormat) {
|
private void setValueAsText(long balance, UnitFormat unitFormat) {
|
||||||
if(getCurrency() != null && getBtcRate() > 0.0) {
|
if(getCurrency() != null && getBtcRate() > 0.0) {
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
setText("*****");
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
BigDecimal satsBalance = BigDecimal.valueOf(balance);
|
BigDecimal satsBalance = BigDecimal.valueOf(balance);
|
||||||
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
|
BigDecimal btcBalance = satsBalance.divide(BigDecimal.valueOf(Transaction.SATOSHIS_PER_BITCOIN));
|
||||||
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(getBtcRate()));
|
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(getBtcRate()));
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,10 @@ public class UtxosChart extends BarChart<String, Number> {
|
||||||
private void installTooltip(XYChart.Data<String, Number> item) {
|
private void installTooltip(XYChart.Data<String, Number> item) {
|
||||||
Tooltip.uninstall(item.getNode(), null);
|
Tooltip.uninstall(item.getNode(), null);
|
||||||
|
|
||||||
|
if(Config.get().isHideAmounts()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String satsValue = String.format(Locale.ENGLISH, "%,d", item.getYValue());
|
String satsValue = String.format(Locale.ENGLISH, "%,d", item.getYValue());
|
||||||
Tooltip tooltip = new Tooltip(item.getXValue() + "\n" + satsValue + " sats");
|
Tooltip tooltip = new Tooltip(item.getXValue() + "\n" + satsValue + " sats");
|
||||||
tooltip.setShowDelay(Duration.millis(TOOLTIP_SHOW_DELAY));
|
tooltip.setShowDelay(Duration.millis(TOOLTIP_SHOW_DELAY));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue