From 2b171e48317044e40ad1b3496d5b37115cc1ce34 Mon Sep 17 00:00:00 2001 From: a123b <6329481+a123b@users.noreply.github.com> Date: Sat, 29 Jun 2019 17:03:19 +0200 Subject: [PATCH] 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. --- .../main/portfolio/editoffer/EditOfferDataModel.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java index c28fda0f218..27772a2941f 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java @@ -23,6 +23,7 @@ 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 @@ public void applyOpenOffer(OpenOffer openOffer) { 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 @@ public void applyOpenOffer(OpenOffer openOffer) { 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; }