mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Call validatePayoutTx only after trades are initialized
This commit is contained in:
parent
677211badf
commit
08fb596629
@ -725,9 +725,19 @@ public abstract class Trade implements Tradable, Model {
|
||||
@Nullable
|
||||
public Transaction getDelayedPayoutTx() {
|
||||
if (delayedPayoutTx == null) {
|
||||
delayedPayoutTx = delayedPayoutTxBytes != null && processModel.getBtcWalletService() != null ?
|
||||
processModel.getBtcWalletService().getTxFromSerializedTx(delayedPayoutTxBytes) :
|
||||
null;
|
||||
BtcWalletService btcWalletService = processModel.getBtcWalletService();
|
||||
if (btcWalletService == null) {
|
||||
log.warn("btcWalletService is null. You might call that method before the tradeManager has " +
|
||||
"initialized all trades");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (delayedPayoutTxBytes == null) {
|
||||
log.warn("delayedPayoutTxBytes are null");
|
||||
return null;
|
||||
}
|
||||
|
||||
delayedPayoutTx = btcWalletService.getTxFromSerializedTx(delayedPayoutTxBytes);
|
||||
}
|
||||
return delayedPayoutTx;
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ public class TradeManager implements PersistedDataHost {
|
||||
|
||||
private final Storage<TradableList<Trade>> tradableListStorage;
|
||||
private TradableList<Trade> tradableList;
|
||||
@Getter
|
||||
private final BooleanProperty pendingTradesInitialized = new SimpleBooleanProperty();
|
||||
private List<Trade> tradesForStatistics;
|
||||
@Setter
|
||||
|
@ -24,7 +24,13 @@ import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.trade.DelayedPayoutTxValidation;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
||||
public class BuyerStep1View extends TradeStepView {
|
||||
private ChangeListener<Boolean> pendingTradesInitializedListener;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor, Initialisation
|
||||
@ -38,18 +44,18 @@ public class BuyerStep1View extends TradeStepView {
|
||||
public void activate() {
|
||||
super.activate();
|
||||
|
||||
try {
|
||||
DelayedPayoutTxValidation.validatePayoutTx(trade,
|
||||
trade.getDelayedPayoutTx(),
|
||||
model.dataModel.daoFacade,
|
||||
model.dataModel.btcWalletService);
|
||||
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
|
||||
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
|
||||
// trade manager after initPendingTrades which happens after activate might be called.
|
||||
} catch (DelayedPayoutTxValidation.ValidationException e) {
|
||||
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
|
||||
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
|
||||
}
|
||||
// We need to have the trades initialized before we can call validatePayoutTx.
|
||||
BooleanProperty pendingTradesInitialized = model.dataModel.tradeManager.getPendingTradesInitialized();
|
||||
if (pendingTradesInitialized.get()) {
|
||||
validatePayoutTx();
|
||||
} else {
|
||||
pendingTradesInitializedListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
validatePayoutTx();
|
||||
UserThread.execute(() -> pendingTradesInitialized.removeListener(pendingTradesInitializedListener));
|
||||
}
|
||||
};
|
||||
pendingTradesInitialized.addListener(pendingTradesInitializedListener);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +91,29 @@ public class BuyerStep1View extends TradeStepView {
|
||||
protected String getPeriodOverWarnText() {
|
||||
return Res.get("portfolio.pending.step1.openForDispute");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void validatePayoutTx() {
|
||||
try {
|
||||
DelayedPayoutTxValidation.validatePayoutTx(trade,
|
||||
trade.getDelayedPayoutTx(),
|
||||
model.dataModel.daoFacade,
|
||||
model.dataModel.btcWalletService);
|
||||
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
|
||||
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
|
||||
// trade manager after initPendingTrades which happens after activate might be called.
|
||||
log.error("");
|
||||
} catch (DelayedPayoutTxValidation.ValidationException e) {
|
||||
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
|
||||
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,6 +88,9 @@ import javafx.scene.layout.Priority;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.Subscription;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -104,6 +107,7 @@ public class BuyerStep2View extends TradeStepView {
|
||||
private BusyAnimation busyAnimation;
|
||||
private Subscription tradeStatePropertySubscription;
|
||||
private Timer timeoutTimer;
|
||||
private ChangeListener<Boolean> pendingTradesInitializedListener;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor, Initialisation
|
||||
@ -117,18 +121,18 @@ public class BuyerStep2View extends TradeStepView {
|
||||
public void activate() {
|
||||
super.activate();
|
||||
|
||||
try {
|
||||
DelayedPayoutTxValidation.validatePayoutTx(trade,
|
||||
trade.getDelayedPayoutTx(),
|
||||
model.dataModel.daoFacade,
|
||||
model.dataModel.btcWalletService);
|
||||
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
|
||||
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
|
||||
// trade manager after initPendingTrades which happens after activate might be called.
|
||||
} catch (DelayedPayoutTxValidation.ValidationException e) {
|
||||
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
|
||||
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
|
||||
}
|
||||
// We need to have the trades initialized before we can call validatePayoutTx.
|
||||
BooleanProperty pendingTradesInitialized = model.dataModel.tradeManager.getPendingTradesInitialized();
|
||||
if (pendingTradesInitialized.get()) {
|
||||
validatePayoutTx();
|
||||
} else {
|
||||
pendingTradesInitializedListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
validatePayoutTx();
|
||||
UserThread.execute(() -> pendingTradesInitialized.removeListener(pendingTradesInitializedListener));
|
||||
}
|
||||
};
|
||||
pendingTradesInitialized.addListener(pendingTradesInitializedListener);
|
||||
}
|
||||
|
||||
if (timeoutTimer != null)
|
||||
@ -629,6 +633,23 @@ public class BuyerStep2View extends TradeStepView {
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePayoutTx() {
|
||||
try {
|
||||
DelayedPayoutTxValidation.validatePayoutTx(trade,
|
||||
trade.getDelayedPayoutTx(),
|
||||
model.dataModel.daoFacade,
|
||||
model.dataModel.btcWalletService);
|
||||
} catch (DelayedPayoutTxValidation.MissingTxException ignore) {
|
||||
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
|
||||
// trade manager after initPendingTrades which happens after activate might be called.
|
||||
log.error("");
|
||||
} catch (DelayedPayoutTxValidation.ValidationException e) {
|
||||
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
|
||||
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateConfirmButtonDisableState(boolean isDisabled) {
|
||||
confirmButton.setDisable(isDisabled);
|
||||
|
Loading…
Reference in New Issue
Block a user