Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the calculated security deposit at order entry #4555

Merged
merged 1 commit into from Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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