-
Notifications
You must be signed in to change notification settings - Fork 2
feat(wallet): add change password view in settings #174
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
Open
evavirseda
wants to merge
12
commits into
develop
Choose a base branch
from
feat/add-change-password-feature
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9f56836
add change password
evavirseda 84c3b2d
add validation
evavirseda d349e0b
fix format
evavirseda 99486a5
minor fix
evavirseda b66c789
Merge branch 'develop' into feat/add-change-password-feature
evavirseda 3fe2fea
trigger vercel deploy
evavirseda f40a70e
apply suggestions
evavirseda 25ec833
Merge branch 'develop' into feat/add-change-password-feature
evavirseda e8ba499
make it scrollable
evavirseda 05c2e88
Merge branch 'develop' into feat/add-change-password-feature
evavirseda 39a0025
Merge branch 'develop' into feat/add-change-password-feature
evavirseda 53b36e6
apply suggestions
evavirseda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@iota/apps-ui-kit': minor | ||
| --- | ||
|
|
||
| fix checkbox alignment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
apps/wallet/src/ui/app/components/menu/content/ChangePasswordSettings.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) 2026 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { useEffect } from 'react'; | ||
| import { useZodForm, toast } from '@iota/core'; | ||
| import { z } from 'zod'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { Button, ButtonHtmlType, ButtonType, Input, InputType } from '@iota/apps-ui-kit'; | ||
| import { Overlay } from '_components'; | ||
| import { Form } from '_src/ui/app/shared/forms/Form'; | ||
| import { CheckboxField } from '_src/ui/app/shared/forms/CheckboxField'; | ||
| import { validatePasswordStrength } from '_src/ui/app/shared/forms/passwordValidation'; | ||
| import { useBackgroundClient } from '_src/ui/app/hooks/useBackgroundClient'; | ||
|
|
||
| const formSchema = z | ||
| .object({ | ||
| currentPassword: z.string().nonempty('Required'), | ||
| newPassword: z | ||
| .string() | ||
| .nonempty('Required') | ||
| .min(8, 'Must be at least 8 characters') | ||
| .superRefine(validatePasswordStrength), | ||
| confirmPassword: z.string().nonempty('Required'), | ||
| confirmed: z.boolean(), | ||
| }) | ||
| .superRefine((data, ctx) => { | ||
| if (data.confirmPassword && data.newPassword !== data.confirmPassword) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| path: ['confirmPassword'], | ||
| message: "Passwords don't match", | ||
| }); | ||
| } | ||
| if (data.currentPassword && data.newPassword === data.currentPassword) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| path: ['newPassword'], | ||
| message: 'New password must be different from current password', | ||
| }); | ||
| } | ||
| if (!data.confirmed) { | ||
| ctx.addIssue({ | ||
| code: z.ZodIssueCode.custom, | ||
| path: ['confirmed'], | ||
| message: 'You must confirm you understand this change', | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| type FormValues = z.infer<typeof formSchema>; | ||
|
|
||
| export function ChangePasswordSettings() { | ||
| const navigate = useNavigate(); | ||
| const backgroundClient = useBackgroundClient(); | ||
|
|
||
| const form = useZodForm({ | ||
| mode: 'all', | ||
| schema: formSchema, | ||
| defaultValues: { | ||
| currentPassword: '', | ||
| newPassword: '', | ||
| confirmPassword: '', | ||
| confirmed: false, | ||
| }, | ||
| }); | ||
|
|
||
| const { | ||
| register, | ||
| watch, | ||
| trigger, | ||
| getValues, | ||
| formState: { isSubmitting, isValid, errors }, | ||
| } = form; | ||
|
|
||
| useEffect(() => { | ||
| const { unsubscribe } = watch((_, { name, type }) => { | ||
| if (type !== 'change') return; | ||
| if (name !== 'newPassword' && getValues('newPassword')) { | ||
| trigger('newPassword'); | ||
| } | ||
| if (name !== 'confirmPassword' && getValues('confirmPassword')) { | ||
| trigger('confirmPassword'); | ||
| } | ||
| }); | ||
| return unsubscribe; | ||
| }, [watch, trigger, getValues]); | ||
|
|
||
| async function handleSubmit(values: FormValues) { | ||
| try { | ||
| await backgroundClient.changePassword({ | ||
| currentPassword: values.currentPassword, | ||
| newPassword: values.newPassword, | ||
| }); | ||
| toast.success('Password updated successfully'); | ||
| navigate(-1); | ||
| } catch (e) { | ||
| toast.error((e as Error)?.message || 'Failed to update password'); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Overlay | ||
| showModal | ||
| title="Change Password" | ||
| closeOverlay={() => navigate('/tokens')} | ||
| showBackButton | ||
| > | ||
| <Form className="flex h-full flex-col gap-y-md" form={form} onSubmit={handleSubmit}> | ||
| <Input | ||
| type={InputType.Password} | ||
| isVisibilityToggleEnabled | ||
| label="Current password" | ||
| placeholder="********" | ||
| errorMessage={errors.currentPassword?.message} | ||
| {...register('currentPassword')} | ||
| data-amp-mask | ||
| /> | ||
| <Input | ||
| type={InputType.Password} | ||
| isVisibilityToggleEnabled | ||
| label="New password" | ||
| placeholder="********" | ||
| errorMessage={errors.newPassword?.message} | ||
| {...register('newPassword')} | ||
| data-amp-mask | ||
| /> | ||
| <Input | ||
| type={InputType.Password} | ||
| isVisibilityToggleEnabled | ||
| label="Confirm new password" | ||
| placeholder="********" | ||
| errorMessage={errors.confirmPassword?.message} | ||
| {...register('confirmPassword')} | ||
| data-amp-mask | ||
| /> | ||
| <div className="flex-1" /> | ||
| <CheckboxField | ||
| name="confirmed" | ||
| label="This password secures all accounts. If I forget it, IOTA cannot restore access" | ||
| /> | ||
| <Button | ||
| type={ButtonType.Primary} | ||
| htmlType={ButtonHtmlType.Submit} | ||
| text="Update Password" | ||
| disabled={!isValid || isSubmitting} | ||
| fullWidth | ||
| /> | ||
| </Form> | ||
| </Overlay> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.