mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
export transactions to csv
This commit is contained in:
parent
3203308d82
commit
0fdc90523e
8 changed files with 81 additions and 2 deletions
|
@ -70,6 +70,7 @@ dependencies {
|
||||||
exclude group: 'org.openjfx', module: 'javafx-media'
|
exclude group: 'org.openjfx', module: 'javafx-media'
|
||||||
}
|
}
|
||||||
implementation('dev.bwt:bwt-jni:0.1.7')
|
implementation('dev.bwt:bwt-jni:0.1.7')
|
||||||
|
implementation('net.sourceforge.javacsv:javacsv:2.0')
|
||||||
testImplementation('junit:junit:4.12')
|
testImplementation('junit:junit:4.12')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class EntryCell extends TreeTableCell<Entry, Entry> {
|
public class EntryCell extends TreeTableCell<Entry, Entry> {
|
||||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
public EntryCell() {
|
public EntryCell() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class FontAwesome5 extends GlyphFont {
|
||||||
EXTERNAL_LINK_ALT('\uf35d'),
|
EXTERNAL_LINK_ALT('\uf35d'),
|
||||||
ELLIPSIS_H('\uf141'),
|
ELLIPSIS_H('\uf141'),
|
||||||
EYE('\uf06e'),
|
EYE('\uf06e'),
|
||||||
|
FILE_CSV('\uf6dd'),
|
||||||
HAND_HOLDING('\uf4bd'),
|
HAND_HOLDING('\uf4bd'),
|
||||||
HAND_HOLDING_MEDICAL('\ue05c'),
|
HAND_HOLDING_MEDICAL('\ue05c'),
|
||||||
HISTORY('\uf1da'),
|
HISTORY('\uf1da'),
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.sparrowwallet.sparrow.wallet;
|
package com.sparrowwallet.sparrow.wallet;
|
||||||
|
|
||||||
|
import com.csvreader.CsvWriter;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import com.sparrowwallet.drongo.BitcoinUnit;
|
||||||
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.sparrow.AppServices;
|
import com.sparrowwallet.sparrow.AppServices;
|
||||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
|
@ -8,14 +11,26 @@ import com.sparrowwallet.sparrow.control.*;
|
||||||
import com.sparrowwallet.sparrow.event.*;
|
import com.sparrowwallet.sparrow.event.*;
|
||||||
import com.sparrowwallet.sparrow.net.ExchangeSource;
|
import com.sparrowwallet.sparrow.net.ExchangeSource;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TreeItem;
|
import javafx.scene.control.TreeItem;
|
||||||
|
import javafx.stage.FileChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class TransactionsController extends WalletFormController implements Initializable {
|
public class TransactionsController extends WalletFormController implements Initializable {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TransactionsController.class);
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CoinLabel balance;
|
private CoinLabel balance;
|
||||||
|
@ -38,6 +53,9 @@ public class TransactionsController extends WalletFormController implements Init
|
||||||
@FXML
|
@FXML
|
||||||
private BalanceChart balanceChart;
|
private BalanceChart balanceChart;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button exportCsv;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
EventManager.get().register(this);
|
EventManager.get().register(this);
|
||||||
|
@ -81,6 +99,41 @@ public class TransactionsController extends WalletFormController implements Init
|
||||||
transactionCount.setText(walletTransactionsEntry.getChildren() != null ? Integer.toString(walletTransactionsEntry.getChildren().size()) : "0");
|
transactionCount.setText(walletTransactionsEntry.getChildren() != null ? Integer.toString(walletTransactionsEntry.getChildren().size()) : "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void exportCSV(ActionEvent event) {
|
||||||
|
WalletTransactionsEntry walletTransactionsEntry = getWalletForm().getWalletTransactionsEntry();
|
||||||
|
|
||||||
|
Stage window = new Stage();
|
||||||
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
fileChooser.setTitle("Export Transactions as CSV");
|
||||||
|
fileChooser.setInitialFileName(getWalletForm().getWallet().getName() + ".csv");
|
||||||
|
|
||||||
|
File file = fileChooser.showSaveDialog(window);
|
||||||
|
if(file != null) {
|
||||||
|
try(FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||||
|
CsvWriter writer = new CsvWriter(outputStream, ',', StandardCharsets.UTF_8);
|
||||||
|
writer.writeRecord(new String[] {"Date", "Label", "Value", "Balance"});
|
||||||
|
for(Entry entry : walletTransactionsEntry.getChildren()) {
|
||||||
|
TransactionEntry txEntry = (TransactionEntry)entry;
|
||||||
|
writer.write(EntryCell.DATE_FORMAT.format(txEntry.getBlockTransaction().getDate()));
|
||||||
|
writer.write(txEntry.getLabel());
|
||||||
|
writer.write(getCoinValue(txEntry.getValue()));
|
||||||
|
writer.write(getCoinValue(txEntry.getBalance()));
|
||||||
|
writer.endRecord();
|
||||||
|
}
|
||||||
|
writer.close();
|
||||||
|
} catch(IOException e) {
|
||||||
|
log.error("Error exporting transactions as CSV", e);
|
||||||
|
AppServices.showErrorDialog("Error exporting transactions as CSV", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCoinValue(Long value) {
|
||||||
|
return BitcoinUnit.BTC.equals(transactionsTable.getBitcoinUnit()) ?
|
||||||
|
CoinLabel.getBTCFormat().format(value.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN) :
|
||||||
|
String.format(Locale.ENGLISH, "%d", value);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void walletNodesChanged(WalletNodesChangedEvent event) {
|
public void walletNodesChanged(WalletNodesChangedEvent event) {
|
||||||
if(event.getWallet().equals(walletForm.getWallet())) {
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
|
|
@ -27,4 +27,5 @@ open module com.sparrowwallet.sparrow {
|
||||||
requires slf4j.api;
|
requires slf4j.api;
|
||||||
requires bwt.jni;
|
requires bwt.jni;
|
||||||
requires jtorctl;
|
requires jtorctl;
|
||||||
|
requires javacsv;
|
||||||
}
|
}
|
|
@ -34,3 +34,8 @@
|
||||||
-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -20%), derive(-fx-text-box-border, -30%)), linear-gradient(to bottom, derive(#50a14f, 30%), #50a14f);
|
-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -20%), derive(-fx-text-box-border, -30%)), linear-gradient(to bottom, derive(#50a14f, 30%), #50a14f);
|
||||||
-fx-background-insets: 0, 1;
|
-fx-background-insets: 0, 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.public-server.toggle-switch:selected .thumb-area {
|
||||||
|
-fx-background-color: linear-gradient(to bottom, derive(-fx-text-box-border, -20%), derive(-fx-text-box-border, -30%)), linear-gradient(to bottom, derive(gold, 30%), gold);
|
||||||
|
-fx-background-insets: 0, 1;
|
||||||
|
}
|
|
@ -22,4 +22,16 @@
|
||||||
|
|
||||||
.chart-line-symbol.selected {
|
.chart-line-symbol.selected {
|
||||||
-fx-background-color: rgba(30, 136, 207, 0.6);
|
-fx-background-color: rgba(30, 136, 207, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
#exportCsv {
|
||||||
|
-fx-border-style: none;
|
||||||
|
-fx-border-width: 0;
|
||||||
|
-fx-border-insets: 0;
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
#exportCsv:hover {
|
||||||
|
-fx-opacity: 1.0;
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
|
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
|
||||||
<?import com.sparrowwallet.sparrow.control.FiatLabel?>
|
<?import com.sparrowwallet.sparrow.control.FiatLabel?>
|
||||||
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
|
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
|
||||||
|
<?import org.controlsfx.glyphfont.Glyph?>
|
||||||
|
|
||||||
<BorderPane stylesheets="@transactions.css, @wallet.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.TransactionsController">
|
<BorderPane stylesheets="@transactions.css, @wallet.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.TransactionsController">
|
||||||
<center>
|
<center>
|
||||||
|
@ -40,6 +41,11 @@
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Transactions:">
|
<Field text="Transactions:">
|
||||||
<CopyableLabel fx:id="transactionCount" />
|
<CopyableLabel fx:id="transactionCount" />
|
||||||
|
<Button fx:id="exportCsv" maxHeight="25" onAction="#exportCSV" translateY="-1">
|
||||||
|
<graphic>
|
||||||
|
<Glyph fontFamily="Font Awesome 5 Free Solid" icon="FILE_CSV" fontSize="14" />
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
</Field>
|
</Field>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
Loading…
Reference in a new issue