Skip to content

Commit

Permalink
Merge pull request #3057 from axpoems/simplify-trade-wizard-2
Browse files Browse the repository at this point in the history
Consolidate amount and price in create offer wizard
  • Loading branch information
axpoems authored Dec 19, 2024
2 parents 26ec6a5 + dcdeb09 commit 3e1a662
Show file tree
Hide file tree
Showing 32 changed files with 2,271 additions and 1,142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class MaterialTextField extends Pane {
@Getter
protected final Label errorLabel = new Label();
@Getter
private final BisqIconButton iconButton = new BisqIconButton();
protected final BisqIconButton iconButton = new BisqIconButton();
protected final ValidationControl validationControl;
private final BooleanProperty isValid = new SimpleBooleanProperty(false);
private Optional<StringConverter<Number>> stringConverter = Optional.empty();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
import bisq.common.observable.Pin;
import bisq.common.util.MathUtils;
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.components.controls.MaterialTextField;
import bisq.desktop.components.controls.validator.NumberValidator;
import bisq.i18n.Res;
import bisq.presentation.formatters.PriceFormatter;
import bisq.presentation.parser.PriceParser;
import javafx.beans.property.*;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import lombok.Getter;
Expand Down Expand Up @@ -66,6 +73,10 @@ public void setQuote(PriceQuote priceQuote) {
controller.setQuote(priceQuote);
}

public void setPercentage(String percentage) {
controller.setPercentage(percentage);
}

public void setIsTakeOffer() {
controller.model.isEditable = false;
}
Expand Down Expand Up @@ -129,9 +140,14 @@ public void setQuote(PriceQuote priceQuote) {
model.priceQuote.set(priceQuote);
}

public void setPercentage(String percentage) {
model.percentagePriceString.set(percentage);
}

private void updateFromMarketPrice() {
if (model.market != null && model.description.get() == null) {
model.description.set(Res.get("component.priceInput.description", model.market.getMarketCodes()));
model.textInputCurrencyCodes.set(model.market.getMarketCodes());
}
if (model.isEditable) {
setQuoteFromMarketPrice();
Expand All @@ -145,7 +161,9 @@ public void onActivate() {

marketPricePin = marketPriceService.getMarketPriceByCurrencyMap().addObserver(() -> {
// We only set it initially
if (model.priceQuote.get() != null) return;
if (model.priceQuote.get() != null) {
return;
}
UIThread.run(this::setQuoteFromMarketPrice);
});

Expand Down Expand Up @@ -196,7 +214,9 @@ private void onFocusedChanged(boolean isFocused) {
}

private void setQuoteFromMarketPrice() {
if (model.market == null) return;
if (model.market == null) {
return;
}
marketPriceService.findMarketPrice(model.market)
.ifPresent(marketPrice -> model.priceQuote.set(marketPrice.getPriceQuote()));
}
Expand All @@ -209,6 +229,8 @@ private static class Model implements bisq.desktop.common.view.Model {
private Market market;
private boolean isFocused;
private final StringProperty description = new SimpleStringProperty();
private final StringProperty textInputCurrencyCodes = new SimpleStringProperty();
private final StringProperty percentagePriceString = new SimpleStringProperty();
private boolean isEditable = true;
private final BooleanProperty isPriceValid = new SimpleBooleanProperty();
private final BooleanProperty doResetValidation = new SimpleBooleanProperty();
Expand All @@ -222,29 +244,35 @@ public void reset() {
market = null;
isFocused = false;
description.set(null);
textInputCurrencyCodes.set(null);
percentagePriceString.set(null);
isEditable = true;
}
}

public static class View extends bisq.desktop.common.view.View<Pane, Model, Controller> {
private final static int WIDTH = 250;
private final MaterialTextField textInput;
private final PriceInputBox textInput;
private Subscription focusedPin, doResetValidationPin;

private View(Model model, Controller controller, NumberValidator validator) {
super(new VBox(), model, controller);

textInput = new MaterialTextField(model.description.get(), Res.get("component.priceInput.prompt"));
textInput = new PriceInputBox(model.description.get(), Res.get("component.priceInput.prompt"));
textInput.setPrefWidth(WIDTH);
textInput.setValidator(validator);
textInput.conversionPriceSymbolTextProperty().set("%");

root.getChildren().add(textInput);
}

@Override
protected void onViewAttached() {
textInput.descriptionProperty().bind(model.description);
textInput.textInputSymbolTextProperty().bind(model.textInputCurrencyCodes);
textInput.conversionPriceTextProperty().bind(model.percentagePriceString);
textInput.textProperty().bindBidirectional(model.priceString);
textInput.initialize();
focusedPin = EasyBind.subscribe(textInput.textInputFocusedProperty(), controller::onFocusedChanged);
doResetValidationPin = EasyBind.subscribe(model.doResetValidation, doResetValidation -> {
if (doResetValidation != null && doResetValidation) {
Expand All @@ -257,10 +285,13 @@ protected void onViewAttached() {
@Override
protected void onViewDetached() {
textInput.descriptionProperty().unbind();
textInput.textInputSymbolTextProperty().unbind();
textInput.conversionPriceTextProperty().unbind();
textInput.textProperty().unbindBidirectional(model.priceString);
textInput.resetValidation();
textInput.dispose();
focusedPin.unsubscribe();
doResetValidationPin.unsubscribe();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.content.bisq_easy.components;

import bisq.desktop.components.controls.MaterialTextField;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class PriceInputBox extends MaterialTextField {
public final static int AMOUNT_BOX_WIDTH = 340;
public final static int AMOUNT_BOX_HEIGHT = 127;
private final static String INPUT_TEXT_9_STYLE_CLASS = "input-text-9";
private final static String INPUT_TEXT_10_STYLE_CLASS = "input-text-10";
private final static String INPUT_TEXT_11_STYLE_CLASS = "input-text-11";
private final static String INPUT_TEXT_12_STYLE_CLASS = "input-text-12";
private final static String INPUT_TEXT_13_STYLE_CLASS = "input-text-13";
private final static String INPUT_TEXT_14_STYLE_CLASS = "input-text-14";

private final Label textInputSymbolLabel, conversionPriceLabel, conversionPriceLabelSymbol;
private final HBox textInputAndSymbolHBox;
private final ChangeListener<Number> textInputLengthListener;

public PriceInputBox(String description, String prompt) {
super(description, prompt);

bg.getStyleClass().setAll("bisq-dual-amount-bg");

descriptionLabel.setLayoutX(20);
descriptionLabel.setPadding(new Insets(2, 0, 0, 0));
textInputSymbolLabel = new Label();
textInputSymbolLabel.getStyleClass().add("text-input-symbol");
textInputAndSymbolHBox = new HBox(10, textInputControl, textInputSymbolLabel);
textInputAndSymbolHBox.setLayoutY(27);

conversionPriceLabel = new Label();
conversionPriceLabel.getStyleClass().add("conversion-price");
conversionPriceLabelSymbol = new Label();
conversionPriceLabelSymbol.getStyleClass().add("conversion-price-symbol");
HBox conversionPriceBox = new HBox(7, conversionPriceLabel, conversionPriceLabelSymbol);
conversionPriceBox.getStyleClass().add("conversion-price-box");
conversionPriceBox.setLayoutY(97);

getChildren().setAll(bg, conversionPriceBox, line, selectionLine, descriptionLabel, textInputAndSymbolHBox, iconButton, helpLabel, errorLabel);
getStyleClass().add("price-input-box");

textInputLengthListener = (observable, oldValue, newValue) -> applyFontStyle(newValue.intValue());
initialize();
}

public PriceInputBox(String description) {
this(description, null);
}

public void initialize() {
textInputControl.lengthProperty().addListener(textInputLengthListener);
}

public void dispose() {
textInputControl.lengthProperty().removeListener(textInputLengthListener);
}

public final StringProperty textInputSymbolTextProperty() {
return textInputSymbolLabel.textProperty();
}

public final StringProperty conversionPriceTextProperty() {
return conversionPriceLabel.textProperty();
}

public final StringProperty conversionPriceSymbolTextProperty() {
return conversionPriceLabelSymbol.textProperty();
}

private void applyFontStyle(int length) {
textInputAndSymbolHBox.getStyleClass().clear();
textInputAndSymbolHBox.getStyleClass().addAll("text-input-and-units-box",
getFontStyleBasedOnTextLength(length));
}

@Override
protected double getBgHeight() {
return AMOUNT_BOX_HEIGHT;
}

private static String getFontStyleBasedOnTextLength(int charCount) {
if (charCount < 9) {
return INPUT_TEXT_9_STYLE_CLASS;
}
if (charCount == 9) {
return INPUT_TEXT_10_STYLE_CLASS;
}
if (charCount == 10) {
return INPUT_TEXT_11_STYLE_CLASS;
}
if (charCount == 11) {
return INPUT_TEXT_12_STYLE_CLASS;
}
if (charCount == 12) {
return INPUT_TEXT_13_STYLE_CLASS;
}
return INPUT_TEXT_14_STYLE_CLASS;
}
}
Loading

0 comments on commit 3e1a662

Please sign in to comment.