mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-01 10:38:17 -04:00
allow offer trigger price outside of current price
This commit is contained in:
parent
290a3738b7
commit
f675588a2d
@ -595,6 +595,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
offerBookService.activateOffer(offer,
|
||||
() -> {
|
||||
openOffer.setState(OpenOffer.State.AVAILABLE);
|
||||
applyTriggerState(openOffer);
|
||||
requestPersistence();
|
||||
log.debug("activateOpenOffer, offerId={}", offer.getId());
|
||||
resultHandler.handleResult();
|
||||
@ -603,6 +604,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
}
|
||||
}
|
||||
|
||||
private void applyTriggerState(OpenOffer openOffer) {
|
||||
if (openOffer.getState() != OpenOffer.State.AVAILABLE) return;
|
||||
if (TriggerPriceService.isTriggered(priceFeedService.getMarketPrice(openOffer.getOffer().getCurrencyCode()), openOffer)) {
|
||||
openOffer.deactivate(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivateOpenOffer(OpenOffer openOffer,
|
||||
boolean deactivatedByTrigger,
|
||||
ResultHandler resultHandler,
|
||||
@ -688,7 +696,12 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
removeOpenOffer(openOffer);
|
||||
|
||||
OpenOffer editedOpenOffer = new OpenOffer(editedOffer, triggerPrice, openOffer);
|
||||
editedOpenOffer.setState(originalState);
|
||||
if (originalState == OpenOffer.State.DEACTIVATED && openOffer.isDeactivatedByTrigger()) {
|
||||
editedOpenOffer.setState(OpenOffer.State.AVAILABLE);
|
||||
applyTriggerState(editedOpenOffer);
|
||||
} else {
|
||||
editedOpenOffer.setState(originalState);
|
||||
}
|
||||
|
||||
addOpenOffer(editedOpenOffer);
|
||||
|
||||
|
@ -22,7 +22,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import haveno.common.util.MathUtils;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.monetary.CryptoMoney;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.TraditionalMoney;
|
||||
@ -69,27 +68,8 @@ public class PriceUtil {
|
||||
if (!result.isValid) {
|
||||
return result;
|
||||
}
|
||||
|
||||
long triggerPriceAsLong = PriceUtil.getMarketPriceAsLong(triggerPriceAsString, marketPrice.getCurrencyCode());
|
||||
long marketPriceAsLong = PriceUtil.getMarketPriceAsLong("" + marketPrice.getPrice(), marketPrice.getCurrencyCode());
|
||||
String marketPriceAsString = FormattingUtils.formatMarketPrice(marketPrice.getPrice(), marketPrice.getCurrencyCode());
|
||||
|
||||
boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
|
||||
if ((isSellOffer && !isCryptoCurrency) || (!isSellOffer && isCryptoCurrency)) {
|
||||
if (triggerPriceAsLong >= marketPriceAsLong) {
|
||||
return new InputValidator.ValidationResult(false,
|
||||
Res.get("createOffer.triggerPrice.invalid.tooHigh", marketPriceAsString));
|
||||
} else {
|
||||
return new InputValidator.ValidationResult(true);
|
||||
}
|
||||
} else {
|
||||
if (triggerPriceAsLong <= marketPriceAsLong) {
|
||||
return new InputValidator.ValidationResult(false,
|
||||
Res.get("createOffer.triggerPrice.invalid.tooLow", marketPriceAsString));
|
||||
} else {
|
||||
return new InputValidator.ValidationResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
return new InputValidator.ValidationResult(true);
|
||||
}
|
||||
|
||||
public static Price marketPriceToPrice(MarketPrice marketPrice) {
|
||||
|
@ -692,7 +692,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||
AutoTooltipSlideToggleButton checkBox;
|
||||
|
||||
private void updateState(@NotNull OpenOffer openOffer) {
|
||||
if (checkBox != null) checkBox.setSelected(!openOffer.isDeactivated());
|
||||
if (checkBox != null) checkBox.setSelected(openOffer.getState() == OpenOffer.State.AVAILABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user