From c193385475d9ab0f07b1e9760a28334df24c8c15 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 9 Aug 2023 09:21:53 -0400 Subject: [PATCH] fix npe opening deposit view without monero connection #431 --- .../haveno/desktop/main/funds/deposit/DepositListItem.java | 6 +++++- .../java/haveno/desktop/main/funds/deposit/DepositView.java | 6 ++++-- desktop/src/main/java/haveno/desktop/util/GUIUtil.java | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositListItem.java b/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositListItem.java index f9725d7c82..c7de866dd9 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositListItem.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositListItem.java @@ -162,7 +162,11 @@ class DepositListItem { // get tx with fewest confirmations MoneroTxWallet highestTx = null; - for (MoneroTxWallet tx : txs) if (highestTx == null || tx.getNumConfirmations() < highestTx.getNumConfirmations()) highestTx = tx; + for (MoneroTxWallet tx : txs) { + if (highestTx == null || tx.getHeight() == null || (highestTx.getHeight() != null && tx.getHeight() > highestTx.getHeight())) { + highestTx = tx; + } + } return highestTx; } } diff --git a/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositView.java b/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositView.java index b68d7a764c..7958cb3e6c 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositView.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/deposit/DepositView.java @@ -318,12 +318,14 @@ public class DepositView extends ActivatableView { /////////////////////////////////////////////////////////////////////////////////////////// private void updateList() { - observableList.forEach(DepositListItem::cleanup); - observableList.clear(); // cache incoming txs txsWithIncomingOutputs = xmrWalletService.getTxsWithIncomingOutputs(); + // clear existing items + observableList.forEach(DepositListItem::cleanup); + observableList.clear(); + // add address entries xmrWalletService.getAddressEntries() .forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter, txsWithIncomingOutputs))); diff --git a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java index 8e9d75fdc2..f4440eec6f 100644 --- a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java @@ -528,7 +528,7 @@ public class GUIUtil { public static void updateConfidence(MoneroTx tx, Tooltip tooltip, TxConfidenceIndicator txConfidenceIndicator) { - if (tx != null && !tx.isRelayed()) { + if (tx != null && (tx.getNumConfirmations() == null || !tx.isRelayed())) { tooltip.setText(Res.get("confidence.unknown")); txConfidenceIndicator.setProgress(0); } else if (tx != null && tx.isFailed()) {