From 6e901c9852f9aca9efdf1a9a0eaeb7ed01ce551a Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 28 Apr 2023 14:16:16 -0400 Subject: [PATCH] prevent trade mixup in ui by synchronizing trade and state events --- .../pendingtrades/PendingTradesViewModel.java | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) 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 5fb8db9316..e07dd2fdea 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 @@ -19,7 +19,6 @@ package haveno.desktop.main.portfolio.pendingtrades; import com.google.inject.Inject; import haveno.common.ClockWatcher; -import haveno.common.UserThread; import haveno.common.app.DevEnv; import haveno.core.account.witness.AccountAgeWitnessService; import haveno.core.network.MessageState; @@ -148,55 +147,59 @@ public class PendingTradesViewModel extends ActivatableWithDataModel { + onTradeStateChanged(state); + }); + payoutStateSubscription = EasyBind.subscribe(trade.payoutStateProperty(), state -> { + onPayoutStateChanged(state); + }); + messageStateSubscription = EasyBind.subscribe(trade.getProcessModel().getPaymentSentMessageStateProperty(), this::onMessageStateChanged); + } - if (payoutStateSubscription != null) { - payoutStateSubscription.unsubscribe(); - sellerState.set(SellerState.UNDEFINED); - buyerState.set(BuyerState.UNDEFINED); - } - - if (messageStateSubscription != null) { - messageStateSubscription.unsubscribe(); - messageStateProperty.set(MessageState.UNDEFINED); - } - - if (selectedItem != null) { - this.trade = selectedItem.getTrade(); - tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), state -> { - UserThread.execute(() -> onTradeStateChanged(state)); - }); - payoutStateSubscription = EasyBind.subscribe(trade.payoutStateProperty(), state -> { - UserThread.execute(() -> onPayoutStateChanged(state)); - }); - messageStateSubscription = EasyBind.subscribe(trade.getProcessModel().getPaymentSentMessageStateProperty(), this::onMessageStateChanged); } } public void setMessageStateProperty(MessageState messageState) { - // ARRIVED is set internally after ACKNOWLEDGED, otherwise warn if subsequent states received if ((messageStateProperty.get() == MessageState.ACKNOWLEDGED && messageState != MessageState.ARRIVED) || messageStateProperty.get() == MessageState.ARRIVED) { log.warn("We have already an ACKNOWLEDGED/ARRIVED message received. " +