diff --git a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java index 50296fe5..6e77988b 100644 --- a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java @@ -914,16 +914,21 @@ public class XmrWalletService { return getNumTxOutputsForSubaddress(subaddressIndex, null); } - private int getNumTxOutputsForSubaddress(int subaddressIndex, List incomingTxs) { + public int getNumTxOutputsForSubaddress(int subaddressIndex, List incomingTxs) { if (incomingTxs == null) incomingTxs = getIncomingTxs(subaddressIndex); int numUnspentOutputs = 0; for (MoneroTxWallet tx : incomingTxs) { + if (tx.getTransfers(new MoneroTransferQuery().setSubaddressIndex(subaddressIndex)).isEmpty()) continue; numUnspentOutputs += tx.isConfirmed() ? tx.getOutputsWallet(new MoneroOutputQuery().setSubaddressIndex(subaddressIndex)).size() : 1; // TODO: monero-project does not provide outputs for unconfirmed txs } return numUnspentOutputs; } - private List getIncomingTxs(Integer subaddressIndex) { + public List getIncomingTxs() { + return getIncomingTxs(null); + } + + public List getIncomingTxs(Integer subaddressIndex) { return wallet.getTxs(new MoneroTxQuery() .setTransferQuery((new MoneroTransferQuery() .setAccountIndex(0) @@ -970,7 +975,7 @@ public class XmrWalletService { // TODO (woodser): update balance and other listening public void addBalanceListener(XmrBalanceListener listener) { - balanceListeners.add(listener); + if (!balanceListeners.contains(listener)) balanceListeners.add(listener); } public void removeBalanceListener(XmrBalanceListener listener) { 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 b25bb23a..e027581f 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 @@ -59,7 +59,7 @@ class DepositListItem { return lazyFieldsSupplier.get(); } - DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) { + DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter, List cachedTxs) { this.xmrWalletService = xmrWalletService; this.addressEntry = addressEntry; @@ -68,7 +68,7 @@ class DepositListItem { public void onBalanceChanged(BigInteger balance) { DepositListItem.this.balanceAsCoin = HavenoUtils.atomicUnitsToCoin(balance); DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin)); - updateUsage(addressEntry.getSubaddressIndex()); + updateUsage(addressEntry.getSubaddressIndex(), null); } }; xmrWalletService.addBalanceListener(balanceListener); @@ -76,7 +76,7 @@ class DepositListItem { balanceAsCoin = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex()); balance.set(formatter.formatCoin(balanceAsCoin)); - updateUsage(addressEntry.getSubaddressIndex()); + updateUsage(addressEntry.getSubaddressIndex(), cachedTxs); // confidence lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{ @@ -95,8 +95,8 @@ class DepositListItem { }}); } - private void updateUsage(int subaddressIndex) { - numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex()); + private void updateUsage(int subaddressIndex, List cachedTxs) { + numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex(), cachedTxs); usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs); } 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 c5328e48..bf6d3f6c 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 @@ -52,6 +52,7 @@ import net.glxn.qrgen.image.ImageType; import javax.inject.Inject; import javax.inject.Named; import monero.wallet.model.MoneroTxConfig; +import monero.wallet.model.MoneroTxWallet; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -83,6 +84,7 @@ import javafx.util.Callback; import java.io.ByteArrayInputStream; import java.math.BigInteger; import java.util.Comparator; +import java.util.List; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; @@ -298,8 +300,10 @@ public class DepositView extends ActivatableView { private void updateList() { observableList.forEach(DepositListItem::cleanup); observableList.clear(); + + List incomingTxs = xmrWalletService.getIncomingTxs(); // cache incoming txs for performance xmrWalletService.getAvailableAddressEntries() - .forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter))); + .forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter, incomingTxs))); } private Coin getAmountAsCoin() {