From 1329902a553455efd6771b73760684e61e7bfbf9 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 25 Sep 2024 11:34:12 -0400 Subject: [PATCH] add transaction fee column to funds > transactions Co-authored-by: niyid --- .../transactions/TransactionsListItem.java | 10 +++++ .../funds/transactions/TransactionsView.fxml | 3 +- .../funds/transactions/TransactionsView.java | 42 ++++++++++++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java index c9ef1d6cfe..f0baf8c922 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java @@ -54,6 +54,7 @@ class TransactionsListItem { private boolean received; private boolean detailsAvailable; private BigInteger amount = BigInteger.ZERO; + private BigInteger txFee = BigInteger.ZERO; private String memo = ""; private long confirmations = 0; @Getter @@ -107,6 +108,7 @@ class TransactionsListItem { amount = valueSentFromMe.multiply(BigInteger.valueOf(-1)); received = false; direction = Res.get("funds.tx.direction.sentTo"); + txFee = tx.getFee().multiply(BigInteger.valueOf(-1)); } if (optionalTradable.isPresent()) { @@ -201,6 +203,14 @@ class TransactionsListItem { return amount; } + public BigInteger getTxFee() { + return txFee; + } + + public String getTxFeeStr() { + return txFee.equals(BigInteger.ZERO) ? "" : HavenoUtils.formatXmr(txFee); + } + public String getAddressString() { return addressString; } diff --git a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.fxml b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.fxml index 8cd53a17e3..7c5da97808 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.fxml +++ b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.fxml @@ -36,7 +36,8 @@ - + + diff --git a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.java b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.java index f5cca952d6..44fdab6bc0 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsView.java @@ -70,7 +70,7 @@ public class TransactionsView extends ActivatableView { @FXML TableView tableView; @FXML - TableColumn dateColumn, detailsColumn, addressColumn, transactionColumn, amountColumn, memoColumn, confidenceColumn, revertTxColumn; + TableColumn dateColumn, detailsColumn, addressColumn, transactionColumn, amountColumn, txFeeColumn, memoColumn, confidenceColumn, revertTxColumn; @FXML Label numItems; @FXML @@ -89,7 +89,7 @@ public class TransactionsView extends ActivatableView { private EventHandler keyEventEventHandler; private Scene scene; - private TransactionsUpdater transactionsUpdater = new TransactionsUpdater(); + private final TransactionsUpdater transactionsUpdater = new TransactionsUpdater(); private class TransactionsUpdater extends MoneroWalletListener { @Override @@ -129,11 +129,12 @@ public class TransactionsView extends ActivatableView { addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address"))); transactionColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.txId", Res.getBaseCurrencyCode()))); amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode()))); + txFeeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.txFee", Res.getBaseCurrencyCode()))); memoColumn.setGraphic(new AutoTooltipLabel(Res.get("funds.tx.memo"))); confidenceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.confirmations", Res.getBaseCurrencyCode()))); revertTxColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.revert", Res.getBaseCurrencyCode()))); - tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN); tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.tx.noTxAvailable"))); setDateColumnCellFactory(); @@ -141,6 +142,7 @@ public class TransactionsView extends ActivatableView { setAddressColumnCellFactory(); setTransactionColumnCellFactory(); setAmountColumnCellFactory(); + setTxFeeColumnCellFactory(); setMemoColumnCellFactory(); setConfidenceColumnCellFactory(); setRevertTxColumnCellFactory(); @@ -156,7 +158,7 @@ public class TransactionsView extends ActivatableView { addressColumn.setComparator(Comparator.comparing(item -> item.getDirection() + item.getAddressString())); transactionColumn.setComparator(Comparator.comparing(TransactionsListItem::getTxId)); amountColumn.setComparator(Comparator.comparing(TransactionsListItem::getAmount)); - confidenceColumn.setComparator(Comparator.comparingLong(item -> item.getNumConfirmations())); + confidenceColumn.setComparator(Comparator.comparingLong(TransactionsListItem::getNumConfirmations)); memoColumn.setComparator(Comparator.comparing(TransactionsListItem::getMemo)); dateColumn.setSortType(TableColumn.SortType.DESCENDING); @@ -216,8 +218,9 @@ public class TransactionsView extends ActivatableView { columns[2] = item.getDirection() + " " + item.getAddressString(); columns[3] = item.getTxId(); columns[4] = item.getAmountStr(); - columns[5] = item.getMemo() == null ? "" : item.getMemo(); - columns[6] = String.valueOf(item.getNumConfirmations()); + columns[5] = item.getTxFeeStr(); + columns[6] = item.getMemo() == null ? "" : item.getMemo(); + columns[7] = String.valueOf(item.getNumConfirmations()); return columns; }; @@ -414,6 +417,33 @@ public class TransactionsView extends ActivatableView { }); } + + private void setTxFeeColumnCellFactory() { + txFeeColumn.setCellValueFactory((addressListItem) -> + new ReadOnlyObjectWrapper<>(addressListItem.getValue())); + txFeeColumn.setCellFactory( + new Callback<>() { + + @Override + public TableCell call(TableColumn column) { + return new TableCell<>() { + + @Override + public void updateItem(final TransactionsListItem item, boolean empty) { + super.updateItem(item, empty); + + if (item != null && !empty) { + setGraphic(new AutoTooltipLabel(item.getTxFeeStr())); + } else { + setGraphic(null); + } + } + }; + } + }); + } + private void setMemoColumnCellFactory() { memoColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));