Skip to content

Commit

Permalink
Merge pull request #4555 from jmacxx/fix_security_deposit_display
Browse files Browse the repository at this point in the history
Display the calculated security deposit at order entry
  • Loading branch information
sqrrm authored Sep 27, 2020
2 parents a408dd5 + 3e22b6e commit 37ce52b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public MutableOfferDataModel(CreateOfferService createOfferService,
addressEntry = btcWalletService.getOrCreateAddressEntry(offerId, AddressEntry.Context.OFFER_FUNDING);

useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice());
buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent(null));
buyerSecurityDeposit.set(Restrictions.getMinBuyerSecurityDepositAsPercent());

btcBalanceListener = new BalanceListener(getAddressEntry().getAddress()) {
@Override
Expand Down Expand Up @@ -334,10 +334,10 @@ void onPaymentAccountSelected(PaymentAccount paymentAccount) {
}

private void setSuggestedSecurityDeposit(PaymentAccount paymentAccount) {
var minSecurityDeposit = preferences.getBuyerSecurityDepositAsPercent(getPaymentAccount());
var minSecurityDeposit = Restrictions.getMinBuyerSecurityDepositAsPercent();
try {
if (getTradeCurrency() == null) {
setBuyerSecurityDeposit(minSecurityDeposit, false);
setBuyerSecurityDeposit(minSecurityDeposit);
return;
}
// Get average historic prices over for the prior trade period equaling the lock time
Expand All @@ -360,7 +360,7 @@ private void setSuggestedSecurityDeposit(PaymentAccount paymentAccount) {
var min = extremes[0];
var max = extremes[1];
if (min == 0d || max == 0d) {
setBuyerSecurityDeposit(minSecurityDeposit, false);
setBuyerSecurityDeposit(minSecurityDeposit);
return;
}
// Suggested deposit is double the trade range over the previous lock time period, bounded by min/max deposit
Expand Down Expand Up @@ -640,12 +640,8 @@ protected void setVolume(Volume volume) {
this.volume.set(volume);
}

void setBuyerSecurityDeposit(double value, boolean persist) {
void setBuyerSecurityDeposit(double value) {
this.buyerSecurityDeposit.set(value);
if (persist) {
// Only expected to persist for manually changed deposit values
preferences.setBuyerSecurityDepositAsPercent(value, getPaymentAccount());
}
}

protected boolean isUseMarketBasedPriceValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private void createListeners() {
securityDepositStringListener = (ov, oldValue, newValue) -> {
if (!ignoreSecurityDepositStringListener) {
if (securityDepositValidator.validate(newValue).isValid) {
setBuyerSecurityDepositToModel(false);
setBuyerSecurityDepositToModel();
dataModel.calculateTotalToPay();
}
updateButtonDisableState();
Expand Down Expand Up @@ -898,7 +898,7 @@ void onFocusOutBuyerSecurityDepositTextField(boolean oldValue, boolean newValue)
.width(800)
.actionButtonText(Res.get("createOffer.resetToDefault"))
.onAction(() -> {
dataModel.setBuyerSecurityDeposit(defaultSecurityDeposit, false);
dataModel.setBuyerSecurityDeposit(defaultSecurityDeposit);
ignoreSecurityDepositStringListener = true;
buyerSecurityDeposit.set(FormattingUtils.formatToPercent(dataModel.getBuyerSecurityDeposit().get()));
ignoreSecurityDepositStringListener = false;
Expand All @@ -915,7 +915,7 @@ void onFocusOutBuyerSecurityDepositTextField(boolean oldValue, boolean newValue)
}

private void applyBuyerSecurityDepositOnFocusOut() {
setBuyerSecurityDepositToModel(true);
setBuyerSecurityDepositToModel();
ignoreSecurityDepositStringListener = true;
buyerSecurityDeposit.set(FormattingUtils.formatToPercent(dataModel.getBuyerSecurityDeposit().get()));
ignoreSecurityDepositStringListener = false;
Expand Down Expand Up @@ -1146,21 +1146,19 @@ private void setVolumeToModel() {
}
}

private void setBuyerSecurityDepositToModel(boolean persistPreference) {
private void setBuyerSecurityDepositToModel() {
if (buyerSecurityDeposit.get() != null && !buyerSecurityDeposit.get().isEmpty()) {
dataModel.setBuyerSecurityDeposit(ParsingUtils.parsePercentStringToDouble(buyerSecurityDeposit.get()),
persistPreference);
dataModel.setBuyerSecurityDeposit(ParsingUtils.parsePercentStringToDouble(buyerSecurityDeposit.get()));
} else {
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent(),
persistPreference);
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent());
}
}

private void validateAndSetBuyerSecurityDepositToModel() {
// If the security deposit in the model is not valid percent
String value = FormattingUtils.formatToPercent(dataModel.getBuyerSecurityDeposit().get());
if (!securityDepositValidator.validate(value).isValid) {
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent(), false);
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent());
}
}

Expand Down

0 comments on commit 37ce52b

Please sign in to comment.