From 35672c3cc03a52e36326d5971cfe0b4cda2816a9 Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:17:19 +0100 Subject: [PATCH 1/5] Only allow decimal numbers in amount text input --- .../components/amount_selection/QuoteAmountInputBox.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java index a46152f46d..8ad3c4f23f 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java @@ -211,6 +211,8 @@ void reset() { } private static class View extends bisq.desktop.common.view.View { + private static final String NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?"; + private final ChangeListener textListener; private final ChangeListener focusListener; private final ChangeListener amountListener; @@ -258,7 +260,7 @@ protected void onViewDetached() { private void onTextChanged(ObservableValue observable, String oldValue, String newValue) { if (model.textInputMaxCharCount.isPresent()) { - if (newValue.length() > model.textInputMaxCharCount.get()) { + if (newValue.length() > model.textInputMaxCharCount.get() || !newValue.matches(NUMERIC_WITH_DECIMAL_REGEX)) { textInput.setText(oldValue); } } From 590a0b67d1e4468f38e2d3ca4495a9bd4e1d80c5 Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:26:50 +0100 Subject: [PATCH 2/5] Only allow decimal numbers in price text input --- .../desktop/main/content/bisq_easy/BisqEasyViewUtils.java | 1 + .../main/content/bisq_easy/components/PriceInputBox.java | 4 +++- .../components/amount_selection/QuoteAmountInputBox.java | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java index 6f25729bf7..4a66a90029 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java @@ -38,6 +38,7 @@ import java.util.List; public class BisqEasyViewUtils { + public static final String NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?"; private static final String[] customPaymentIconIds = { "CUSTOM_PAYMENT_1", "CUSTOM_PAYMENT_2", "CUSTOM_PAYMENT_3", "CUSTOM_PAYMENT_4", "CUSTOM_PAYMENT_5", "CUSTOM_PAYMENT_6"}; diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java index c3efe51f87..24b6041743 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java @@ -18,6 +18,7 @@ package bisq.desktop.main.content.bisq_easy.components; import bisq.desktop.components.controls.MaterialTextField; +import bisq.desktop.main.content.bisq_easy.BisqEasyViewUtils; import javafx.beans.property.StringProperty; import javafx.beans.value.ChangeListener; import javafx.geometry.Insets; @@ -66,7 +67,8 @@ public PriceInputBox(String description, String prompt) { getStyleClass().add("price-input-box"); textInputTextListener = (observable, oldValue, newValue) -> { - if (newValue.length() > INPUT_TEXT_MAX_LENGTH) { + if (newValue.length() > INPUT_TEXT_MAX_LENGTH + || !newValue.matches(BisqEasyViewUtils.NUMERIC_WITH_DECIMAL_REGEX)) { textInputControl.setText(oldValue); } applyFontStyle(textInputControl.getLength()); diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java index 8ad3c4f23f..9b3ddb791e 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java @@ -21,6 +21,7 @@ import bisq.common.monetary.Monetary; import bisq.common.util.MathUtils; import bisq.common.util.StringUtils; +import bisq.desktop.main.content.bisq_easy.BisqEasyViewUtils; import bisq.presentation.formatters.AmountFormatter; import bisq.presentation.parser.AmountParser; import javafx.beans.property.BooleanProperty; @@ -211,8 +212,6 @@ void reset() { } private static class View extends bisq.desktop.common.view.View { - private static final String NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?"; - private final ChangeListener textListener; private final ChangeListener focusListener; private final ChangeListener amountListener; @@ -260,7 +259,8 @@ protected void onViewDetached() { private void onTextChanged(ObservableValue observable, String oldValue, String newValue) { if (model.textInputMaxCharCount.isPresent()) { - if (newValue.length() > model.textInputMaxCharCount.get() || !newValue.matches(NUMERIC_WITH_DECIMAL_REGEX)) { + if (newValue.length() > model.textInputMaxCharCount.get() + || !newValue.matches(BisqEasyViewUtils.NUMERIC_WITH_DECIMAL_REGEX)) { textInput.setText(oldValue); } } From e16b888895cc64b6470ce34dfbeb1ae861d48c89 Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:41:08 +0100 Subject: [PATCH 3/5] Allow negative numbers for percentage price --- .../main/content/bisq_easy/BisqEasyViewUtils.java | 3 ++- .../main/content/bisq_easy/components/PriceInput.java | 4 +++- .../content/bisq_easy/components/PriceInputBox.java | 10 ++++------ .../amount_selection/QuoteAmountInputBox.java | 2 +- .../trade_wizard/price/TradeWizardPriceView.java | 4 +++- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java index 4a66a90029..dc760e01c8 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/BisqEasyViewUtils.java @@ -38,7 +38,8 @@ import java.util.List; public class BisqEasyViewUtils { - public static final String NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?"; + public static final String POSITIVE_NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?"; + public static final String NUMERIC_WITH_DECIMAL_REGEX = "-?\\d*([.,]\\d*)?"; private static final String[] customPaymentIconIds = { "CUSTOM_PAYMENT_1", "CUSTOM_PAYMENT_2", "CUSTOM_PAYMENT_3", "CUSTOM_PAYMENT_4", "CUSTOM_PAYMENT_5", "CUSTOM_PAYMENT_6"}; diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java index 26d15f3e0d..94c8fe6f24 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInput.java @@ -24,6 +24,7 @@ import bisq.common.util.MathUtils; import bisq.desktop.common.threading.UIThread; import bisq.desktop.components.controls.validator.NumberValidator; +import bisq.desktop.main.content.bisq_easy.BisqEasyViewUtils; import bisq.i18n.Res; import bisq.presentation.formatters.PriceFormatter; import bisq.presentation.parser.PriceParser; @@ -266,7 +267,8 @@ public static class View extends bisq.desktop.common.view.View textInputTextListener; - public PriceInputBox(String description, String prompt) { + public PriceInputBox(String description, String prompt, String numericRegex) { super(description, prompt); bg.getStyleClass().setAll("bisq-dual-amount-bg"); @@ -67,8 +66,7 @@ public PriceInputBox(String description, String prompt) { getStyleClass().add("price-input-box"); textInputTextListener = (observable, oldValue, newValue) -> { - if (newValue.length() > INPUT_TEXT_MAX_LENGTH - || !newValue.matches(BisqEasyViewUtils.NUMERIC_WITH_DECIMAL_REGEX)) { + if (newValue.length() > INPUT_TEXT_MAX_LENGTH || !newValue.matches(numericRegex)) { textInputControl.setText(oldValue); } applyFontStyle(textInputControl.getLength()); @@ -76,8 +74,8 @@ public PriceInputBox(String description, String prompt) { initialize(); } - public PriceInputBox(String description) { - this(description, null); + public PriceInputBox(String description, String numericRegex) { + this(description, null, numericRegex); } public void initialize() { diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java index 9b3ddb791e..dd70c7b6e8 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/QuoteAmountInputBox.java @@ -260,7 +260,7 @@ protected void onViewDetached() { private void onTextChanged(ObservableValue observable, String oldValue, String newValue) { if (model.textInputMaxCharCount.isPresent()) { if (newValue.length() > model.textInputMaxCharCount.get() - || !newValue.matches(BisqEasyViewUtils.NUMERIC_WITH_DECIMAL_REGEX)) { + || !newValue.matches(BisqEasyViewUtils.POSITIVE_NUMERIC_WITH_DECIMAL_REGEX)) { textInput.setText(oldValue); } } diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java index 33821f2b8e..a857f33a9b 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/trade_wizard/price/TradeWizardPriceView.java @@ -23,6 +23,7 @@ import bisq.desktop.components.containers.Spacer; import bisq.desktop.components.controls.UnorderedList; import bisq.desktop.components.controls.validator.PercentageValidator; +import bisq.desktop.main.content.bisq_easy.BisqEasyViewUtils; import bisq.desktop.main.content.bisq_easy.components.PriceInput; import bisq.desktop.main.content.bisq_easy.components.PriceInputBox; import bisq.i18n.Res; @@ -80,7 +81,8 @@ public TradeWizardPriceView(TradeWizardPriceModel model, TradeWizardPriceControl pricingModels.getStyleClass().addAll("selection-models", "bisq-text-3"); // Input box - percentageInput = new PriceInputBox(Res.get("bisqEasy.price.percentage.inputBoxText")); + percentageInput = new PriceInputBox(Res.get("bisqEasy.price.percentage.inputBoxText"), + BisqEasyViewUtils.NUMERIC_WITH_DECIMAL_REGEX); percentageInput.setValidator(new PercentageValidator()); percentageInput.textInputSymbolTextProperty().set("%"); VBox fieldsBox = new VBox(20, priceInput.getRoot(), percentageInput); From bf3ad30a4845b5c2aefed640a76a3f04a9e19978 Mon Sep 17 00:00:00 2001 From: axpoems <145597137+axpoems@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:20:55 +0100 Subject: [PATCH 4/5] Fix cropping when using integer numbers in amount text input --- .../amount_selection/AmountSelectionView.java | 33 ++++++++++++++----- .../amount_selection/QuoteAmountInputBox.java | 4 +++ .../src/main/resources/css/bisq_easy.css | 4 +-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/AmountSelectionView.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/AmountSelectionView.java index 223240d4cf..d4a91b5871 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/AmountSelectionView.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/amount_selection/AmountSelectionView.java @@ -40,7 +40,7 @@ public class AmountSelectionView extends View Date: Wed, 8 Jan 2025 09:25:38 +0100 Subject: [PATCH 5/5] Fix cropping when using integers number in price input text --- .../main/content/bisq_easy/components/PriceInputBox.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java index 520c1ce697..74355f3cf4 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/bisq_easy/components/PriceInputBox.java @@ -28,7 +28,7 @@ @Slf4j public class PriceInputBox extends MaterialTextField { public static final int AMOUNT_BOX_HEIGHT = 127; - private static final int INPUT_TEXT_MAX_LENGTH = 15; + private static final int INPUT_TEXT_MAX_LENGTH = 14; private static final String INPUT_TEXT_9_STYLE_CLASS = "input-text-9"; private static final String INPUT_TEXT_10_STYLE_CLASS = "input-text-10"; private static final String INPUT_TEXT_11_STYLE_CLASS = "input-text-11"; @@ -69,7 +69,11 @@ public PriceInputBox(String description, String prompt, String numericRegex) { if (newValue.length() > INPUT_TEXT_MAX_LENGTH || !newValue.matches(numericRegex)) { textInputControl.setText(oldValue); } - applyFontStyle(textInputControl.getLength()); + // If using an integer we need to count one more char since a dot occupies much less space. + int calculatedLength = !textInputControl.getText().contains(".") + ? textInputControl.getLength() + 1 + : textInputControl.getLength(); + applyFontStyle(calculatedLength); }; initialize(); }