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..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 @@ -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,43 @@ protected void activate() { updateAnyChainHeightTimer = UserThread.runPeriodically(this::onUpdateAnyChainHeight, 100, TimeUnit.MILLISECONDS); } onUpdateAnyChainHeight(); + + exportButton.setOnAction(event -> { + ObservableList> tableColumns = tableView.getColumns(); + 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 +257,7 @@ protected void deactivate() { bsqWalletService.removeBsqBalanceListener(this); btcWalletService.getChainHeightProperty().removeListener(walletChainHeightListener); daoFacade.removeBsqStateListener(this); + exportButton.setOnAction(null); observableList.forEach(BsqTxListItem::cleanup); @@ -368,7 +417,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 +571,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); } 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));