always round offer amounts to 4 decimal places

This commit is contained in:
woodser 2025-01-17 10:24:47 -05:00
parent 130a45c99a
commit fac901331f
2 changed files with 11 additions and 13 deletions

View file

@ -151,11 +151,9 @@ public class CreateOfferService {
throw new IllegalArgumentException("Must provide fixed price"); throw new IllegalArgumentException("Must provide fixed price");
} }
// adjust amount and min amount for fixed-price offer // adjust amount and min amount
if (fixedPrice != null) { amount = CoinUtil.getRoundedAmount(amount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId());
amount = CoinUtil.getRoundedAmount(amount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId()); minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId());
minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId());
}
// generate one-time challenge for private offer // generate one-time challenge for private offer
String challenge = null; String challenge = null;

View file

@ -76,14 +76,14 @@ public class CoinUtil {
} }
public static BigInteger getRoundedAmount(BigInteger amount, Price price, Long maxTradeLimit, String currencyCode, String paymentMethodId) { public static BigInteger getRoundedAmount(BigInteger amount, Price price, Long maxTradeLimit, String currencyCode, String paymentMethodId) {
if (PaymentMethod.isRoundedForAtmCash(paymentMethodId)) { if (price != null) {
return getRoundedAtmCashAmount(amount, price, maxTradeLimit); if (PaymentMethod.isRoundedForAtmCash(paymentMethodId)) {
} else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) { return getRoundedAtmCashAmount(amount, price, maxTradeLimit);
return getRoundedAmountUnit(amount, price, maxTradeLimit); } else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) {
} else if (CurrencyUtil.isFiatCurrency(currencyCode)) { return getRoundedAmountUnit(amount, price, maxTradeLimit);
return getRoundedAmount4Decimals(amount, price, maxTradeLimit); }
} }
return amount; return getRoundedAmount4Decimals(amount, maxTradeLimit);
} }
public static BigInteger getRoundedAtmCashAmount(BigInteger amount, Price price, Long maxTradeLimit) { public static BigInteger getRoundedAtmCashAmount(BigInteger amount, Price price, Long maxTradeLimit) {
@ -103,7 +103,7 @@ public class CoinUtil {
return getAdjustedAmount(amount, price, maxTradeLimit, 1); return getAdjustedAmount(amount, price, maxTradeLimit, 1);
} }
public static BigInteger getRoundedAmount4Decimals(BigInteger amount, Price price, Long maxTradeLimit) { public static BigInteger getRoundedAmount4Decimals(BigInteger amount, Long maxTradeLimit) {
DecimalFormat decimalFormat = new DecimalFormat("#.####"); DecimalFormat decimalFormat = new DecimalFormat("#.####");
double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount))); double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount)));
return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount); return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount);