mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-06 21:13:59 -04:00
Fix bugs with availability check
This commit is contained in:
parent
700c58071c
commit
afd52b5948
@ -47,6 +47,7 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.HPos;
|
||||
@ -96,6 +97,8 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
private final OverlayManager overlayManager;
|
||||
private TradeView.CloseHandler closeHandler;
|
||||
|
||||
private ChangeListener<String> errorMessageChangeListener;
|
||||
|
||||
@Inject
|
||||
private TakeOfferView(TakeOfferViewModel model, Navigation navigation,
|
||||
OverlayManager overlayManager) {
|
||||
@ -113,6 +116,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
|
||||
@Override
|
||||
protected void doDeactivate() {
|
||||
model.errorMessage.removeListener(errorMessageChangeListener);
|
||||
}
|
||||
|
||||
public void initWithData(Direction direction, Coin amount, Offer offer) {
|
||||
@ -229,14 +233,14 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
model.errorMessage.addListener((o, oldValue, newValue) -> {
|
||||
errorMessageChangeListener = (o, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
Popups.openErrorPopup(BSResources.get("shared.error"), BSResources.get("takeOffer.error.message", model.errorMessage.get()));
|
||||
Popups.removeBlurContent();
|
||||
Platform.runLater(this::close);
|
||||
}
|
||||
});
|
||||
};
|
||||
model.errorMessage.addListener(errorMessageChangeListener);
|
||||
|
||||
model.showTransactionPublishedScreen.addListener((o, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
@ -294,7 +298,6 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void showCheckAvailabilityScreen() {
|
||||
|
||||
}
|
||||
|
@ -146,62 +146,62 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
||||
bankAccountCurrency = BSResources.get(offer.getCurrency().getDisplayName());
|
||||
bankAccountCounty = BSResources.get(offer.getBankAccountCountry().getName());
|
||||
|
||||
offer.stateProperty().addListener((ov, oldValue, newValue) -> {
|
||||
log.debug("offer state = " + newValue);
|
||||
offer.stateProperty().addListener((ov, oldValue, newValue) -> applyOfferState(newValue));
|
||||
applyOfferState(offer.stateProperty().get());
|
||||
}
|
||||
|
||||
switch (newValue) {
|
||||
case UNKNOWN:
|
||||
log.error("Must not happen.");
|
||||
break;
|
||||
case AVAILABLE:
|
||||
state.set(State.AMOUNT_SCREEN);
|
||||
break;
|
||||
case RESERVED:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed because offer is not available anymore. " +
|
||||
"Maybe another trader has taken the offer in the meantime.");
|
||||
else
|
||||
errorMessage.set("You cannot take that offer because the offer was already taken by another trader.");
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case REMOVED:
|
||||
if (!takeOfferRequested)
|
||||
errorMessage.set("You cannot take that offer because the offer has been removed in the meantime.");
|
||||
private void applyOfferState(Offer.State state) {
|
||||
log.debug("offer state = " + state);
|
||||
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case OFFERER_OFFLINE:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed because offerer is not online anymore.");
|
||||
else
|
||||
errorMessage.set("You cannot take that offer because the offerer is offline.");
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case FAULT:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed.");
|
||||
else
|
||||
errorMessage.set("The check for the offer availability failed.");
|
||||
switch (state) {
|
||||
case UNKNOWN:
|
||||
log.error("Must not happen.");
|
||||
break;
|
||||
case AVAILABLE:
|
||||
this.state.set(State.AMOUNT_SCREEN);
|
||||
break;
|
||||
case RESERVED:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed because offer is not available anymore. " +
|
||||
"Maybe another trader has taken the offer in the meantime.");
|
||||
else
|
||||
errorMessage.set("You cannot take that offer because the offer was already taken by another trader.");
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case REMOVED:
|
||||
if (!takeOfferRequested)
|
||||
errorMessage.set("You cannot take that offer because the offer has been removed in the meantime.");
|
||||
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
default:
|
||||
log.error("Unhandled offer state: " + newValue);
|
||||
break;
|
||||
}
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case OFFERER_OFFLINE:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed because offerer is not online anymore.");
|
||||
else
|
||||
errorMessage.set("You cannot take that offer because the offerer is offline.");
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
case FAULT:
|
||||
if (takeOfferRequested)
|
||||
errorMessage.set("Take offer request failed.");
|
||||
else
|
||||
errorMessage.set("The check for the offer availability failed.");
|
||||
|
||||
if (errorMessage.get() != null) {
|
||||
isTakeOfferSpinnerVisible.set(false);
|
||||
}
|
||||
takeOfferRequested = false;
|
||||
break;
|
||||
default:
|
||||
log.error("Unhandled offer state: " + state);
|
||||
break;
|
||||
}
|
||||
|
||||
evaluateState();
|
||||
});
|
||||
if (errorMessage.get() != null) {
|
||||
isTakeOfferSpinnerVisible.set(false);
|
||||
}
|
||||
|
||||
evaluateState();
|
||||
}
|
||||
|
||||
void takeOffer() {
|
||||
errorMessage.set(null);
|
||||
takeOfferRequested = true;
|
||||
applyTakeOfferRequestResult(false);
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class Offer implements Serializable {
|
||||
// Mutable property. Has to be set before offer is save in DHT as it changes the objects hash!
|
||||
private String offerFeePaymentTxID;
|
||||
private State state;
|
||||
|
||||
|
||||
// Those state properties are transient and only used at runtime!
|
||||
// don't access directly as it might be null; use getStateProperty() which creates an object if not instantiated
|
||||
private transient ObjectProperty<State> stateProperty;
|
||||
@ -124,8 +124,7 @@ public class Offer implements Serializable {
|
||||
this.acceptedLanguageLocales = acceptedLanguageLocales;
|
||||
|
||||
creationDate = new Date();
|
||||
state = State.UNKNOWN;
|
||||
stateProperty().set(state);
|
||||
setState(State.UNKNOWN);
|
||||
}
|
||||
|
||||
|
||||
@ -231,9 +230,6 @@ public class Offer implements Serializable {
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
if (state == null)
|
||||
setState(State.UNKNOWN);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -136,6 +136,7 @@ public class TradeManager {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void checkOfferAvailability(Offer offer) {
|
||||
offer.setState(Offer.State.UNKNOWN);
|
||||
if (!checkOfferAvailabilityProtocolMap.containsKey(offer.getId())) {
|
||||
CheckOfferAvailabilityModel model = new CheckOfferAvailabilityModel(
|
||||
offer,
|
||||
@ -202,10 +203,7 @@ public class TradeManager {
|
||||
}
|
||||
|
||||
public void requestTakeOffer(Coin amount, Offer offer, TradeResultHandler tradeResultHandler) {
|
||||
CheckOfferAvailabilityModel model = new CheckOfferAvailabilityModel(
|
||||
offer,
|
||||
tradeMessageService);
|
||||
|
||||
CheckOfferAvailabilityModel model = new CheckOfferAvailabilityModel(offer, tradeMessageService);
|
||||
CheckOfferAvailabilityProtocol protocol = new CheckOfferAvailabilityProtocol(model,
|
||||
() -> {
|
||||
disposeCheckOfferAvailabilityRequest(offer);
|
||||
@ -293,7 +291,7 @@ public class TradeManager {
|
||||
// Process new tradeMessages
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Routes the incoming messages to the responsible protocol
|
||||
// Offerer handles those requests
|
||||
private void handleMessage(Message message, Peer sender) {
|
||||
if (message instanceof RequestIsOfferAvailableMessage) {
|
||||
String offerId = ((RequestIsOfferAvailableMessage) message).getOfferId();
|
||||
|
Loading…
x
Reference in New Issue
Block a user