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

Update number validation to be more strict #1994

Merged
merged 4 commits into from
Apr 6, 2024

Conversation

axpoems
Copy link
Contributor

@axpoems axpoems commented Apr 4, 2024

Based on #1993

  • Use a more strict number validation to prevent cases like "123abc" to be flagged as valid.
    Before:
    image

    After:
    image

  • Force a validation after updating the switch for both min. required rep. and diff. factor. This avoids getting into an inconsistent state when switching back to default with a previous errorLabel.
    Before:
    image

    After:
    image

  • Misc. refactors and improvements.

@axpoems axpoems added bug Something isn't working ui labels Apr 4, 2024
@axpoems axpoems requested a review from HenrikJannsen April 4, 2024 20:42
Copy link
Contributor

@djing-chan djing-chan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See open questions

@@ -152,6 +115,10 @@ protected void eval() {
}
}

private String cleanUpFormatting(String inputText) {
return inputText.replace(",", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately diff. locales use diff. separator here. I am not a fan of those local number formats and we could just use one default number format independent of users locale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be the safest as well. What do you think about using Locale.US as default?
I think ideally we only have the number formatted when the input is in read mode, and then remove the formats when writing, but that adds a lot of unnecessary complexity imo.

private String cleanUpFormatting(String inputText) {
return inputText.replace(",", "");
}

private boolean isNumber(String inputText) {
return inputText.matches("^-?\\d+(\\.\\d+)?$");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that respect any decimal and thousands separator format diff. locals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does respect any decimals, but not the thousands separator (that's why the clean-up first). But we could have it implicitly if we define the locale.

I still see that inputs like this are accepted (although later we ignore the decimals):

image

Therefore I propose just using NumberFormat to validate for now and if we decide on a locale, then we can make it more specific and target those corner cases better. (In another PR)

model.getIgnoreMinRequiredReputationScoreFromSecManager().set(isSelected);
minRequiredReputationScore.validate();
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the update from the model to the switch handled? It was bi-directional binding before not its like a normal binding of switch to model.
I guess we only need it at active to apply the model date to the switch as the model data gets not changed by any other source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. No need to remove it then, let's just use the listener to trigger validation.

@axpoems axpoems force-pushed the imp-number-validation branch from c3d0589 to f727511 Compare April 6, 2024 10:50
@axpoems axpoems force-pushed the imp-number-validation branch from f727511 to 8492f31 Compare April 6, 2024 10:54
Copy link
Contributor

@HenrikJannsen HenrikJannsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@djing-chan djing-chan merged commit 639535f into bisq-network:main Apr 6, 2024
16 checks passed
@axpoems axpoems deleted the imp-number-validation branch April 6, 2024 15:16
@djing-chan djing-chan added this to the 2.0.3 milestone Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants