-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PasswordProtect for SeedPhrase and PrivateKey pages
Fixed Header and ChangePasscode styles
- Loading branch information
1 parent
f9f2c7c
commit c43caef
Showing
18 changed files
with
174 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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
14 changes: 10 additions & 4 deletions
14
packages/browser-wallet/src/popup/popupX/pages/ChangePasscode/ChangePasscode.scss
This file contains 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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
.change-passcode-x { | ||
.divider { | ||
display: block; | ||
margin: rem(16px) 0 rem(24px) 0; | ||
border-bottom: 1px solid rgba($color-white, 0.1); | ||
.change-passcode-page__form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: rem(8px); | ||
|
||
.divider { | ||
display: block; | ||
margin: rem(8px) 0 rem(16px) 0; | ||
border-bottom: 1px solid rgba($color-white, 0.1); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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
5 changes: 5 additions & 0 deletions
5
packages/browser-wallet/src/popup/popupX/shared/PasswordProtect/PasswordProtect.scss
This file contains 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 @@ | ||
.confirm-password-x { | ||
#confirm-password-form { | ||
margin-top: rem(30px); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/browser-wallet/src/popup/popupX/shared/PasswordProtect/PasswordProtect.tsx
This file contains 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,79 @@ | ||
import React from 'react'; | ||
import { Validate } from 'react-hook-form'; | ||
import { useAtomValue } from 'jotai'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Page from '@popup/popupX/shared/Page'; | ||
import Text from '@popup/popupX/shared/Text'; | ||
import Button from '@popup/popupX/shared/Button'; | ||
import FormPassword from '@popup/popupX/shared/Form/Password'; | ||
import Form from '@popup/popupX/shared/Form/Form'; | ||
import { sessionPasscodeAtom } from '@popup/store/settings'; | ||
import { useForm } from '@popup/shared/Form'; | ||
import { TranslationKeyX } from '@popup/shell/i18n/i18n'; | ||
|
||
type FormValues = { | ||
currentPasscode: string; | ||
}; | ||
|
||
export type PasswordProtectConfigType = { | ||
headingKey: TranslationKeyX; | ||
pageInfoKey: TranslationKeyX; | ||
submitKey: TranslationKeyX; | ||
}; | ||
|
||
type PasswordProtectProps = { | ||
setPasswordConfirmed: (passwordConfirmed: boolean) => void; | ||
config: PasswordProtectConfigType; | ||
}; | ||
|
||
export default function PasswordProtect({ | ||
setPasswordConfirmed, | ||
config: { headingKey, pageInfoKey, submitKey }, | ||
}: PasswordProtectProps) { | ||
const { t: tUse } = useTranslation('x'); | ||
const t = (key: TranslationKeyX) => tUse(key) as unknown as string; | ||
const { t: tPasscode } = useTranslation('x', { keyPrefix: 'sharedX.form.password' }); | ||
const passcode = useAtomValue(sessionPasscodeAtom); | ||
const form = useForm<FormValues>(); | ||
|
||
const handleSubmit = () => { | ||
setPasswordConfirmed(true); | ||
}; | ||
|
||
function validateCurrentPasscode(): Validate<string> { | ||
return (currentPasscode) => (currentPasscode !== passcode.value ? tPasscode('incorrectPasscode') : undefined); | ||
} | ||
|
||
return ( | ||
<Page className="confirm-password-x"> | ||
<Page.Top heading={t(headingKey)} /> | ||
<Page.Main> | ||
<Text.MainRegular>{t(pageInfoKey)}</Text.MainRegular> | ||
<Form id="confirm-password-form" onSubmit={handleSubmit} formMethods={form}> | ||
{(f) => { | ||
return ( | ||
<FormPassword | ||
control={f.control} | ||
name="currentPasscode" | ||
label={tPasscode('currentPasscode')} | ||
className="m-t-10" | ||
rules={{ | ||
required: tPasscode('passcodeRequired'), | ||
validate: validateCurrentPasscode(), | ||
}} | ||
/> | ||
); | ||
}} | ||
</Form> | ||
</Page.Main> | ||
<Page.Footer> | ||
<Button.Main | ||
form="confirm-password-form" | ||
type="submit" | ||
label={t(submitKey)} | ||
disabled={form.formState.isSubmitting} | ||
/> | ||
</Page.Footer> | ||
</Page> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/browser-wallet/src/popup/popupX/shared/PasswordProtect/index.ts
This file contains 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,2 @@ | ||
export { default } from './PasswordProtect'; | ||
export type { PasswordProtectConfigType } from './PasswordProtect'; |
This file contains 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 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
4 changes: 4 additions & 0 deletions
4
packages/browser-wallet/src/popup/popupX/shared/utils/typescriptHelpers.ts
This file contains 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,4 @@ | ||
// Generic type for iterating through nested object keys | ||
export type ObjectPath<T extends object, D extends string = ''> = { | ||
[K in keyof T]: `${D}${Exclude<K, symbol>}${'' | (T[K] extends object ? ObjectPath<T[K], '.'> : '')}`; | ||
}[keyof T]; |
This file contains 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 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 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