diff --git a/core/src/main/java/bisq/core/api/CoreOffersService.java b/core/src/main/java/bisq/core/api/CoreOffersService.java index 252fe11a7e0..ba1750290fd 100644 --- a/core/src/main/java/bisq/core/api/CoreOffersService.java +++ b/core/src/main/java/bisq/core/api/CoreOffersService.java @@ -464,22 +464,35 @@ private OfferPayload getMergedOfferPayload(EditOfferValidator editOfferValidator // in OfferPayload. Offer offer = openOffer.getOffer(); String currencyCode = offer.getCurrencyCode(); - boolean isEditingPrice = editType.equals(FIXED_PRICE_ONLY) || editType.equals(FIXED_PRICE_AND_ACTIVATION_STATE); - Price editedPrice; - if (isEditingPrice) { - editedPrice = Price.valueOf(currencyCode, priceStringToLong(editedPriceAsString, currencyCode)); + boolean isUsingMktPriceMargin = editOfferValidator.isEditingUseMktPriceMarginFlag.test(offer, editType); + boolean isEditingFixedPrice = editType.equals(FIXED_PRICE_ONLY) || editType.equals(FIXED_PRICE_AND_ACTIVATION_STATE); + Price editedFixedPrice; + if (isEditingFixedPrice) { + editedFixedPrice = Price.valueOf(currencyCode, priceStringToLong(editedPriceAsString, currencyCode)); } else { - editedPrice = offer.getPrice(); + // When isUsingMktPriceMargin=true, (fixed) price must be set to 0 on the server. + // The client, however, still must show the calculated price when + // isUsingMktPriceMargin=true. + editedFixedPrice = isUsingMktPriceMargin ? Price.valueOf(currencyCode, 0) : offer.getPrice(); } - boolean isUsingMktPriceMargin = editOfferValidator.isEditingUseMktPriceMarginFlag.test(offer, editType); + // If isUsingMktPriceMargin=true, throw exception if new fixed-price != 0. + // If isUsingMktPriceMargin=false, throw exception if new fixed-price == 0. + if (isUsingMktPriceMargin && editedFixedPrice.getValue() != 0) + throw new IllegalStateException( + format("Fixed price on mkt price margin based offer %s must be set to 0 in server.", + offer.getId())); + else if (!isUsingMktPriceMargin && editedFixedPrice.getValue() == 0) + throw new IllegalStateException( + format("Fixed price on fixed price offer %s cannot be 0.", offer.getId())); + boolean isEditingMktPriceMargin = editOfferValidator.isEditingMktPriceMargin.test(editType); double newMarketPriceMargin = isEditingMktPriceMargin ? exactMultiply(editedMarketPriceMargin, 0.01) : offer.getMarketPriceMargin(); MutableOfferPayloadFields mutableOfferPayloadFields = new MutableOfferPayloadFields( - Objects.requireNonNull(editedPrice).getValue(), + Objects.requireNonNull(editedFixedPrice).getValue(), isUsingMktPriceMargin ? newMarketPriceMargin : 0.00, isUsingMktPriceMargin, offer.getBaseCurrencyCode(), diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index e93e420f892..488fb87567a 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -420,7 +420,7 @@ public OfferPayload getMergedOfferPayload(OpenOffer openOffer, original.getOwnerNodeAddress(), original.getPubKeyRing(), original.getDirection(), - mutableOfferPayloadFields.getPrice(), + mutableOfferPayloadFields.getFixedPrice(), mutableOfferPayloadFields.getMarketPriceMargin(), mutableOfferPayloadFields.isUseMarketBasedPrice(), original.getAmount(), diff --git a/core/src/main/java/bisq/core/offer/bisq_v1/MutableOfferPayloadFields.java b/core/src/main/java/bisq/core/offer/bisq_v1/MutableOfferPayloadFields.java index e672a2c0ed5..c7e654594f5 100644 --- a/core/src/main/java/bisq/core/offer/bisq_v1/MutableOfferPayloadFields.java +++ b/core/src/main/java/bisq/core/offer/bisq_v1/MutableOfferPayloadFields.java @@ -32,7 +32,7 @@ @Setter public final class MutableOfferPayloadFields { - private final long price; + private final long fixedPrice; // Must be 0 when marketPriceMargin = true (on server). private final double marketPriceMargin; private final boolean useMarketBasedPrice; private final String baseCurrencyCode; @@ -69,7 +69,7 @@ public MutableOfferPayloadFields(OfferPayload offerPayload) { offerPayload.getExtraDataMap()); } - public MutableOfferPayloadFields(long price, + public MutableOfferPayloadFields(long fixedPrice, double marketPriceMargin, boolean useMarketBasedPrice, String baseCurrencyCode, @@ -83,7 +83,7 @@ public MutableOfferPayloadFields(long price, @Nullable String bankId, @Nullable List acceptedBankIds, @Nullable Map extraDataMap) { - this.price = price; + this.fixedPrice = fixedPrice; this.marketPriceMargin = marketPriceMargin; this.useMarketBasedPrice = useMarketBasedPrice; this.baseCurrencyCode = baseCurrencyCode; @@ -102,7 +102,7 @@ public MutableOfferPayloadFields(long price, @Override public String toString() { return "MutableOfferPayloadFields{" + "\n" + - " price=" + price + "\n" + + " fixedPrice=" + fixedPrice + "\n" + ", marketPriceMargin=" + marketPriceMargin + "\n" + ", useMarketBasedPrice=" + useMarketBasedPrice + "\n" + ", baseCurrencyCode='" + baseCurrencyCode + '\'' + "\n" +