diff --git a/core/src/main/java/bisq/core/util/PriceUtil.java b/core/src/main/java/bisq/core/util/PriceUtil.java index 977420a8356..9f8b934c111 100644 --- a/core/src/main/java/bisq/core/util/PriceUtil.java +++ b/core/src/main/java/bisq/core/util/PriceUtil.java @@ -72,7 +72,7 @@ public static MonetaryValidator getPriceValidator(boolean isFiatCurrency) { } public static InputValidator.ValidationResult isTriggerPriceValid(String triggerPriceAsString, - Price price, + MarketPrice marketPrice, boolean isSellOffer, boolean isFiatCurrency) { if (triggerPriceAsString == null || triggerPriceAsString.isEmpty()) { @@ -84,20 +84,21 @@ public static InputValidator.ValidationResult isTriggerPriceValid(String trigger return result; } - long triggerPriceAsLong = PriceUtil.getMarketPriceAsLong(triggerPriceAsString, price.getCurrencyCode()); - long priceAsLong = price.getValue(); - String priceAsString = FormattingUtils.formatPrice(price); + long triggerPriceAsLong = PriceUtil.getMarketPriceAsLong(triggerPriceAsString, marketPrice.getCurrencyCode()); + long marketPriceAsLong = PriceUtil.getMarketPriceAsLong("" + marketPrice.getPrice(), marketPrice.getCurrencyCode()); + String marketPriceAsString = FormattingUtils.formatMarketPrice(marketPrice.getPrice(), marketPrice.getCurrencyCode()); + if ((isSellOffer && isFiatCurrency) || (!isSellOffer && !isFiatCurrency)) { - if (triggerPriceAsLong >= priceAsLong) { + if (triggerPriceAsLong >= marketPriceAsLong) { return new InputValidator.ValidationResult(false, - Res.get("createOffer.triggerPrice.invalid.tooHigh", priceAsString)); + Res.get("createOffer.triggerPrice.invalid.tooHigh", marketPriceAsString)); } else { return new InputValidator.ValidationResult(true); } } else { - if (triggerPriceAsLong <= priceAsLong) { + if (triggerPriceAsLong <= marketPriceAsLong) { return new InputValidator.ValidationResult(false, - Res.get("createOffer.triggerPrice.invalid.tooLow", priceAsString)); + Res.get("createOffer.triggerPrice.invalid.tooLow", marketPriceAsString)); } else { return new InputValidator.ValidationResult(true); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java index 32576575c10..a7f4c138ca4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferViewModel.java @@ -791,12 +791,14 @@ public void onTriggerPriceTextFieldChanged() { // if not reset here. Not clear why... triggerPriceValidationResult.set(new InputValidator.ValidationResult(true)); - if (dataModel.getPrice().get() == null) // fix NPE @ bisq/issues/5166 - return; + String currencyCode = dataModel.getTradeCurrencyCode().get(); + MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); + InputValidator.ValidationResult result = PriceUtil.isTriggerPriceValid(triggerPriceAsString, - dataModel.getPrice().get(), + marketPrice, dataModel.isSellOffer(), - dataModel.isFiatCurrency()); + dataModel.isFiatCurrency() + ); triggerPriceValidationResult.set(result); updateButtonDisableState(); if (result.isValid) {