From 29b4a60dacc64d5b07c13ebbf992a7cb70d7009e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Mon, 4 Jan 2021 16:23:49 -0500 Subject: [PATCH 1/3] Add export to CSV button --- .../components/TxConfidenceListItem.java | 5 ++ .../main/dao/wallet/tx/BsqTxListItem.java | 20 +++++++ .../desktop/main/dao/wallet/tx/BsqTxView.java | 56 ++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/TxConfidenceListItem.java b/desktop/src/main/java/bisq/desktop/components/TxConfidenceListItem.java index f8f7cc58f31..e658cf9ee63 100644 --- a/desktop/src/main/java/bisq/desktop/components/TxConfidenceListItem.java +++ b/desktop/src/main/java/bisq/desktop/components/TxConfidenceListItem.java @@ -61,6 +61,11 @@ public void onTransactionConfidenceChanged(TransactionConfidence confidence) { updateConfidence(bsqWalletService.getConfidenceForTxId(txId), tooltip); } + protected TxConfidenceListItem() { + this.bsqWalletService = null; + this.txId = null; + } + private void updateConfidence(TransactionConfidence confidence, Tooltip tooltip) { if (confidence != null) { GUIUtil.updateConfidence(confidence, tooltip, txConfidenceIndicator); diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java index 342bdfdd761..77198821625 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java @@ -18,6 +18,7 @@ package bisq.desktop.main.dao.wallet.tx; import bisq.desktop.components.TxConfidenceListItem; +import bisq.desktop.util.DisplayUtils; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; @@ -131,6 +132,17 @@ class BsqTxListItem extends TxConfidenceListItem { address = ""; } + BsqTxListItem() { + this.daoFacade = null; + this.isBurnedBsqTx = false; + this.date = null; + this.withdrawalToBTCWallet = false; + this.address = null; + this.direction = null; + this.amount = null; + this.bsqFormatter = null; + } + public TxType getTxType() { return daoFacade.getTx(txId) .flatMap(tx -> daoFacade.getOptionalTxType(tx.getId())) @@ -140,5 +152,13 @@ public TxType getTxType() { public boolean isWithdrawalToBTCWallet() { return withdrawalToBTCWallet; } + + public String getDateAsString() { + return DisplayUtils.formatDateTime(date); + } + + public String getAmountAsString() { + return bsqFormatter.formatCoin(amount); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java index 72200461b1c..e86e4c3acda 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java @@ -20,6 +20,7 @@ import bisq.desktop.common.view.ActivatableView; import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AddressWithIconAndDirection; +import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.AutoTooltipTableColumn; import bisq.desktop.components.ExternalHyperlink; @@ -49,12 +50,16 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.Transaction; +import com.googlecode.jcsv.writer.CSVEntryConverter; + import javax.inject.Inject; import de.jensd.fx.fontawesome.AwesomeIcon; import com.jfoenix.controls.JFXProgressBar; +import javafx.stage.Stage; + import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.TableCell; @@ -64,6 +69,7 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; +import javafx.scene.layout.Region; import javafx.scene.layout.VBox; import javafx.geometry.Insets; @@ -88,6 +94,7 @@ public class BsqTxView extends ActivatableView implements BsqBal BsqWalletService.WalletTransactionsChangeListener { private TableView tableView; + private AutoTooltipButton exportButton; private final DaoFacade daoFacade; private final DaoStateService daoStateService; @@ -156,10 +163,14 @@ public void initialize() { chainHeightLabel = FormBuilder.addLabel(root, ++gridRow, ""); chainHeightLabel.setId("num-offers"); chainHeightLabel.setPadding(new Insets(-5, 0, -10, 5)); + exportButton = new AutoTooltipButton(); + exportButton.updateText(Res.get("shared.exportCSV")); + Region spacer = new Region(); + HBox.setHgrow(spacer, Priority.ALWAYS); HBox hBox = new HBox(); hBox.setSpacing(10); - hBox.getChildren().addAll(chainHeightLabel, chainSyncIndicator); + hBox.getChildren().addAll(chainHeightLabel, chainSyncIndicator, spacer, exportButton); VBox vBox = new VBox(); vBox.setSpacing(10); @@ -199,6 +210,44 @@ protected void activate() { updateAnyChainHeightTimer = UserThread.runPeriodically(this::onUpdateAnyChainHeight, 100, TimeUnit.MILLISECONDS); } onUpdateAnyChainHeight(); + + exportButton.setOnAction(event -> { + ObservableList> tableColumns = tableView.getColumns(); + int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon) + CSVEntryConverter headerConverter = item -> { + String[] columns = new String[8]; + int i = 0; + columns[i] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText(); + i++; + columns[i] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText(); + i++; + columns[2] = Res.get("shared.details"); + columns[3] = Res.get("shared.address"); + columns[4] = Res.get("funds.tx.receivedFunds"); + i++; + columns[5] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText(); + i++; + columns[6] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText(); + i++; + columns[7] = ((AutoTooltipLabel) tableColumns.get(i).getGraphic()).getText(); + return columns; + }; + CSVEntryConverter contentConverter = item -> { + String[] columns = new String[8]; + columns[0] = item.getDateAsString(); + columns[1] = item.getTxId(); + columns[2] = item.getDirection(); + columns[3] = item.getAddress(); + columns[4] = String.valueOf(item.isReceived()); + columns[5] = item.getAmountAsString(); + columns[6] = String.valueOf(item.getConfirmations()); + columns[7] = item.getTxType().name(); + return columns; + }; + + GUIUtil.exportCSV("BSQ_transactions.csv", headerConverter, contentConverter, + new BsqTxListItem(), sortedList, (Stage) root.getScene().getWindow()); + }); } @Override @@ -209,6 +258,7 @@ protected void deactivate() { bsqWalletService.removeBsqBalanceListener(this); btcWalletService.getChainHeightProperty().removeListener(walletChainHeightListener); daoFacade.removeBsqStateListener(this); + exportButton.setOnAction(null); observableList.forEach(BsqTxListItem::cleanup); @@ -368,7 +418,7 @@ public void updateItem(final BsqTxListItem item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { - setText(DisplayUtils.formatDateTime(item.getDate())); + setText(item.getDateAsString()); } else { setText(""); } @@ -522,7 +572,7 @@ public void updateItem(final BsqTxListItem item, boolean empty) { if (item.getConfirmations() > 0) { if (isValidType(txType)) - bsqAmount = bsqFormatter.formatCoin(item.getAmount()); + bsqAmount = item.getAmountAsString(); else if (item.isWithdrawalToBTCWallet()) bsqAmount = bsqFormatter.formatBSQSatoshis(0L); } From fe7fdbde9a41a2281e9d701babaa6c173961bed7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Mon, 4 Jan 2021 16:24:27 -0500 Subject: [PATCH 2/3] Add `num-offers` stype to numItems labels --- .../src/main/java/bisq/desktop/main/funds/locked/LockedView.java | 1 + .../main/java/bisq/desktop/main/funds/reserved/ReservedView.java | 1 + .../bisq/desktop/main/funds/transactions/TransactionsView.java | 1 + .../desktop/main/portfolio/closedtrades/ClosedTradesView.java | 1 + .../desktop/main/portfolio/failedtrades/FailedTradesView.java | 1 + .../bisq/desktop/main/portfolio/openoffer/OpenOffersView.java | 1 + 6 files changed, 6 insertions(+) diff --git a/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java b/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java index 0148bd4baf6..db459d0515b 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/locked/LockedView.java @@ -161,6 +161,7 @@ public void onBalanceChanged(Coin balance, Transaction tx) { tradeListChangeListener = c -> updateList(); HBox.setHgrow(spacer, Priority.ALWAYS); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); exportButton.updateText(Res.get("shared.exportCSV")); } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java b/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java index f1135246655..4d5db041feb 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/reserved/ReservedView.java @@ -161,6 +161,7 @@ public void onBalanceChanged(Coin balance, Transaction tx) { tradeListChangeListener = c -> updateList(); HBox.setHgrow(spacer, Priority.ALWAYS); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); exportButton.updateText(Res.get("shared.exportCSV")); } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java index 4aefbe9b9d4..3a2d3e1ba2e 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/transactions/TransactionsView.java @@ -192,6 +192,7 @@ public void initialize() { }; HBox.setHgrow(spacer, Priority.ALWAYS); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); exportButton.updateText(Res.get("shared.exportCSV")); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java index 6c4ebcf0f91..cc44cba579f 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesView.java @@ -236,6 +236,7 @@ public void initialize() { searchBox.setSpacing(5); HBox.setHgrow(searchBoxSpacer, Priority.ALWAYS); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); HBox.setHgrow(footerSpacer, Priority.ALWAYS); HBox.setMargin(exportButton, new Insets(0, 10, 0, 0)); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java index 6297584d7f4..26f1ec182c6 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesView.java @@ -179,6 +179,7 @@ public void initialize() { searchBox.setSpacing(5); HBox.setHgrow(searchBoxSpacer, Priority.ALWAYS); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); HBox.setHgrow(footerSpacer, Priority.ALWAYS); HBox.setMargin(exportButton, new Insets(0, 10, 0, 0)); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java index 873c73c0cae..ecd24cf7493 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOffersView.java @@ -183,6 +183,7 @@ public void initialize() { selectToggleButton.setText(Res.get("shared.enabled")); selectToggleButton.setDisable(true); + numItems.setId("num-offers"); numItems.setPadding(new Insets(-5, 0, 0, 10)); HBox.setHgrow(footerSpacer, Priority.ALWAYS); HBox.setMargin(exportButton, new Insets(0, 10, 0, 0)); From 6c62e77d7c6a0a0978c59336fb5c45355da149b9 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 8 Jan 2021 14:24:24 -0500 Subject: [PATCH 3/3] Remove unused variable --- .../src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java | 1 - 1 file changed, 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java index e86e4c3acda..55760b3f1fa 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java @@ -213,7 +213,6 @@ protected void activate() { exportButton.setOnAction(event -> { ObservableList> tableColumns = tableView.getColumns(); - int reportColumns = tableColumns.size() - 1; // CSV report excludes the last column (an icon) CSVEntryConverter headerConverter = item -> { String[] columns = new String[8]; int i = 0;