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");
}
// adjust amount and min amount for fixed-price offer
if (fixedPrice != null) {
// adjust amount and min amount
amount = CoinUtil.getRoundedAmount(amount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId());
minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId());
}
// generate one-time challenge for private offer
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) {
if (price != null) {
if (PaymentMethod.isRoundedForAtmCash(paymentMethodId)) {
return getRoundedAtmCashAmount(amount, price, maxTradeLimit);
} else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) {
return getRoundedAmountUnit(amount, price, maxTradeLimit);
} else if (CurrencyUtil.isFiatCurrency(currencyCode)) {
return getRoundedAmount4Decimals(amount, price, maxTradeLimit);
}
return amount;
}
return getRoundedAmount4Decimals(amount, maxTradeLimit);
}
public static BigInteger getRoundedAtmCashAmount(BigInteger amount, Price price, Long maxTradeLimit) {
@ -103,7 +103,7 @@ public class CoinUtil {
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("#.####");
double roundedXmrAmount = Double.parseDouble(decimalFormat.format(HavenoUtils.atomicUnitsToXmr(amount)));
return HavenoUtils.xmrToAtomicUnits(roundedXmrAmount);