fix ui to set security deposit pct w/o deposit

This commit is contained in:
woodser 2024-12-20 11:45:42 -05:00
parent 389c5dddac
commit c5ef60ce5c

View file

@ -56,6 +56,7 @@ import haveno.core.util.coin.CoinUtil;
import haveno.core.util.validation.AmountValidator4Decimals; import haveno.core.util.validation.AmountValidator4Decimals;
import haveno.core.util.validation.AmountValidator8Decimals; import haveno.core.util.validation.AmountValidator8Decimals;
import haveno.core.util.validation.InputValidator; import haveno.core.util.validation.InputValidator;
import haveno.core.util.validation.InputValidator.ValidationResult;
import haveno.core.util.validation.MonetaryValidator; import haveno.core.util.validation.MonetaryValidator;
import haveno.core.xmr.wallet.Restrictions; import haveno.core.xmr.wallet.Restrictions;
import haveno.desktop.Navigation; import haveno.desktop.Navigation;
@ -490,6 +491,8 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit())); xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()));
if (amount.get() != null) amountValidationResult.set(isXmrInputValid(amount.get())); if (amount.get() != null) amountValidationResult.set(isXmrInputValid(amount.get()));
updateSecurityDeposit(); updateSecurityDeposit();
setSecurityDepositToModel();
onFocusOutSecurityDepositTextField(true, false); // refresh security deposit field
applyMakerFee(); applyMakerFee();
dataModel.calculateTotalToPay(); dataModel.calculateTotalToPay();
updateButtonDisableState(); updateButtonDisableState();
@ -769,7 +772,8 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
} }
} }
} }
// We want to trigger a recalculation of the volume
// trigger recalculation of the volume
UserThread.execute(() -> { UserThread.execute(() -> {
onFocusOutVolumeTextField(true, false); onFocusOutVolumeTextField(true, false);
onFocusOutMinAmountTextField(true, false); onFocusOutMinAmountTextField(true, false);
@ -815,6 +819,11 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
} }
maybeShowMakeOfferToUnsignedAccountWarning(); maybeShowMakeOfferToUnsignedAccountWarning();
// trigger recalculation of the security deposit
UserThread.execute(() -> {
onFocusOutSecurityDepositTextField(true, false);
});
} }
} }
@ -944,11 +953,16 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
if (marketPriceMargin.get() == null && amount.get() != null && volume.get() != null) { if (marketPriceMargin.get() == null && amount.get() != null && volume.get() != null) {
updateMarketPriceToManual(); updateMarketPriceToManual();
} }
// trigger recalculation of security deposit
UserThread.execute(() -> {
onFocusOutSecurityDepositTextField(true, false);
});
} }
} }
void onFocusOutSecurityDepositTextField(boolean oldValue, boolean newValue) { void onFocusOutSecurityDepositTextField(boolean oldValue, boolean newValue) {
if (oldValue && !newValue) { if (oldValue && !newValue && !isMinSecurityDeposit.get()) {
InputValidator.ValidationResult result = securityDepositValidator.validate(securityDeposit.get()); InputValidator.ValidationResult result = securityDepositValidator.validate(securityDeposit.get());
securityDepositValidationResult.set(result); securityDepositValidationResult.set(result);
if (result.isValid) { if (result.isValid) {
@ -1040,6 +1054,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
public String getSecurityDepositLabel() { public String getSecurityDepositLabel() {
return dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer() ? Res.get("createOffer.myDeposit") : return dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer() ? Res.get("createOffer.myDeposit") :
dataModel.isMinSecurityDeposit() ? Res.get("createOffer.minSecurityDepositUsed") :
Preferences.USE_SYMMETRIC_SECURITY_DEPOSIT ? Res.get("createOffer.setDepositForBothTraders") : Preferences.USE_SYMMETRIC_SECURITY_DEPOSIT ? Res.get("createOffer.setDepositForBothTraders") :
dataModel.isBuyOffer() ? Res.get("createOffer.setDepositAsBuyer") : Res.get("createOffer.setDeposit"); dataModel.isBuyOffer() ? Res.get("createOffer.setDepositAsBuyer") : Res.get("createOffer.setDeposit");
} }
@ -1211,7 +1226,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
} }
private void setSecurityDepositToModel() { private void setSecurityDepositToModel() {
if (!(dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer()) && securityDeposit.get() != null && !securityDeposit.get().isEmpty()) { if (securityDeposit.get() != null && !securityDeposit.get().isEmpty() && !isMinSecurityDeposit.get()) {
dataModel.setSecurityDepositPct(ParsingUtils.parsePercentStringToDouble(securityDeposit.get())); dataModel.setSecurityDepositPct(ParsingUtils.parsePercentStringToDouble(securityDeposit.get()));
} else { } else {
dataModel.setSecurityDepositPct(Restrictions.getDefaultSecurityDepositAsPercent()); dataModel.setSecurityDepositPct(Restrictions.getDefaultSecurityDepositAsPercent());
@ -1282,11 +1297,11 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
private void updateSecurityDeposit() { private void updateSecurityDeposit() {
isMinSecurityDeposit.set(dataModel.isMinSecurityDeposit()); isMinSecurityDeposit.set(dataModel.isMinSecurityDeposit());
securityDepositLabel.set(getSecurityDepositLabel());
if (dataModel.isMinSecurityDeposit()) { if (dataModel.isMinSecurityDeposit()) {
securityDepositLabel.set(Res.get("createOffer.minSecurityDepositUsed"));
securityDeposit.set(HavenoUtils.formatXmr(Restrictions.getMinSecurityDeposit())); securityDeposit.set(HavenoUtils.formatXmr(Restrictions.getMinSecurityDeposit()));
securityDepositValidationResult.set(new ValidationResult(true));
} else { } else {
securityDepositLabel.set(getSecurityDepositLabel());
boolean hasBuyerAsTakerWithoutDeposit = dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer(); boolean hasBuyerAsTakerWithoutDeposit = dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer();
securityDeposit.set(FormattingUtils.formatToPercent(hasBuyerAsTakerWithoutDeposit ? securityDeposit.set(FormattingUtils.formatToPercent(hasBuyerAsTakerWithoutDeposit ?
Restrictions.getDefaultSecurityDepositAsPercent() : // use default percent if no deposit from buyer Restrictions.getDefaultSecurityDepositAsPercent() : // use default percent if no deposit from buyer