diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 1aa15a381d..2d2f02255e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -121,6 +121,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs protected final ObjectProperty minAmount = new SimpleObjectProperty<>(); protected final ObjectProperty price = new SimpleObjectProperty<>(); protected final ObjectProperty volume = new SimpleObjectProperty<>(); + protected final ObjectProperty minVolume = new SimpleObjectProperty<>(); // Percentage value of buyer security deposit. E.g. 0.01 means 1% of trade amount protected final DoubleProperty buyerSecurityDeposit = new SimpleDoubleProperty(); @@ -427,6 +428,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs void onPaymentAccountSelected(PaymentAccount paymentAccount) { if (paymentAccount != null && !this.paymentAccount.equals(paymentAccount)) { volume.set(null); + minVolume.set(null); price.set(null); marketPriceMargin = 0; preferences.setSelectedPaymentAccountForCreateOffer(paymentAccount); @@ -458,6 +460,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs if (tradeCurrency != null) { if (!this.tradeCurrency.equals(tradeCurrency)) { volume.set(null); + minVolume.set(null); price.set(null); marketPriceMargin = 0; } @@ -591,15 +594,11 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs !amount.get().isZero() && !price.get().isZero()) { try { - Volume volumeByAmount = price.get().getVolumeByAmount(amount.get()); - - // For HalCash we want multiple of 10 EUR - if (isHalCashAccount()) - volumeByAmount = OfferUtil.getAdjustedVolumeForHalCash(volumeByAmount); - else if (CurrencyUtil.isFiatCurrency(tradeCurrencyCode.get())) - volumeByAmount = OfferUtil.getRoundedFiatVolume(volumeByAmount); + Volume volumeByAmount = calculateVolumeForAmount(amount); volume.set(volumeByAmount); + + calculateMinVolume(); } catch (Throwable t) { log.error(t.toString()); } @@ -608,6 +607,33 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs updateBalance(); } + void calculateMinVolume() { + if (price.get() != null && + minAmount.get() != null && + !minAmount.get().isZero() && + !price.get().isZero()) { + try { + Volume volumeByAmount = calculateVolumeForAmount(minAmount); + + minVolume.set(volumeByAmount); + + } catch (Throwable t) { + log.error(t.toString()); + } + } + } + + private Volume calculateVolumeForAmount(ObjectProperty minAmount) { + Volume volumeByAmount = price.get().getVolumeByAmount(minAmount.get()); + + // For HalCash we want multiple of 10 EUR + if (isHalCashAccount()) + volumeByAmount = OfferUtil.getAdjustedVolumeForHalCash(volumeByAmount); + else if (CurrencyUtil.isFiatCurrency(tradeCurrencyCode.get())) + volumeByAmount = OfferUtil.getRoundedFiatVolume(volumeByAmount); + return volumeByAmount; + } + void calculateAmount() { if (volume.get() != null && price.get() != null && @@ -711,6 +737,10 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs return volume; } + ReadOnlyObjectProperty getMinVolume() { + return minVolume; + } + protected void setMinAmount(Coin minAmount) { this.minAmount.set(minAmount); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index f65b67c217..67ac5fea46 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -227,7 +227,6 @@ public abstract class MutableOfferViewModel ext minAmount.set(amount.get()); onFocusOutPriceAsPercentageTextField(true, false); applyMakerFee(); - updateButtonDisableState(); setAmountToModel(); setMinAmountToModel(); setPriceToModel(); @@ -743,6 +742,18 @@ public abstract class MutableOfferViewModel ext Coin minAmountAsCoin = dataModel.getMinAmount().get(); syncMinAmountWithAmount = minAmountAsCoin != null && minAmountAsCoin.equals(dataModel.getAmount().get()); setMinAmountToModel(); + + dataModel.calculateMinVolume(); + + if (dataModel.getMinVolume().get() != null) { + InputValidator.ValidationResult minVolumeResult = isVolumeInputValid( + btcFormatter.formatVolume(dataModel.getMinVolume().get())); + + volumeValidationResult.set(minVolumeResult); + + updateButtonDisableState(); + } + this.minAmount.set(btcFormatter.formatCoin(minAmountAsCoin)); if (!dataModel.isMinAmountLessOrEqualAmount()) { @@ -1167,6 +1178,7 @@ public abstract class MutableOfferViewModel ext dataModel.getPrice().get() != null && dataModel.getPrice().get().getValue() != 0 && isVolumeInputValid(volume.get()).isValid && + isVolumeInputValid(btcFormatter.formatVolume(dataModel.getMinVolume().get())).isValid && dataModel.isMinAmountLessOrEqualAmount(); isNextButtonDisabled.set(!inputDataValid); 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 6fa8f90f1a..a723a368c7 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 @@ -99,6 +99,7 @@ class EditOfferDataModel extends MutableOfferDataModel { minAmount.set(null); price.set(null); volume.set(null); + minVolume.set(null); buyerSecurityDeposit.set(0); paymentAccounts.clear(); paymentAccount = null;