diff --git a/core/src/main/java/bisq/core/util/CoinUtil.java b/core/src/main/java/bisq/core/util/CoinUtil.java index 7357c61c366..cb79de0d29a 100644 --- a/core/src/main/java/bisq/core/util/CoinUtil.java +++ b/core/src/main/java/bisq/core/util/CoinUtil.java @@ -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); } 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 a723a368c7e..c28fda0f218 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 @@ -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());