From 2b9d0ef5a6c1633a29e4199aa85a4295401f5e84 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 11 Jan 2024 10:22:38 -0500 Subject: [PATCH] fix payment sent message state property after improper shut down --- .../main/java/haveno/core/trade/Trade.java | 26 +++++++++++++++++++ .../core/trade/protocol/TradeProtocol.java | 2 +- .../pendingtrades/PendingTradesViewModel.java | 6 ++--- .../steps/buyer/BuyerStep2View.java | 11 ++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 591de631b9..bc49739444 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -32,6 +32,7 @@ import haveno.common.util.Utilities; import haveno.core.api.XmrConnectionService; import haveno.core.monetary.Price; import haveno.core.monetary.Volume; +import haveno.core.network.MessageState; import haveno.core.offer.Offer; import haveno.core.offer.OfferDirection; import haveno.core.payment.payload.PaymentAccountPayload; @@ -693,6 +694,13 @@ public abstract class Trade implements Tradable, Model { xmrWalletService.addWalletListener(idlePayoutSyncer); } + // TODO: trader's payment sent message state property can become unsynced (after improper shut down?) + MessageState expectedState = getPaymentSentMessageState(); + if (!isArbitrator() && expectedState != null && expectedState != processModel.getPaymentSentMessageStateProperty().get()) { + log.warn("Updating unexpected payment sent message state for {} {}, expected={}, actual={}", getClass().getSimpleName(), getId(), expectedState, processModel.getPaymentSentMessageStateProperty().get()); + processModel.getPaymentSentMessageStateProperty().set(expectedState); + } + // trade is initialized isInitialized = true; @@ -1569,6 +1577,24 @@ public abstract class Trade implements Tradable, Model { throw new IllegalArgumentException("Trade is not buyer, seller, or arbitrator"); } + public MessageState getPaymentSentMessageState() { + if (isPaymentReceived()) return MessageState.ACKNOWLEDGED; + if (processModel.getPaymentSentMessageStateProperty().get() == MessageState.ACKNOWLEDGED) return MessageState.ACKNOWLEDGED; + switch (state) { + case BUYER_SENT_PAYMENT_SENT_MSG: + case BUYER_SAW_ARRIVED_PAYMENT_SENT_MSG: + return MessageState.SENT; + case BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG: + return MessageState.STORED_IN_MAILBOX; + case SELLER_RECEIVED_PAYMENT_SENT_MSG: + return MessageState.ARRIVED; + case BUYER_SEND_FAILED_PAYMENT_SENT_MSG: + return MessageState.FAILED; + default: + return null; + } + } + public String getPeerRole(TradePeer peer) { if (peer == getBuyer()) return "Buyer"; if (peer == getSeller()) return "Seller"; diff --git a/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java b/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java index f04f9f1fb4..446215cbfa 100644 --- a/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java @@ -770,7 +770,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D trade.setMyNodeAddress(); // TODO: this is a hack to update my node address before verifying the message TradePeer peer = trade.getTradePeer(address); if (peer == null) { - log.warn("Cannot get peer's pub key ring because peer is not maker, taker, or arbitrator. Their address might have changed: " + peer); + log.warn("Cannot get peer's pub key ring because peer is not maker, taker, or arbitrator. Their address might have changed: " + address); return null; } return peer.getPubKeyRing(); diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index 1cddb827d4..73db3c3541 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -191,14 +191,12 @@ public class PendingTradesViewModel extends ActivatableWithDataModel { busyAnimation.stop(); statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); @@ -167,25 +166,25 @@ public class BuyerStep2View extends TradeStepView { case BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG: busyAnimation.stop(); statusLabel.setText(Res.get("shared.messageStoredInMailbox")); - model.setMessageStateProperty(MessageState.STORED_IN_MAILBOX); + model.setMessageStateProperty(trade.getPaymentSentMessageState()); break; case SELLER_RECEIVED_PAYMENT_SENT_MSG: busyAnimation.stop(); statusLabel.setText(Res.get("shared.messageArrived")); - model.setMessageStateProperty(MessageState.ARRIVED); + model.setMessageStateProperty(trade.getPaymentSentMessageState()); break; case BUYER_SEND_FAILED_PAYMENT_SENT_MSG: // We get a popup and the trade closed, so we dont need to show anything here busyAnimation.stop(); statusLabel.setText(""); - model.setMessageStateProperty(MessageState.FAILED); + model.setMessageStateProperty(trade.getPaymentSentMessageState()); break; default: log.warn("Unexpected case: State={}, tradeId={} ", state.name(), trade.getId()); busyAnimation.stop(); statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); break; - } + } } }); }