Skip to content

Commit edca409

Browse files
committed
reset trade state after first poll if necessary
1 parent 90c77cc commit edca409

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

core/src/main/java/haveno/core/trade/Trade.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@
7474
import haveno.network.p2p.NodeAddress;
7575
import haveno.network.p2p.P2PService;
7676
import haveno.network.p2p.network.TorNetworkNode;
77+
import javafx.beans.property.BooleanProperty;
7778
import javafx.beans.property.DoubleProperty;
7879
import javafx.beans.property.IntegerProperty;
7980
import javafx.beans.property.ObjectProperty;
8081
import javafx.beans.property.ReadOnlyDoubleProperty;
8182
import javafx.beans.property.ReadOnlyObjectProperty;
8283
import javafx.beans.property.ReadOnlyStringProperty;
84+
import javafx.beans.property.SimpleBooleanProperty;
8385
import javafx.beans.property.SimpleDoubleProperty;
8486
import javafx.beans.property.SimpleIntegerProperty;
8587
import javafx.beans.property.SimpleObjectProperty;
@@ -153,6 +155,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
153155
private Subscription protocolErrorStateSubscription;
154156
private Subscription protocolErrorHeightSubscription;
155157
public static final String PROTOCOL_VERSION = "protocolVersion"; // key for extraDataMap in trade statistics
158+
private BooleanProperty wasWalletPolled = new SimpleBooleanProperty(false);
156159

157160
///////////////////////////////////////////////////////////////////////////////////////////
158161
// Enums
@@ -639,21 +642,23 @@ public void initialize(ProcessModelServiceProvider serviceProvider) {
639642
ThreadUtils.execute(() -> onConnectionChanged(connection), getId());
640643
});
641644

642-
// reset states if no ack receive
643-
if (!isPayoutPublished()) {
645+
// reset state after first poll if necessary
646+
wasWalletPolled.addListener((observable, oldValue, newValue) -> {
647+
if (!isPayoutPublished()) {
644648

645-
// reset buyer's payment sent state if no ack receive
646-
if (this instanceof BuyerTrade && getState().ordinal() >= Trade.State.BUYER_CONFIRMED_PAYMENT_SENT.ordinal() && getState().ordinal() < Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG.ordinal()) {
647-
log.warn("Resetting state of {} {} from {} to {} because no ack was received", getClass().getSimpleName(), getId(), getState(), Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
648-
setState(Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
649-
}
650-
651-
// reset seller's payment received state if no ack receive
652-
if (this instanceof SellerTrade && getState().ordinal() >= Trade.State.SELLER_CONFIRMED_PAYMENT_RECEIPT.ordinal() && getState().ordinal() < Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG.ordinal()) {
653-
log.warn("Resetting state of {} {} from {} to {} because no ack was received", getClass().getSimpleName(), getId(), getState(), Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
654-
resetToPaymentSentState();
655-
}
656-
}
649+
// reset buyer's payment sent state if no ack received
650+
if (this instanceof BuyerTrade && getState().ordinal() >= Trade.State.BUYER_CONFIRMED_PAYMENT_SENT.ordinal() && getState().ordinal() < Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG.ordinal() && getState() != Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG) {
651+
log.warn("Resetting state of {} {} from {} to {} because payout is not published", getClass().getSimpleName(), getId(), getState(), Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
652+
setState(Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
653+
}
654+
655+
// reset seller's payment received state unless stored in mailbox
656+
if (this instanceof SellerTrade && getState().ordinal() >= Trade.State.SELLER_CONFIRMED_PAYMENT_RECEIPT.ordinal() && getState().ordinal() != Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG.ordinal()) {
657+
log.warn("Resetting state of {} {} from {} to {} because payout is not published", getClass().getSimpleName(), getId(), getState(), Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
658+
resetToPaymentSentState();
659+
}
660+
};
661+
});
657662

658663
// handle trade state events
659664
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
@@ -2840,6 +2845,7 @@ else if (hasFailedTx && isPayoutPublished()) {
28402845
pollInProgress = false;
28412846
}
28422847
}
2848+
wasWalletPolled.set(true);
28432849
saveWalletWithDelay();
28442850
}
28452851
}

0 commit comments

Comments
 (0)