Merge pull request #4178 from jmacxx/fix_issue_3871

When accepting an offer do not round the BTC amount outside range
This commit is contained in:
sqrrm 2020-05-11 15:18:47 +02:00 committed by GitHub
commit d51c4c82e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -361,7 +361,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
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 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
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 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
return amount.value == offer.getMinAmount().value;
}
private boolean isAmountEqualMaxAmount(Coin amount) {
return amount.value == offer.getAmount().value;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters