Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add csv export to bsq tx view #5054

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand All @@ -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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -88,6 +94,7 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
BsqWalletService.WalletTransactionsChangeListener {

private TableView<BsqTxListItem> tableView;
private AutoTooltipButton exportButton;

private final DaoFacade daoFacade;
private final DaoStateService daoStateService;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -199,6 +210,43 @@ protected void activate() {
updateAnyChainHeightTimer = UserThread.runPeriodically(this::onUpdateAnyChainHeight, 100, TimeUnit.MILLISECONDS);
}
onUpdateAnyChainHeight();

exportButton.setOnAction(event -> {
ObservableList<TableColumn<BsqTxListItem, ?>> tableColumns = tableView.getColumns();
CSVEntryConverter<BsqTxListItem> 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<BsqTxListItem> 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
Expand All @@ -209,6 +257,7 @@ protected void deactivate() {
bsqWalletService.removeBsqBalanceListener(this);
btcWalletService.getChainHeightProperty().removeListener(walletChainHeightListener);
daoFacade.removeBsqStateListener(this);
exportButton.setOnAction(null);

observableList.forEach(BsqTxListItem::cleanup);

Expand Down Expand Up @@ -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("");
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down