-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onboarding welcome & create-pw redesign
- Loading branch information
1 parent
dcde181
commit f8ab96a
Showing
30 changed files
with
1,323 additions
and
77 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
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
99 changes: 99 additions & 0 deletions
99
components/brave_wallet_ui/common/hooks/use-password-strength.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,99 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { useLib } from './useLib' | ||
|
||
export interface PasswordStrengthResults { | ||
isLongEnough: boolean | ||
containsSpecialChar: boolean | ||
containsUppercase: boolean | ||
containsNumber: boolean | ||
} | ||
|
||
const STRONG_PASSWORD_RESULTS = { | ||
containsNumber: true, | ||
containsSpecialChar: true, | ||
containsUppercase: true, | ||
isLongEnough: true | ||
} as const | ||
|
||
export const usePasswordStrength = () => { | ||
// custom hooks | ||
const { isStrongPassword: checkIsStrongPassword } = useLib() | ||
|
||
// state | ||
const [password, setPassword] = React.useState<string>('') | ||
const [confirmedPassword, setConfirmedPassword] = React.useState<string>('') | ||
const [isStrongPassword, setIsStrongPassword] = React.useState<boolean>(false) | ||
|
||
const onPasswordChanged = React.useCallback(async (value: string) => { | ||
setPassword(value) | ||
const isStrong = await checkIsStrongPassword(value) | ||
setIsStrongPassword(isStrong) | ||
}, [checkIsStrongPassword]) | ||
|
||
const hasPasswordError = React.useMemo(() => { | ||
if (password === '') { | ||
return false | ||
} | ||
return !isStrongPassword | ||
}, [password, isStrongPassword]) | ||
|
||
const hasConfirmedPasswordError = React.useMemo(() => { | ||
if (confirmedPassword === '') { | ||
return false | ||
} else { | ||
return confirmedPassword !== password | ||
} | ||
}, [confirmedPassword, password]) | ||
|
||
// granular results of password strength check | ||
const passwordStrength: PasswordStrengthResults = React.useMemo(() => { | ||
if (isStrongPassword) { | ||
// backend reported password as strong, so all checks passed | ||
return STRONG_PASSWORD_RESULTS | ||
} | ||
|
||
// is at least 7 characters | ||
const isLongEnough = password.length >= 7 | ||
|
||
// contains a special character | ||
const containsSpecialChar = /[-’/`~!#*$@_%+=.,^&(){}[\]|;:”<>?\\]/g.test(password) | ||
|
||
// contains an uppercase character | ||
const containsUppercase = password.toLowerCase() !== password | ||
|
||
// contains a number | ||
const containsNumber = /\d/.test(password) | ||
|
||
return { | ||
isLongEnough, | ||
containsSpecialChar, | ||
containsUppercase, | ||
containsNumber | ||
} | ||
}, [password, isStrongPassword]) | ||
|
||
const isValid = !( | ||
hasConfirmedPasswordError || | ||
hasPasswordError || | ||
password === '' || | ||
confirmedPassword === '' | ||
) | ||
|
||
return { | ||
confirmedPassword, | ||
password, | ||
onPasswordChanged, | ||
setConfirmedPassword, | ||
isStrongPassword, | ||
isValid, | ||
hasConfirmedPasswordError, | ||
hasPasswordError, | ||
checkIsStrongPassword, | ||
passwordStrength | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
components/brave_wallet_ui/components/desktop/steps-navigation/steps-navigation.stories.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,25 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { MemoryRouter as Router, Route } from 'react-router' | ||
|
||
import { StepsNavigation } from './steps-navigation' | ||
|
||
export const Nav = () => { | ||
return <Router> | ||
<Route path={'/:currentStep'}> | ||
{({ match }) => ( | ||
<StepsNavigation | ||
steps={['1', '2', '3']} | ||
currentStep={match?.params.currentStep || '1'} | ||
goBack={() => alert('go back')} | ||
/> | ||
)} | ||
</Route> | ||
</Router> | ||
} | ||
|
||
export default Nav |
63 changes: 63 additions & 0 deletions
63
components/brave_wallet_ui/components/desktop/steps-navigation/steps-navigation.style.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,63 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import styled, { css } from 'styled-components' | ||
import { WalletButton } from '../../shared/style' | ||
|
||
const Font = css` | ||
font-family: Poppins; | ||
font-style: normal; | ||
font-weight: 600; | ||
font-size: 13px; | ||
line-height: 20px; | ||
color: ${(p) => p.theme.color.text02}; | ||
` | ||
|
||
export const Wrapper = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 10fr 1fr; | ||
width: 100%; | ||
margin-bottom: 60px; | ||
` | ||
|
||
export const BackButton = styled(WalletButton)` | ||
${Font} | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
text-align: center; | ||
align-self: flex-start; | ||
color: ${(p) => p.theme.color.text01}; | ||
cursor: pointer; | ||
outline: none; | ||
background: none; | ||
padding: 3px 0px; | ||
line-height: 20px; | ||
letter-spacing: 0.01em; | ||
border: none; | ||
gap: 12px; | ||
` | ||
|
||
export const DotsWrapper = styled.div` | ||
display: flex; | ||
flex: 1; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
align-self: center; | ||
& > * { | ||
display: inline; | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 25px; | ||
margin-right: 16px; | ||
background-color: ${(p) => p.theme.color.divider01}; | ||
} | ||
& > .active { | ||
background-color: ${(p) => p.theme.color.interactive05}; | ||
} | ||
` |
61 changes: 61 additions & 0 deletions
61
components/brave_wallet_ui/components/desktop/steps-navigation/steps-navigation.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,61 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import { getLocale } from '$web-common/locale' | ||
import * as React from 'react' | ||
import { NavLink } from 'react-router-dom' | ||
import { BackIcon } from '../../buy-send-swap/select-header/style' | ||
|
||
import { BackButton, DotsWrapper, Wrapper } from './steps-navigation.style' | ||
|
||
export interface StepsNavigationProps<T extends string> { | ||
readonly steps: T[] | ||
currentStep: T | ||
goBack: () => void | ||
preventSkipAhead?: boolean | ||
} | ||
|
||
export const StepsNavigation: <T extends string>( | ||
props: StepsNavigationProps<T> | ||
) => JSX.Element = ({ | ||
preventSkipAhead, | ||
currentStep, | ||
goBack, | ||
steps | ||
}) => { | ||
const currentStepIndex = steps.findIndex(s => s === currentStep) | ||
|
||
return ( | ||
<Wrapper> | ||
|
||
<BackButton onClick={goBack}> | ||
<BackIcon /> | ||
{getLocale('braveWalletBack')} | ||
</BackButton> | ||
|
||
<DotsWrapper> | ||
{steps.map((stepName, stepIndex) => { | ||
const showLink = stepIndex > currentStepIndex | ||
? !preventSkipAhead | ||
: true | ||
|
||
return showLink | ||
? <NavLink | ||
to={`/${stepName}`} | ||
key={stepName} | ||
isActive={() => currentStep === stepName} | ||
activeClassName="active" | ||
/> | ||
: <div /> | ||
})} | ||
</DotsWrapper> | ||
|
||
<div /> | ||
|
||
</Wrapper> | ||
) | ||
} | ||
|
||
export default StepsNavigation |
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
Oops, something went wrong.