From adcddfa84d7fc5163819d6a3ef7e667a4408626c Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 17 May 2021 10:09:19 +0200 Subject: [PATCH] various minor utxo screen improvements, including hiding the utxo chart --- .../sparrowwallet/sparrow/AppController.java | 10 ++++++ .../sparrow/control/DateCell.java | 2 +- .../sparrow/control/UtxosChart.java | 11 ++++--- .../sparrow/event/UtxosChartChangedEvent.java | 13 ++++++++ .../com/sparrowwallet/sparrow/io/Config.java | 10 ++++++ .../sparrow/wallet/UtxosController.java | 8 +++++ .../com/sparrowwallet/sparrow/app.fxml | 1 + .../sparrowwallet/sparrow/wallet/utxos.fxml | 33 +++++++------------ 8 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/UtxosChartChangedEvent.java diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 790cfa7b..834d7f79 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -123,6 +123,9 @@ public class AppController implements Initializable { @FXML private CheckMenuItem showLoadingLog; + @FXML + private CheckMenuItem showUtxosChart; + @FXML private CheckMenuItem showTxHex; @@ -259,6 +262,7 @@ public class AppController implements Initializable { useHdCameraResolution.setSelected(Config.get().isHdCapture()); showTxHex.setSelected(Config.get().isShowTransactionHex()); showLoadingLog.setSelected(Config.get().isShowLoadingLog()); + showUtxosChart.setSelected(Config.get().isShowUtxosChart()); savePSBT.visibleProperty().bind(saveTransaction.visibleProperty().not()); exportWallet.setDisable(true); refreshWallet.disableProperty().bind(Bindings.or(exportWallet.disableProperty(), Bindings.or(serverToggle.disableProperty(), AppServices.onlineProperty().not()))); @@ -670,6 +674,12 @@ public class AppController implements Initializable { EventManager.get().post(new LoadingLogChangedEvent(item.isSelected())); } + public void showUtxosChart(ActionEvent event) { + CheckMenuItem item = (CheckMenuItem)event.getSource(); + Config.get().setShowUtxosChart(item.isSelected()); + EventManager.get().post(new UtxosChartChangedEvent(item.isSelected())); + } + public void showTxHex(ActionEvent event) { CheckMenuItem item = (CheckMenuItem)event.getSource(); Config.get().setShowTransactionHex(item.isSelected()); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DateCell.java b/src/main/java/com/sparrowwallet/sparrow/control/DateCell.java index 817abcf7..c9223ef6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DateCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DateCell.java @@ -34,7 +34,7 @@ public class DateCell extends TreeTableCell { if(entry instanceof UtxoEntry) { UtxoEntry utxoEntry = (UtxoEntry)entry; if(utxoEntry.getHashIndex().getHeight() <= 0) { - setText("Unconfirmed " + (utxoEntry.isSpendable() ? "(Spendable)" : "(Not yet spendable)")); + setText("Unconfirmed " + (utxoEntry.getHashIndex().getHeight() < 0 ? "Parent " : "") + (utxoEntry.isSpendable() ? "(Spendable)" : "(Not yet spendable)")); } else { String date = DATE_FORMAT.format(utxoEntry.getHashIndex().getDate()); setText(date); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java b/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java index cd6e12ba..2cdab12a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java @@ -44,16 +44,18 @@ public class UtxosChart extends BarChart { totalUtxos = utxoDataList.size(); if(utxoDataList.size() > MAX_BARS) { - Long otherTotal = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size()).stream().mapToLong(data -> data.getYValue().longValue()).sum(); + List> otherDataList = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size()); + List otherEntries = otherDataList.stream().map(data -> (Entry)data.getExtraValue()).collect(Collectors.toList()); + Long otherTotal = otherDataList.stream().mapToLong(data -> data.getYValue().longValue()).sum(); utxoDataList = utxoDataList.subList(0, MAX_BARS - 1); - utxoDataList.add(new XYChart.Data<>(OTHER_CATEGORY, otherTotal)); + utxoDataList.add(new XYChart.Data<>(OTHER_CATEGORY, otherTotal, otherEntries)); } for(int i = 0; i < utxoDataList.size(); i++) { XYChart.Data newData = utxoDataList.get(i); if(i < utxoSeries.getData().size()) { XYChart.Data existingData = utxoSeries.getData().get(i); - if(!newData.getXValue().equals(existingData.getXValue()) || !newData.getYValue().equals(existingData.getYValue()) || (newData.getExtraValue() != null && !newData.getExtraValue().equals(existingData.getExtraValue()))) { + if(!newData.getXValue().equals(existingData.getXValue()) || !newData.getYValue().equals(existingData.getYValue()) || (newData.getExtraValue() instanceof Entry && !newData.getExtraValue().equals(existingData.getExtraValue()))) { utxoSeries.getData().set(i, newData); } } else { @@ -87,7 +89,8 @@ public class UtxosChart extends BarChart { for(int i = 0; i < utxoSeries.getData().size(); i++) { XYChart.Data data = utxoSeries.getData().get(i); - if((data.getExtraValue() != null && entries.contains((Entry)data.getExtraValue())) || (data.getExtraValue() == null && entries.size() == totalUtxos)) { + if((data.getExtraValue() instanceof Entry && entries.contains((Entry)data.getExtraValue())) || + (data.getExtraValue() instanceof List && entries.containsAll((List)data.getExtraValue()))) { Node bar = lookup(".data" + i); if(bar != null) { bar.getStyleClass().add("selected"); diff --git a/src/main/java/com/sparrowwallet/sparrow/event/UtxosChartChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/UtxosChartChangedEvent.java new file mode 100644 index 00000000..99a95be9 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/UtxosChartChangedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +public class UtxosChartChangedEvent { + private final boolean visible; + + public UtxosChartChangedEvent(boolean visible) { + this.visible = visible; + } + + public boolean isVisible() { + return visible; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index 781cc04c..4587fe88 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -41,6 +41,7 @@ public class Config { private boolean hideEmptyUsedAddresses = false; private boolean showTransactionHex = true; private boolean showLoadingLog = false; + private boolean showUtxosChart = true; private List recentWalletFiles; private Integer keyDerivationPeriod; private File hwi; @@ -257,6 +258,15 @@ public class Config { flush(); } + public boolean isShowUtxosChart() { + return showUtxosChart; + } + + public void setShowUtxosChart(boolean showUtxosChart) { + this.showUtxosChart = showUtxosChart; + flush(); + } + public List getRecentWalletFiles() { return recentWalletFiles; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java index 462e8247..16311c8e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java @@ -50,6 +50,9 @@ public class UtxosController extends WalletFormController implements Initializab utxosChart.select(selectedEntries); updateSendSelected(Config.get().getBitcoinUnit()); }); + + utxosChart.managedProperty().bind(utxosChart.visibleProperty()); + utxosChart.setVisible(Config.get().isShowUtxosChart()); } private void updateSendSelected(BitcoinUnit unit) { @@ -167,4 +170,9 @@ public class UtxosController extends WalletFormController implements Initializab public void includeMempoolOutputsChangedEvent(IncludeMempoolOutputsChangedEvent event) { utxosTable.refresh(); } + + @Subscribe + public void utxosChartChanged(UtxosChartChangedEvent event) { + utxosChart.setVisible(event.isVisible()); + } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/app.fxml b/src/main/resources/com/sparrowwallet/sparrow/app.fxml index 90f0196a..a4503225 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/app.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/app.fxml @@ -89,6 +89,7 @@ + diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/utxos.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/utxos.fxml index 93016bef..cd235f7f 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/utxos.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/utxos.fxml @@ -19,15 +19,8 @@
- - - - - - - - - + + @@ -45,18 +38,14 @@ - -
- - - - - - - - -
-
-
+ + + + + + + + +