prevent trade mixup in ui by synchronizing trade and state events

This commit is contained in:
woodser 2023-04-28 14:16:16 -04:00
parent 6b105f80cf
commit 6e901c9852

View file

@ -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,6 +147,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
@Override
protected void deactivate() {
synchronized (this) {
if (tradeStateSubscription != null) {
tradeStateSubscription.unsubscribe();
tradeStateSubscription = null;
@ -163,9 +163,11 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
messageStateSubscription = null;
}
}
}
// Don't set own listener as we need to control the order of the calls
public void onSelectedItemChanged(PendingTradesListItem selectedItem) {
synchronized (this) {
if (tradeStateSubscription != null) {
tradeStateSubscription.unsubscribe();
sellerState.set(SellerState.UNDEFINED);
@ -186,17 +188,18 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
if (selectedItem != null) {
this.trade = selectedItem.getTrade();
tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), state -> {
UserThread.execute(() -> onTradeStateChanged(state));
onTradeStateChanged(state);
});
payoutStateSubscription = EasyBind.subscribe(trade.payoutStateProperty(), state -> {
UserThread.execute(() -> onPayoutStateChanged(state));
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. " +