Fix wrong calculation of percentage based security deposit

This commit is contained in:
Christoph Atteneder 2019-04-16 11:27:59 +02:00
parent 24d0baeaa6
commit 02f6475470
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
2 changed files with 14 additions and 3 deletions

View File

@ -49,8 +49,19 @@ public class CoinUtil {
* @return The percentage value as double (e.g. 1% is 0.01)
*/
public static double getAsPercentPerBtc(Coin value) {
double asDouble = value != null ? (double) value.value : 0;
double btcAsDouble = (double) Coin.COIN.value;
return getAsPercentPerBtc(value, Coin.COIN);
}
/**
* @param part Btc amount to be converted to percent value, based on total value passed.
* E.g. 0.1 BTC is 25% (of 0.4 BTC)
* @param total Total Btc amount the percentage part is calculated from
*
* @return The percentage value as double (e.g. 1% is 0.01)
*/
public static double getAsPercentPerBtc(Coin part, Coin total) {
double asDouble = part != null ? (double) part.value : 0;
double btcAsDouble = total != null ? (double) total.value : 1;
return MathUtils.roundDouble(asDouble / btcAsDouble, 4);
}

View File

@ -114,7 +114,7 @@ class EditOfferDataModel extends MutableOfferDataModel {
CurrencyUtil.getTradeCurrency(offer.getCurrencyCode())
.ifPresent(c -> this.tradeCurrency = c);
tradeCurrencyCode.set(offer.getCurrencyCode());
buyerSecurityDeposit.set(CoinUtil.getAsPercentPerBtc(offer.getBuyerSecurityDeposit()));
buyerSecurityDeposit.set(CoinUtil.getAsPercentPerBtc(offer.getBuyerSecurityDeposit(), offer.getAmount()));
this.initialState = openOffer.getState();
PaymentAccount tmpPaymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId());