Skip to content

Commit

Permalink
Only allow decimal numbers in price text input
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Jan 8, 2025
1 parent 35672c3 commit 590a0b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -211,8 +212,6 @@ void reset() {
}

private static class View extends bisq.desktop.common.view.View<HBox, Model, Controller> {
private static final String NUMERIC_WITH_DECIMAL_REGEX = "\\d*([.,]\\d*)?";

private final ChangeListener<String> textListener;
private final ChangeListener<Boolean> focusListener;
private final ChangeListener<Monetary> amountListener;
Expand Down Expand Up @@ -260,7 +259,8 @@ protected void onViewDetached() {

private void onTextChanged(ObservableValue<? extends String> 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);
}
}
Expand Down

0 comments on commit 590a0b6

Please sign in to comment.