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,24 +50,30 @@ 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);
|
||||||
|
|
||||||
CoinTreeTable coinTreeTable = (CoinTreeTable)getTreeTableView();
|
if(Config.get().isHideAmounts()) {
|
||||||
UnitFormat format = coinTreeTable.getUnitFormat();
|
setText("*****");
|
||||||
BitcoinUnit unit = coinTreeTable.getBitcoinUnit();
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
String satsValue = format.formatSatsValue(amount.longValue());
|
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
tooltip.setValue(btcValue + " " + BitcoinUnit.BTC.getLabel());
|
CoinTreeTable coinTreeTable = (CoinTreeTable)getTreeTableView();
|
||||||
setText(satsValue);
|
UnitFormat format = coinTreeTable.getUnitFormat();
|
||||||
|
BitcoinUnit unit = coinTreeTable.getBitcoinUnit();
|
||||||
|
|
||||||
|
String satsValue = format.formatSatsValue(amount.longValue());
|
||||||
|
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);
|
||||||
|
} 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) {
|
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,20 +48,27 @@ 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()) {
|
||||||
Currency currency = currencyRate.getCurrency();
|
if(Config.get().isHideAmounts()) {
|
||||||
double btcRate = currencyRate.getBtcRate();
|
setText("*****");
|
||||||
|
setGraphic(null);
|
||||||
|
setTooltip(null);
|
||||||
|
setContextMenu(null);
|
||||||
|
} else {
|
||||||
|
Currency currency = currencyRate.getCurrency();
|
||||||
|
double btcRate = currencyRate.getBtcRate();
|
||||||
|
|
||||||
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
|
BigDecimal satsBalance = BigDecimal.valueOf(amount.longValue());
|
||||||
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(btcRate));
|
BigDecimal fiatBalance = btcBalance.multiply(BigDecimal.valueOf(btcRate));
|
||||||
|
|
||||||
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
|
String label = format.formatCurrencyValue(fiatBalance.doubleValue());
|
||||||
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
|
tooltip.setText("1 BTC = " + currency.getSymbol() + " " + format.formatCurrencyValue(btcRate));
|
||||||
|
|
||||||
setText(label);
|
setText(label);
|
||||||
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