Skip to content

Commit 065e6f6

Browse files
committed
fix offer amount adjustment via api
1 parent ca1dde0 commit 065e6f6

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

core/src/main/java/haveno/core/offer/CreateOfferService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import haveno.core.trade.statistics.TradeStatisticsManager;
3636
import haveno.core.user.User;
3737
import haveno.core.util.coin.CoinUtil;
38+
import haveno.core.xmr.wallet.Restrictions;
3839
import haveno.core.xmr.wallet.XmrWalletService;
3940
import haveno.network.p2p.NodeAddress;
4041
import haveno.network.p2p.P2PService;
@@ -158,8 +159,9 @@ public Offer createAndGetOffer(String offerId,
158159
}
159160

160161
// adjust amount and min amount
161-
amount = CoinUtil.getRoundedAmount(amount, fixedPrice, minAmount, amount, currencyCode, paymentAccount.getPaymentMethod().getId());
162-
minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, minAmount, amount, currencyCode, paymentAccount.getPaymentMethod().getId());
162+
BigInteger maxTradeLimit = offerUtil.getMaxTradeLimitForRelease(paymentAccount, currencyCode, direction, buyerAsTakerWithoutDeposit);
163+
amount = CoinUtil.getRoundedAmount(amount, fixedPrice, Restrictions.getMinTradeAmount(), maxTradeLimit, currencyCode, paymentAccount.getPaymentMethod().getId());
164+
minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, Restrictions.getMinTradeAmount(), maxTradeLimit, currencyCode, paymentAccount.getPaymentMethod().getId());
163165

164166
// generate one-time challenge for private offer
165167
String challenge = null;

core/src/main/java/haveno/core/offer/OfferUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import haveno.core.payment.PaymentAccount;
5757
import haveno.core.provider.price.MarketPrice;
5858
import haveno.core.provider.price.PriceFeedService;
59+
import haveno.core.trade.HavenoUtils;
5960
import haveno.core.trade.statistics.ReferralIdService;
6061
import haveno.core.user.AutoConfirmSettings;
6162
import haveno.core.user.Preferences;
@@ -269,4 +270,21 @@ public static boolean isTraditionalOffer(Offer offer) {
269270
public static boolean isCryptoOffer(Offer offer) {
270271
return offer.getCounterCurrencyCode().equals("XMR");
271272
}
273+
274+
public BigInteger getMaxTradeLimitForRelease(PaymentAccount paymentAccount,
275+
String currencyCode,
276+
OfferDirection direction,
277+
boolean buyerAsTakerWithoutDeposit) {
278+
279+
// disallow offers which no buyer can take due to trade limits on release
280+
if (HavenoUtils.isReleasedWithinDays(HavenoUtils.RELEASE_LIMIT_DAYS)) {
281+
return BigInteger.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode, OfferDirection.BUY, buyerAsTakerWithoutDeposit));
282+
}
283+
284+
if (paymentAccount != null) {
285+
return BigInteger.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode, direction, buyerAsTakerWithoutDeposit));
286+
} else {
287+
return BigInteger.ZERO;
288+
}
289+
}
272290
}

desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,7 @@ public double getMarketPriceMarginPct() {
473473
}
474474

475475
BigInteger getMaxTradeLimit() {
476-
477-
// disallow offers which no buyer can take due to trade limits on release
478-
if (HavenoUtils.isReleasedWithinDays(HavenoUtils.RELEASE_LIMIT_DAYS)) {
479-
return BigInteger.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrencyCode.get(), OfferDirection.BUY, buyerAsTakerWithoutDeposit.get()));
480-
}
481-
482-
if (paymentAccount != null) {
483-
return BigInteger.valueOf(accountAgeWitnessService.getMyTradeLimit(paymentAccount, tradeCurrencyCode.get(), direction, buyerAsTakerWithoutDeposit.get()));
484-
} else {
485-
return BigInteger.ZERO;
486-
}
476+
return offerUtil.getMaxTradeLimitForRelease(paymentAccount, tradeCurrencyCode.get(), direction, buyerAsTakerWithoutDeposit.get());
487477
}
488478

489479
BigInteger getMinTradeLimit() {

0 commit comments

Comments
 (0)