Skip to content

Commit

Permalink
add transaction fee column to funds > transactions
Browse files Browse the repository at this point in the history
Co-authored-by: niyid <[email protected]>
  • Loading branch information
woodser and niyid committed Sep 26, 2024
1 parent 6c640dd commit 1329902
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,6 +108,7 @@ private LazyFields lazy() {
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()) {
Expand Down Expand Up @@ -201,6 +203,14 @@ public BigInteger getAmount() {
return amount;
}

public BigInteger getTxFee() {
return txFee;
}

public String getTxFeeStr() {
return txFee.equals(BigInteger.ZERO) ? "" : HavenoUtils.formatXmr(txFee);
}

public String getAddressString() {
return addressString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<TableColumn fx:id="detailsColumn" minWidth="220" maxWidth="220"/>
<TableColumn fx:id="addressColumn" minWidth="260"/>
<TableColumn fx:id="transactionColumn" minWidth="180"/>
<TableColumn fx:id="amountColumn" minWidth="130" maxWidth="130"/>
<TableColumn fx:id="amountColumn" minWidth="110" maxWidth="110"/>
<TableColumn fx:id="txFeeColumn" minWidth="110" maxWidth="110"/>
<TableColumn fx:id="memoColumn" minWidth="40"/>
<TableColumn fx:id="confidenceColumn" minWidth="120" maxWidth="130"/>
<TableColumn fx:id="revertTxColumn" sortable="false" minWidth="110" maxWidth="110" visible="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class TransactionsView extends ActivatableView<VBox, Void> {
@FXML
TableView<TransactionsListItem> tableView;
@FXML
TableColumn<TransactionsListItem, TransactionsListItem> dateColumn, detailsColumn, addressColumn, transactionColumn, amountColumn, memoColumn, confidenceColumn, revertTxColumn;
TableColumn<TransactionsListItem, TransactionsListItem> dateColumn, detailsColumn, addressColumn, transactionColumn, amountColumn, txFeeColumn, memoColumn, confidenceColumn, revertTxColumn;
@FXML
Label numItems;
@FXML
Expand All @@ -89,7 +89,7 @@ public class TransactionsView extends ActivatableView<VBox, Void> {
private EventHandler<KeyEvent> keyEventEventHandler;
private Scene scene;

private TransactionsUpdater transactionsUpdater = new TransactionsUpdater();
private final TransactionsUpdater transactionsUpdater = new TransactionsUpdater();

private class TransactionsUpdater extends MoneroWalletListener {
@Override
Expand Down Expand Up @@ -129,18 +129,20 @@ public void initialize() {
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();
setDetailsColumnCellFactory();
setAddressColumnCellFactory();
setTransactionColumnCellFactory();
setAmountColumnCellFactory();
setTxFeeColumnCellFactory();
setMemoColumnCellFactory();
setConfidenceColumnCellFactory();
setRevertTxColumnCellFactory();
Expand All @@ -156,7 +158,7 @@ public void initialize() {
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);
Expand Down Expand Up @@ -216,8 +218,9 @@ protected void activate() {
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;
};

Expand Down Expand Up @@ -414,6 +417,33 @@ public void updateItem(final TransactionsListItem item, boolean empty) {
});
}


private void setTxFeeColumnCellFactory() {
txFeeColumn.setCellValueFactory((addressListItem) ->
new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
txFeeColumn.setCellFactory(
new Callback<>() {

@Override
public TableCell<TransactionsListItem, TransactionsListItem> call(TableColumn<TransactionsListItem,
TransactionsListItem> 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()));
Expand Down

0 comments on commit 1329902

Please sign in to comment.