From f675588a2deaa123258470df55b6df1b6b4e56e8 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 14 Feb 2025 16:34:08 -0500 Subject: [PATCH] allow offer trigger price outside of current price --- .../haveno/core/offer/OpenOfferManager.java | 15 +++++++++++- .../main/java/haveno/core/util/PriceUtil.java | 24 ++----------------- .../portfolio/openoffer/OpenOffersView.java | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index 5bb127f840..5df08a38ba 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -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); diff --git a/core/src/main/java/haveno/core/util/PriceUtil.java b/core/src/main/java/haveno/core/util/PriceUtil.java index 35a6b0bec8..a91b13c85c 100644 --- a/core/src/main/java/haveno/core/util/PriceUtil.java +++ b/core/src/main/java/haveno/core/util/PriceUtil.java @@ -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) { diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java index 575cc1d2b1..7c41eef890 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java @@ -692,7 +692,7 @@ public class OpenOffersView extends ActivatableViewAndModel