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

ui fixes to buy xmr without deposit #1490

Merged
merged 3 commits into from
Dec 21, 2024
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 @@ -56,6 +56,7 @@
import haveno.core.util.validation.AmountValidator4Decimals;
import haveno.core.util.validation.AmountValidator8Decimals;
import haveno.core.util.validation.InputValidator;
import haveno.core.util.validation.InputValidator.ValidationResult;
import haveno.core.util.validation.MonetaryValidator;
import haveno.core.xmr.wallet.Restrictions;
import haveno.desktop.Navigation;
Expand Down Expand Up @@ -490,6 +491,8 @@ private void createListeners() {
xmrValidator.setMaxTradeLimit(BigInteger.valueOf(dataModel.getMaxTradeLimit()));
if (amount.get() != null) amountValidationResult.set(isXmrInputValid(amount.get()));
updateSecurityDeposit();
setSecurityDepositToModel();
onFocusOutSecurityDepositTextField(true, false); // refresh security deposit field
applyMakerFee();
dataModel.calculateTotalToPay();
updateButtonDisableState();
Expand Down Expand Up @@ -769,7 +772,8 @@ void onFocusOutAmountTextField(boolean oldValue, boolean newValue) {
}
}
}
// We want to trigger a recalculation of the volume

// trigger recalculation of the volume
UserThread.execute(() -> {
onFocusOutVolumeTextField(true, false);
onFocusOutMinAmountTextField(true, false);
Expand Down Expand Up @@ -815,6 +819,11 @@ public void onFocusOutMinAmountTextField(boolean oldValue, boolean newValue) {
}

maybeShowMakeOfferToUnsignedAccountWarning();

// trigger recalculation of the security deposit
UserThread.execute(() -> {
onFocusOutSecurityDepositTextField(true, false);
});
}
}

Expand Down Expand Up @@ -944,11 +953,16 @@ void onFocusOutVolumeTextField(boolean oldValue, boolean newValue) {
if (marketPriceMargin.get() == null && amount.get() != null && volume.get() != null) {
updateMarketPriceToManual();
}

// trigger recalculation of security deposit
UserThread.execute(() -> {
onFocusOutSecurityDepositTextField(true, false);
});
}
}

void onFocusOutSecurityDepositTextField(boolean oldValue, boolean newValue) {
if (oldValue && !newValue) {
if (oldValue && !newValue && !isMinSecurityDeposit.get()) {
InputValidator.ValidationResult result = securityDepositValidator.validate(securityDeposit.get());
securityDepositValidationResult.set(result);
if (result.isValid) {
Expand Down Expand Up @@ -1040,6 +1054,7 @@ public String getTradeAmount() {

public String getSecurityDepositLabel() {
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") :
dataModel.isBuyOffer() ? Res.get("createOffer.setDepositAsBuyer") : Res.get("createOffer.setDeposit");
}
Expand Down Expand Up @@ -1211,7 +1226,7 @@ private void setVolumeToModel() {
}

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()));
} else {
dataModel.setSecurityDepositPct(Restrictions.getDefaultSecurityDepositAsPercent());
Expand Down Expand Up @@ -1282,11 +1297,11 @@ private void updateSpinnerInfo() {

private void updateSecurityDeposit() {
isMinSecurityDeposit.set(dataModel.isMinSecurityDeposit());
securityDepositLabel.set(getSecurityDepositLabel());
if (dataModel.isMinSecurityDeposit()) {
securityDepositLabel.set(Res.get("createOffer.minSecurityDepositUsed"));
securityDeposit.set(HavenoUtils.formatXmr(Restrictions.getMinSecurityDeposit()));
securityDepositValidationResult.set(new ValidationResult(true));
} else {
securityDepositLabel.set(getSecurityDepositLabel());
boolean hasBuyerAsTakerWithoutDeposit = dataModel.buyerAsTakerWithoutDeposit.get() && dataModel.isSellOffer();
securityDeposit.set(FormattingUtils.formatToPercent(hasBuyerAsTakerWithoutDeposit ?
Restrictions.getDefaultSecurityDepositAsPercent() : // use default percent if no deposit from buyer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void initialize() {
paymentMethodComboBox.setCellFactory(GUIUtil.getPaymentMethodCellFactory());
paymentMethodComboBox.setPrefWidth(250);

matchingOffersToggleButton = AwesomeDude.createIconToggleButton(AwesomeIcon.USER, null, "1.3em", null);
matchingOffersToggleButton = AwesomeDude.createIconToggleButton(AwesomeIcon.USER, null, "1.5em", null);
matchingOffersToggleButton.getStyleClass().add("toggle-button-no-slider");
matchingOffersToggleButton.setPrefHeight(27);
Tooltip matchingOffersTooltip = new Tooltip(Res.get("offerbook.matchingOffers"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ private void filterOffers() {
getCurrencyAndMethodPredicate(direction, selectedTradeCurrency).and(getOffersMatchingMyAccountsPredicate()) :
getCurrencyAndMethodPredicate(direction, selectedTradeCurrency);

predicate = predicate.and(offerBookListItem -> offerBookListItem.getOffer().isPrivateOffer() == showPrivateOffers);
// filter private offers
if (direction == OfferDirection.BUY) {
predicate = predicate.and(offerBookListItem -> offerBookListItem.getOffer().isPrivateOffer() == showPrivateOffers);
}

if (!filterText.isEmpty()) {

Expand Down
4 changes: 3 additions & 1 deletion desktop/src/main/java/haveno/desktop/theme-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@
.toggle-button-no-slider {
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
-fx-background-radius: 3;
-fx-background-insets: 0, 1;
}

.toggle-button-no-slider:selected {
-fx-background-color: -bs-color-gray-ddd;
-fx-background-color: -bs-color-gray-bbb;
}
Loading