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

[Seedless Onboarding]: Settings password form #2644

Merged
merged 15 commits into from
Oct 23, 2023

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Oct 17, 2023

What it solves

Resolves #2519

How this PR fixes it

  • Updates the design for the password form
  • Adds a password strength check
  • Uses useWallet on the settings page to determine display logic
  • Dispatches events on success/fail when submitting the form

ToDos

  • - Extract strings
  • Update settings page automatically when logging in with google
  • Dispatch notifications on success/fail

How to test it

TBD

Screenshots

Screenshot 2023-10-17 at 11 28 35 Screenshot 2023-10-17 at 11 28 49 Screenshot 2023-10-17 at 11 29 00 Screenshot 2023-10-17 at 11 29 11

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@github-actions
Copy link

github-actions bot commented Oct 17, 2023

Branch preview

✅ Deploy successful!

https://settings_form--walletweb.review-wallet-web.5afe.dev

@github-actions
Copy link

github-actions bot commented Oct 17, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

github-actions bot commented Oct 17, 2023

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74.46% (-0.14% 🔻)
9339/12543
🔴 Branches
48.5% (-0.21% 🔻)
1870/3856
🔴 Functions
56.31% (-0.14% 🔻)
1370/2433
🟡 Lines
76.02% (-0.12% 🔻)
8443/11106
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / PasswordForm.tsx
56.86% 30% 37.5% 59.57%
🔴
... / helper.ts
28.13% 0% 0% 31.03%
🟡
... / PasswordInput.tsx
50% 0% 0% 62.5%

Test suite run success

998 tests passing in 141 suites.

Report generated by 🧪jest coverage report action from 5615d17

const dispatch = useAppDispatch()
const mpcCoreKit = useMPC()
const [passwordStrength, setPasswordStrength] = useState<PasswordStrength>(PasswordStrength.weak)
const [passwordsMatch, setPasswordsMatch] = useState<boolean>(false)
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this to the react hook form validation?

onChange: (event: ChangeEvent<HTMLInputElement>) => {
const confirmNewPW = getValues(PasswordFieldNames.confirmPassword)
const value = event.target.value
setPasswordsMatch(value !== '' && value === confirmNewPW)
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned above: Should we use the form validation for this?

Comment on lines 157 to 161
passwordStrength === PasswordStrength.strong
? css.strongPassword
: passwordStrength === PasswordStrength.medium
? css.mediumPassword
: css.weakPassword
Copy link
Member

Choose a reason for hiding this comment

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

We have two big condition blocks like this:
For the css class and for the label, should we add a Record<PasswordStrength, { label: string, cssClass: string}> mapping?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! I've extracted them into a const. I had to add a ts-ignore for the className though because css module imports don't seem to be typed.

}

// At least 12 characters, one lowercase, one uppercase, one number, one symbol
const strongPassword = new RegExp('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{12,})')
Copy link
Member

Choose a reason for hiding this comment

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

Let's add tests for this component or at least for these RegEx as RegEx are quite error prone.

Copy link
Member Author

Choose a reason for hiding this comment

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

I extracted the logic into a helper function and wrote a few tests for it.


if (mpcCoreKit?.status !== COREKIT_STATUS.LOGGED_IN) {
if (wallet?.label !== ONBOARD_MPC_MODULE_LABEL) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think we are using this check quite frequently across the app.
Should we add a small helper isSocialLogin(wallet)?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

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

The form looks great now!

I have a small suggestion towards how to get rid of the ts-ignore annotations in an elegant way.

Comment on lines 64 to 79
type PasswordStrengthMap = Record<PasswordStrength, { label: string; className: string }>

const passwordStrengthMap: PasswordStrengthMap = {
[PasswordStrength.strong]: {
label: 'Strong',
className: 'strongPassword',
},
[PasswordStrength.medium]: {
label: 'Medium',
className: 'mediumPassword',
},
[PasswordStrength.weak]: {
label: 'Weak',
className: 'weakPassword',
},
}
Copy link
Member

Choose a reason for hiding this comment

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

If you rewrite the PasswordStrengthMap and cast it to const it will fix the type errors below and we can remove the ts-ignores.

I think it also makes sense here as the passwordStrengthMap is effectively readonly and won't be mutated.

Suggested change
type PasswordStrengthMap = Record<PasswordStrength, { label: string; className: string }>
const passwordStrengthMap: PasswordStrengthMap = {
[PasswordStrength.strong]: {
label: 'Strong',
className: 'strongPassword',
},
[PasswordStrength.medium]: {
label: 'Medium',
className: 'mediumPassword',
},
[PasswordStrength.weak]: {
label: 'Weak',
className: 'weakPassword',
},
}
const passwordStrengthMap = {
[PasswordStrength.strong]: {
label: 'Strong',
className: 'strongPassword',
},
[PasswordStrength.medium]: {
label: 'Medium',
className: 'mediumPassword',
},
[PasswordStrength.weak]: {
label: 'Weak',
className: 'weakPassword',
},
} as const

alignItems="center"
gap={1}
mt={1}
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this if we change the map's type slightly (see comment above)

} catch (e) {
const error = asError(e)
logError(ErrorCodes._304, error.message)

dispatch(
showNotification({
Copy link
Member

Choose a reason for hiding this comment

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

Should we display the error inside the modal instead wrapped inside an <ErrorMessage>?
Not sure what is more consistent here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a comment in Figma to check with Design

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

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

Vamos! 🚀

@usame-algan usame-algan merged commit 0140ec0 into web3authcoresdk Oct 23, 2023
7 of 8 checks passed
@usame-algan usame-algan deleted the settings-form branch October 23, 2023 08:31
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants