From 24a8ecea2bba1866983bfacbf5af1b3486c00725 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 31 Aug 2022 11:14:47 -0400 Subject: [PATCH] funds tab shows num confirmations per receive address --- .../main/funds/deposit/DepositListItem.java | 60 ++++++++++++++++++- .../main/funds/deposit/DepositView.java | 4 +- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositListItem.java b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositListItem.java index 97f7f4ceaa..96757b0a17 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositListItem.java @@ -23,10 +23,20 @@ import bisq.core.btc.wallet.XmrWalletService; import bisq.core.locale.Res; import bisq.core.util.ParsingUtils; import bisq.core.util.coin.CoinFormatter; +import bisq.desktop.components.indicator.TxConfidenceIndicator; +import bisq.desktop.util.GUIUtil; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import java.math.BigInteger; +import java.util.List; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.scene.control.Tooltip; import lombok.extern.slf4j.Slf4j; +import monero.daemon.model.MoneroTx; +import monero.wallet.model.MoneroTransferQuery; +import monero.wallet.model.MoneroTxQuery; +import monero.wallet.model.MoneroTxWallet; import org.bitcoinj.core.Coin; @Slf4j @@ -38,6 +48,16 @@ class DepositListItem { private String usage = "-"; private XmrBalanceListener balanceListener; private int numTxOutputs = 0; + private final Supplier lazyFieldsSupplier; + + private static class LazyFields { + TxConfidenceIndicator txConfidenceIndicator; + Tooltip tooltip; + } + + private LazyFields lazy() { + return lazyFieldsSupplier.get(); + } DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) { this.xmrWalletService = xmrWalletService; @@ -58,6 +78,22 @@ class DepositListItem { balance.set(formatter.formatCoin(balanceAsCoin)); updateUsage(addressEntry.getSubaddressIndex()); + + // confidence + lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{ + txConfidenceIndicator = new TxConfidenceIndicator(); + txConfidenceIndicator.setId("funds-confidence"); + tooltip = new Tooltip(Res.get("shared.notUsedYet")); + txConfidenceIndicator.setProgress(0); + txConfidenceIndicator.setTooltip(tooltip); + MoneroTx tx = getTxWithFewestConfirmations(); + if (tx == null) { + txConfidenceIndicator.setVisible(false); + } else { + GUIUtil.updateConfidence(tx, tooltip, txConfidenceIndicator); + txConfidenceIndicator.setVisible(true); + } + }}); } private void updateUsage(int subaddressIndex) { @@ -69,6 +105,10 @@ class DepositListItem { xmrWalletService.removeBalanceListener(balanceListener); } + public TxConfidenceIndicator getTxConfidenceIndicator() { + return lazy().txConfidenceIndicator; + } + public String getAddressString() { return addressEntry.getAddressString(); } @@ -93,7 +133,23 @@ class DepositListItem { return numTxOutputs; } - public int getNumConfirmationsSinceFirstUsed() { - throw new RuntimeException("Not implemented"); + public long getNumConfirmationsSinceFirstUsed() { + MoneroTx tx = getTxWithFewestConfirmations(); + return tx == null ? 0 : tx.getNumConfirmations(); + } + + private MoneroTxWallet getTxWithFewestConfirmations() { + + // get txs with incoming transfers to subaddress + List txs = xmrWalletService.getWallet() + .getTxs(new MoneroTxQuery() + .setTransferQuery(new MoneroTransferQuery() + .setIsIncoming(true) + .setSubaddressIndex(addressEntry.getSubaddressIndex()))); + + // get tx with fewest confirmations + MoneroTxWallet highestTx = null; + for (MoneroTxWallet tx : txs) if (highestTx == null || tx.getNumConfirmations() < highestTx.getNumConfirmations()) highestTx = tx; + return highestTx; } } diff --git a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java index 84cc710d15..9024bf6c80 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/deposit/DepositView.java @@ -155,7 +155,7 @@ public class DepositView extends ActivatableView { addressColumn.setComparator(Comparator.comparing(DepositListItem::getAddressString)); balanceColumn.setComparator(Comparator.comparing(DepositListItem::getBalanceAsCoin)); - confirmationsColumn.setComparator(Comparator.comparingInt(o -> o.getNumConfirmationsSinceFirstUsed())); + confirmationsColumn.setComparator(Comparator.comparingLong(o -> o.getNumConfirmationsSinceFirstUsed())); usageColumn.setComparator(Comparator.comparingInt(DepositListItem::getNumTxOutputs)); tableView.getSortOrder().add(usageColumn); tableView.setItems(sortedList); @@ -422,7 +422,7 @@ public class DepositView extends ActivatableView { super.updateItem(item, empty); if (item != null && !empty) { - //setGraphic(item.getTxConfidenceIndicator()); + setGraphic(item.getTxConfidenceIndicator()); } else { setGraphic(null); }