From fac901331faa8ee6acb5525d02af78de5534445f Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 17 Jan 2025 10:24:47 -0500 Subject: [PATCH] always round offer amounts to 4 decimal places --- .../haveno/core/offer/CreateOfferService.java | 8 +++----- .../java/haveno/core/util/coin/CoinUtil.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/CreateOfferService.java b/core/src/main/java/haveno/core/offer/CreateOfferService.java index e135bfa123..35ece3b10e 100644 --- a/core/src/main/java/haveno/core/offer/CreateOfferService.java +++ b/core/src/main/java/haveno/core/offer/CreateOfferService.java @@ -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) { - amount = CoinUtil.getRoundedAmount(amount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId()); - minAmount = CoinUtil.getRoundedAmount(minAmount, fixedPrice, null, currencyCode, paymentAccount.getPaymentMethod().getId()); - } + // 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; diff --git a/core/src/main/java/haveno/core/util/coin/CoinUtil.java b/core/src/main/java/haveno/core/util/coin/CoinUtil.java index bf194b3ea0..4085a63b6a 100644 --- a/core/src/main/java/haveno/core/util/coin/CoinUtil.java +++ b/core/src/main/java/haveno/core/util/coin/CoinUtil.java @@ -76,14 +76,14 @@ public class CoinUtil { } public static BigInteger getRoundedAmount(BigInteger amount, Price price, Long maxTradeLimit, String currencyCode, String paymentMethodId) { - 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); + if (price != null) { + if (PaymentMethod.isRoundedForAtmCash(paymentMethodId)) { + return getRoundedAtmCashAmount(amount, price, maxTradeLimit); + } else if (CurrencyUtil.isVolumeRoundedToNearestUnit(currencyCode)) { + return getRoundedAmountUnit(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);