From 223a1d3a6cd9a9b40e5f6901bdd0c8c4a09a41f2 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Fri, 17 Apr 2020 22:05:30 -0500 Subject: [PATCH] When accepting an offer do not round the BTC amount outside range Fixes 3871. The BTC amount of an offer was being adjusted up in certain cases due to a rounding calculation from the fiat value and price. This would prevent some offers from being taken. There's an existing check to ensure that the amount is not adjusted below the minimum, here we add a check to ensure that the amount is not adjusted higher than the maximum defined in the offer. --- .../desktop/main/offer/takeoffer/TakeOfferViewModel.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java index b3f5dfff99f..685fb6dbe1b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java @@ -361,7 +361,7 @@ void onFocusOutAmountTextField(boolean oldValue, boolean newValue, String userIn dataModel.applyAmount(adjustedAmountForHalCash); amount.set(btcFormatter.formatCoin(dataModel.getAmount().get())); } else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode())) { - if (!isAmountEqualMinAmount(dataModel.getAmount().get())) { + if (!isAmountEqualMinAmount(dataModel.getAmount().get()) && (!isAmountEqualMaxAmount(dataModel.getAmount().get()))) { // We only apply the rounding if the amount is variable (minAmount is lower as amount). // Otherwise we could get an amount lower then the minAmount set by rounding Coin roundedAmount = OfferUtil.getRoundedFiatAmount(dataModel.getAmount().get(), tradePrice, @@ -644,7 +644,8 @@ private void setAmountToModel() { if (price != null) { if (dataModel.isHalCashAccount()) { amount = OfferUtil.getAdjustedAmountForHalCash(amount, price, maxTradeLimit); - } else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode()) && !isAmountEqualMinAmount(amount)) { + } else if (CurrencyUtil.isFiatCurrency(dataModel.getCurrencyCode()) + && !isAmountEqualMinAmount(amount) && !isAmountEqualMaxAmount(amount)) { // We only apply the rounding if the amount is variable (minAmount is lower as amount). // Otherwise we could get an amount lower then the minAmount set by rounding amount = OfferUtil.getRoundedFiatAmount(amount, price, maxTradeLimit); @@ -658,6 +659,9 @@ private boolean isAmountEqualMinAmount(Coin amount) { return amount.value == offer.getMinAmount().value; } + private boolean isAmountEqualMaxAmount(Coin amount) { + return amount.value == offer.getAmount().value; + } /////////////////////////////////////////////////////////////////////////////////////////// // Getters