mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-12 09:31:15 +00:00
prevent trade mixup in ui by synchronizing trade and state events
This commit is contained in:
parent
6b105f80cf
commit
6e901c9852
1 changed files with 43 additions and 40 deletions
|
@ -19,7 +19,6 @@ package haveno.desktop.main.portfolio.pendingtrades;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import haveno.common.ClockWatcher;
|
import haveno.common.ClockWatcher;
|
||||||
import haveno.common.UserThread;
|
|
||||||
import haveno.common.app.DevEnv;
|
import haveno.common.app.DevEnv;
|
||||||
import haveno.core.account.witness.AccountAgeWitnessService;
|
import haveno.core.account.witness.AccountAgeWitnessService;
|
||||||
import haveno.core.network.MessageState;
|
import haveno.core.network.MessageState;
|
||||||
|
@ -148,55 +147,59 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deactivate() {
|
protected void deactivate() {
|
||||||
if (tradeStateSubscription != null) {
|
synchronized (this) {
|
||||||
tradeStateSubscription.unsubscribe();
|
if (tradeStateSubscription != null) {
|
||||||
tradeStateSubscription = null;
|
tradeStateSubscription.unsubscribe();
|
||||||
}
|
tradeStateSubscription = null;
|
||||||
|
}
|
||||||
if (payoutStateSubscription != null) {
|
|
||||||
payoutStateSubscription.unsubscribe();
|
if (payoutStateSubscription != null) {
|
||||||
payoutStateSubscription = null;
|
payoutStateSubscription.unsubscribe();
|
||||||
}
|
payoutStateSubscription = null;
|
||||||
|
}
|
||||||
if (messageStateSubscription != null) {
|
|
||||||
messageStateSubscription.unsubscribe();
|
if (messageStateSubscription != null) {
|
||||||
messageStateSubscription = null;
|
messageStateSubscription.unsubscribe();
|
||||||
|
messageStateSubscription = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't set own listener as we need to control the order of the calls
|
// Don't set own listener as we need to control the order of the calls
|
||||||
public void onSelectedItemChanged(PendingTradesListItem selectedItem) {
|
public void onSelectedItemChanged(PendingTradesListItem selectedItem) {
|
||||||
if (tradeStateSubscription != null) {
|
synchronized (this) {
|
||||||
tradeStateSubscription.unsubscribe();
|
if (tradeStateSubscription != null) {
|
||||||
sellerState.set(SellerState.UNDEFINED);
|
tradeStateSubscription.unsubscribe();
|
||||||
buyerState.set(BuyerState.UNDEFINED);
|
sellerState.set(SellerState.UNDEFINED);
|
||||||
}
|
buyerState.set(BuyerState.UNDEFINED);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 -> {
|
||||||
|
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) {
|
public void setMessageStateProperty(MessageState messageState) {
|
||||||
|
|
||||||
// ARRIVED is set internally after ACKNOWLEDGED, otherwise warn if subsequent states received
|
// ARRIVED is set internally after ACKNOWLEDGED, otherwise warn if subsequent states received
|
||||||
if ((messageStateProperty.get() == MessageState.ACKNOWLEDGED && messageState != MessageState.ARRIVED) || messageStateProperty.get() == MessageState.ARRIVED) {
|
if ((messageStateProperty.get() == MessageState.ACKNOWLEDGED && messageState != MessageState.ARRIVED) || messageStateProperty.get() == MessageState.ARRIVED) {
|
||||||
log.warn("We have already an ACKNOWLEDGED/ARRIVED message received. " +
|
log.warn("We have already an ACKNOWLEDGED/ARRIVED message received. " +
|
||||||
|
|
Loading…
Reference in a new issue