Fix offer editing for low volume offers

For very low volume offers, it can happen that the minimum buyer security
deposit by coin value is bigger than the maximum security deposit by
percentage of trade amount.
This caused the security deposit validity check in the offer editor to fail,
making it impossible to edit these offers.
This commit fixes the problem by setting the default percentage value to
the model instead of the calculated one in this specific case.
This commit is contained in:
a123b 2019-06-29 17:03:19 +02:00
parent e13faba79a
commit 2b171e4831

View file

@ -23,6 +23,7 @@ import bisq.desktop.main.offer.MutableOfferDataModel;
import bisq.core.btc.TxFeeEstimationService;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.filter.FilterManager;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.TradeCurrency;
@ -114,7 +115,6 @@ class EditOfferDataModel extends MutableOfferDataModel {
CurrencyUtil.getTradeCurrency(offer.getCurrencyCode())
.ifPresent(c -> this.tradeCurrency = c);
tradeCurrencyCode.set(offer.getCurrencyCode());
buyerSecurityDeposit.set(CoinUtil.getAsPercentPerBtc(offer.getBuyerSecurityDeposit(), offer.getAmount()));
this.initialState = openOffer.getState();
PaymentAccount tmpPaymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId());
@ -128,6 +128,16 @@ class EditOfferDataModel extends MutableOfferDataModel {
paymentAccount.setSelectedTradeCurrency(selectedTradeCurrency);
}
// If the security deposit got bounded because it was below the coin amount limit, it can be bigger
// by percentage than the restriction. We can't determine the percentage originally entered at offer
// creation, so just use the default value as it doesn't matter anyway.
double buyerSecurityDepositPercent = CoinUtil.getAsPercentPerBtc(offer.getBuyerSecurityDeposit(), offer.getAmount());
if (buyerSecurityDepositPercent > Restrictions.getMaxBuyerSecurityDepositAsPercent(this.paymentAccount)
&& offer.getBuyerSecurityDeposit().value == Restrictions.getMinBuyerSecurityDepositAsCoin().value)
buyerSecurityDeposit.set(Restrictions.getDefaultBuyerSecurityDepositAsPercent(this.paymentAccount));
else
buyerSecurityDeposit.set(buyerSecurityDepositPercent);
allowAmountUpdate = false;
}