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

feat: improve the PIN Enter repetition validation rule and add relevant messages #1401

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jian4on
Copy link
Contributor

@jian4on jian4on commented Jan 18, 2025

Summary of Changes

Change the PIN repetition validation to a number type rule 'no_repeated_numbers' to make the repeated-times validation setting more readable

Screenshots, videos, or gifs

N/A

Breaking change guide

The previous 'no_repeated_numbers' was an union type 'boolean | number', it is changed to a simple number. The default validation setting was '0' for allowing any times repeating.
Don't implement boolean value, the number value explanation:
0: Disable the repetition check, e.g. '111111' is allowed
1: Enable the repetition check, '123456' is allowed but '113456' forbidden
2: Enable the repetition check, '113456' is allowed but '111456' forbidden
...

Related Issues

N/A

Pull Request Checklist

Tick all boxes below to demonstrate that you have completed the respective task. If the item does not apply to your this PR check it anyway to make it apparent that there's nothing to do.

  • All commits contain a DCO Signed-off-by line (we use the DCO GitHub app to enforce this)
  • If applicable, screenshots, gifs, or video are included for UI changes
  • If applicable, breaking changes are described above along with how to address them
  • Updated documentation as needed for changed code and new or modified features
  • Added sufficient tests so that overall code coverage is not reduced

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

Pro Tip 🤓

  • Read our contribution guide at least once; it will save you a few review cycles!
  • Your PR will likely not be reviewed until all the above boxes are checked and all automated checks have passed

@jian4on jian4on requested a review from a team as a code owner January 18, 2025 18:28
@jian4on jian4on marked this pull request as draft January 18, 2025 18:29
@jian4on jian4on marked this pull request as ready for review January 20, 2025 14:58
@jian4on jian4on marked this pull request as draft January 20, 2025 18:24
@@ -71,7 +71,7 @@ export const PINRules: PINValidationRules = {
only_numbers: true,
min_length: 6,
max_length: 6,
no_repeated_numbers: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is in draft but if it's doable could we keep the defaults the same and just allow for opt-in behavior with the injectable PINSecurity.rules config we have currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Put both PINSecurity and PINCreationValidation to IoC container, then the wallet variants can customize them without changinf Bifold default validating behavior. I will discuss with team. Thanks @bryce-mcmath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Back to default, but change the validating logic for '0' as 'repeating times' instead of its boolean value, keep the extra message for numbers repeating allowed but the repeating times exceeding the max times rule

Signed-off-by: Jian Wang <[email protected]>
…lidation message and change the logic of '0' in no_repeated_behavior

Signed-off-by: Jian Wang <[email protected]>
@jian4on jian4on changed the title feat: refactor the repetition rule in PINValidation and add relevant messages feat: improve the PIN Enter repetition validation rule and add relevant messages Jan 23, 2025
@jian4on jian4on marked this pull request as ready for review January 23, 2025 22:02
@jian4on jian4on requested a review from bryce-mcmath January 23, 2025 22:02
bryce-mcmath
bryce-mcmath previously approved these changes Jan 24, 2025
Copy link
Contributor

@bryce-mcmath bryce-mcmath left a comment

Choose a reason for hiding this comment

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

I did have one question out of curiosity but it seems to still work either way. Nice going!

noRepeatedNumbers = new RegExp(`(\\d)\\1{${PINRules.no_repeated_numbers - 1},}`)
}

if ('number' === typeof(PINRules.no_repeated_numbers) && PINRules.no_repeated_numbers > 2 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When would the > 2 check be needed at the same time as the string interpolation below is? Wouldn't there only be one case (3) where that condition is satisfied?

@@ -77,7 +77,7 @@ describe('PIN creation validations', () => {
test('PIN with repeated numbers and repeated numbers validation to true, so the validation use the default of two repeated numbers, should return NoRepetitionOfTheSameNumbersValidation as invalid', async () => {
const PINRulesWithRepeatedNumbers = {
...defaultPINRules,
no_repeated_numbers: true,
no_repeated_numbers: 0,
Copy link
Contributor

@jleach jleach Jan 28, 2025

Choose a reason for hiding this comment

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

I think no_ should be change to num_ if it now indicates the number of of repeating values allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jleach Good point, It is type 'boolean | number' now. I changed it to an enum [1,2,3,4 ...] type in the Draft version for discussing and then changed it back. Actually I still think maxRepetition number is an option.
@bryce-mcmath If you think we need more discussion, I will pull this feat back to draft

Copy link
Contributor

Choose a reason for hiding this comment

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

@jian4on ah right, the type changed. num is good I think, we can change the default since the type is changing. maybe just add a note in the "Breaking changes" section of the description of this PR so other teams know what to change to keep their existing behavior

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this will work well. There will be no way to disable the rule unless another flag is added. You can put in a high number but that will then be displayed during password selection, which would be confusing for the user.

…e rule 'max_repeated_numbers', and refactor the test cases relevently

Signed-off-by: Jian Wang <[email protected]>
@jian4on jian4on marked this pull request as draft February 5, 2025 14:26
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 55.61%. Comparing base (aff8281) to head (005976c).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ges/legacy/core/App/utils/PINCreationValidation.ts 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1401      +/-   ##
==========================================
+ Coverage   55.52%   55.61%   +0.08%     
==========================================
  Files         223      227       +4     
  Lines        7985     8039      +54     
  Branches     2241     2273      +32     
==========================================
+ Hits         4434     4471      +37     
- Misses       3528     3544      +16     
- Partials       23       24       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jian4on jian4on marked this pull request as ready for review February 11, 2025 06:10
@jian4on jian4on requested a review from timbl-ont February 11, 2025 14:13
Copy link
Contributor

@bryce-mcmath bryce-mcmath left a comment

Choose a reason for hiding this comment

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

One suggested change that you don't have to make, but it might make sense to do it at the same time - I'll leave it up to you. Nice work, sorry for the wait!

Comment on lines +22 to 23
no_repeated_numbers: number
no_repetition_of_the_two_same_numbers: boolean | number
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably make the same change for the rules below:

Suggested change
no_repeated_numbers: number
no_repetition_of_the_two_same_numbers: boolean | number
no_repeated_numbers: number
no_repetition_of_the_two_same_numbers: number

@bryce-mcmath
Copy link
Contributor

@jleach I think your re-review will be required as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants