Skip to content

Commit

Permalink
Merge pull request #2723 from ripcurlx/fix-calculation-of-sec-deposit…
Browse files Browse the repository at this point in the history
…-in-edit-offer

Fix wrong calculation of percentage based security deposit
  • Loading branch information
ripcurlx authored Apr 16, 2019
2 parents 24d0bae + 02f6475 commit ddeb1b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions core/src/main/java/bisq/core/util/CoinUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,19 @@ public static double getFeePerByte(Coin miningFee, int txSize) {
* @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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void applyOpenOffer(OpenOffer openOffer) {
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());
Expand Down

0 comments on commit ddeb1b4

Please sign in to comment.