7 changed files with 350 additions and 181 deletions
@ -1,93 +1,169 @@ |
|||||
// UNTIL IS NEEDED SET PASSWORD STEP IS COMMENTED OUT
|
// @flow
|
||||
|
|
||||
// // @flow
|
import React, { PureComponent, Fragment } from 'react' |
||||
//
|
import bcrypt from 'bcryptjs' |
||||
// import React, { PureComponent } from 'react'
|
import { colors } from 'styles/theme' |
||||
// import bcrypt from 'bcryptjs'
|
import styled from 'styled-components' |
||||
//
|
import { radii } from 'styles/theme' |
||||
// import { setEncryptionKey } from 'helpers/db'
|
|
||||
//
|
import { setEncryptionKey } from 'helpers/db' |
||||
// import Box from 'components/base/Box'
|
|
||||
// import Button from 'components/base/Button'
|
import Box from 'components/base/Box' |
||||
//
|
import Button from 'components/base/Button' |
||||
// import IconSetPassword from 'icons/onboarding/SetPassword'
|
|
||||
// import PasswordModal from 'components/SettingsPage/PasswordModal'
|
import PasswordModal from 'components/SettingsPage/PasswordModal' |
||||
// import OnboardingFooter from '../OnboardingFooter'
|
import OnboardingFooter from '../OnboardingFooter' |
||||
//
|
import IconChevronRight from 'icons/ChevronRight' |
||||
// import type { StepProps } from '..'
|
import { ErrorMessageInput } from 'components/base/Input' |
||||
//
|
|
||||
// import { Title, Description } from '../helperComponents'
|
import PasswordForm from '../../SettingsPage/PasswordForm' |
||||
//
|
import type { StepProps } from '..' |
||||
// type State = {
|
|
||||
// isPasswordModalOpened: boolean,
|
import { Title, Description, DisclaimerBox, Inner } from '../helperComponents' |
||||
// isPasswordEnabled: boolean,
|
|
||||
// }
|
type State = { |
||||
//
|
currentPassword: string, |
||||
// class SetPassword extends PureComponent<StepProps, State> {
|
newPassword: string, |
||||
// state = {
|
confirmPassword: string, |
||||
// isPasswordModalOpened: false,
|
incorrectPassword: boolean, |
||||
// isPasswordEnabled: false,
|
submitError: boolean, |
||||
// }
|
} |
||||
//
|
|
||||
// handleOpenPasswordModal = () => {
|
const INITIAL_STATE = { |
||||
// this.setState({ isPasswordModalOpened: true })
|
currentPassword: '', |
||||
// }
|
newPassword: '', |
||||
// handleClosePasswordModal = () => {
|
confirmPassword: '', |
||||
// this.setState({ isPasswordModalOpened: false })
|
incorrectPassword: false, |
||||
// }
|
submitError: false, |
||||
// handleChangePassword = (password: string) => {
|
} |
||||
// window.requestIdleCallback(() => {
|
|
||||
// setEncryptionKey('accounts', password)
|
class SetPassword extends PureComponent<StepProps, State> { |
||||
// const hash = password ? bcrypt.hashSync(password, 8) : undefined
|
state = INITIAL_STATE |
||||
// this.props.savePassword(hash)
|
|
||||
// })
|
handleSave = (e: SyntheticEvent<HTMLFormElement>) => { |
||||
// }
|
if (e) { |
||||
//
|
e.preventDefault() |
||||
// handleInputChange = (key: string) => (value: string) => {
|
} |
||||
// this.setState({ [key]: value })
|
if (!this.isValid()) { |
||||
// }
|
this.setState({ submitError: true }) |
||||
//
|
return |
||||
// render() {
|
} |
||||
// const { nextStep, prevStep, t } = this.props
|
const { newPassword } = this.state |
||||
// const { isPasswordModalOpened, isPasswordEnabled } = this.state
|
const { nextStep } = this.props |
||||
// return (
|
|
||||
// <Box sticky pt={150}>
|
setEncryptionKey('accounts', newPassword) |
||||
// <Box grow alignItems="center">
|
const hash = newPassword ? bcrypt.hashSync(newPassword, 8) : undefined |
||||
// <Title>{t('onboarding:setPassword.title')}</Title>
|
this.props.savePassword(hash) |
||||
// <Description>{t('onboarding:setPassword.desc')}</Description>
|
nextStep() |
||||
// <IconSetPassword />
|
} |
||||
// <Box style={{ paddingTop: 35 }}>
|
|
||||
// <Button small primary onClick={() => this.handleOpenPasswordModal()}>
|
handleInputChange = (key: string) => (value: string) => { |
||||
// Set Password
|
if (this.state.incorrectPassword) { |
||||
// </Button>
|
this.setState({ incorrectPassword: false }) |
||||
// </Box>
|
} |
||||
// {/* we might not be able to re-use what we have currently without modifications
|
this.setState({ [key]: value }) |
||||
// the title and descriptions are not dynamic, we might need deffirent size as well */}
|
} |
||||
// {isPasswordModalOpened && (
|
|
||||
// <PasswordModal
|
handleReset = () => this.setState(INITIAL_STATE) |
||||
// t={t}
|
|
||||
// isOpened={isPasswordModalOpened}
|
isValid = () => { |
||||
// onClose={this.handleClosePasswordModal}
|
const { newPassword, confirmPassword } = this.state |
||||
// onChangePassword={this.handleChangePassword}
|
return newPassword === confirmPassword ? true : false |
||||
// isPasswordEnabled={isPasswordEnabled}
|
} |
||||
// currentPasswordHash=""
|
|
||||
// />
|
render() { |
||||
// )}
|
const { nextStep, prevStep, t, savePassword, settings } = this.props |
||||
// <Box onClick={() => nextStep()} style={{ padding: 15 }}>
|
const { |
||||
// <Button>Skip this step</Button>
|
newPassword, |
||||
// </Box>
|
currentPassword, |
||||
// </Box>
|
incorrectPassword, |
||||
// <OnboardingFooter
|
confirmPassword, |
||||
// horizontal
|
submitError, |
||||
// align="center"
|
} = this.state |
||||
// flow={2}
|
|
||||
// t={t}
|
const isPasswordEnabled = settings.password.isEnabled === true |
||||
// nextStep={nextStep}
|
|
||||
// prevStep={prevStep}
|
const disclaimerNotes = [ |
||||
// />
|
{ |
||||
// </Box>
|
key: 'note1', |
||||
// )
|
icon: <IconChevronRight size={12} style={{ color: colors.smoke }} />, |
||||
// }
|
desc: t('onboarding:writeSeed.disclaimer.note1'), |
||||
// }
|
}, |
||||
//
|
{ |
||||
// export default SetPassword
|
key: 'note2', |
||||
|
icon: <IconChevronRight size={12} style={{ color: colors.smoke }} />, |
||||
|
desc: t('onboarding:writeSeed.disclaimer.note2'), |
||||
|
}, |
||||
|
{ |
||||
|
key: 'note3', |
||||
|
icon: <IconChevronRight size={12} style={{ color: colors.smoke }} />, |
||||
|
desc: t('onboarding:writeSeed.disclaimer.note3'), |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
return ( |
||||
|
<Box sticky pt={50}> |
||||
|
<Box grow alignItems="center" justify="center"> |
||||
|
<Fragment> |
||||
|
<Box mb={3} alignItems="center"> |
||||
|
<Title>{t('onboarding:setPassword.title')}</Title> |
||||
|
<Description style={{ maxWidth: 620 }}> |
||||
|
{t('onboarding:setPassword.desc')} |
||||
|
</Description> |
||||
|
</Box> |
||||
|
<Box align="center" mt={2}> |
||||
|
<PasswordForm |
||||
|
onSubmit={this.handleSave} |
||||
|
isPasswordEnabled={isPasswordEnabled} |
||||
|
newPassword={newPassword} |
||||
|
currentPassword={currentPassword} |
||||
|
confirmPassword={confirmPassword} |
||||
|
incorrectPassword={incorrectPassword} |
||||
|
onChange={this.handleInputChange} |
||||
|
t={t} |
||||
|
/> |
||||
|
{!this.isValid() && ( |
||||
|
<ErrorMessageInput style={{ width: 300 }}> |
||||
|
{t('password:errorMessageNotMatchingPassword')} |
||||
|
</ErrorMessageInput> |
||||
|
)} |
||||
|
<DisclaimerBox mt={6} disclaimerNotes={disclaimerNotes} /> |
||||
|
</Box> |
||||
|
</Fragment> |
||||
|
</Box> |
||||
|
|
||||
|
<CustomFooter> |
||||
|
<Button padded outlineGrey onClick={() => prevStep()}> |
||||
|
{t('common:back')} |
||||
|
</Button> |
||||
|
<Box horizontal ml="auto"> |
||||
|
<Button padded disabled={false} onClick={() => nextStep()} mx={2}> |
||||
|
Skip This Step |
||||
|
</Button> |
||||
|
<Button |
||||
|
padded |
||||
|
onClick={this.handleSave} |
||||
|
disabled={!this.isValid() || !newPassword.length || !confirmPassword.length} |
||||
|
primary |
||||
|
> |
||||
|
{t('common:continue')} |
||||
|
</Button> |
||||
|
</Box> |
||||
|
</CustomFooter> |
||||
|
</Box> |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default SetPassword |
||||
|
|
||||
|
const CustomFooter = styled(Box).attrs({ |
||||
|
px: 5, |
||||
|
py: 3, |
||||
|
horizontal: true, |
||||
|
align: 'center', |
||||
|
})` |
||||
|
border-top: 1px solid ${p => p.theme.colors.lightFog}; |
||||
|
border-bottom-left-radius: ${radii[1]}px; |
||||
|
border-bottom-right-radius: ${radii[1]}px; |
||||
|
` |
||||
|
@ -0,0 +1,92 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React, { PureComponent, Fragment } from 'react' |
||||
|
import { connect } from 'react-redux' |
||||
|
import bcrypt from 'bcryptjs' |
||||
|
|
||||
|
import Box from 'components/base/Box' |
||||
|
import Button from 'components/base/Button' |
||||
|
import InputPassword from 'components/base/InputPassword' |
||||
|
import Label from 'components/base/Label' |
||||
|
import { ErrorMessageInput } from 'components/base/Input' |
||||
|
|
||||
|
import type { T } from 'types/common' |
||||
|
|
||||
|
type Props = { |
||||
|
t: T, |
||||
|
isPasswordEnabled: boolean, |
||||
|
|
||||
|
currentPassword: string, |
||||
|
newPassword: string, |
||||
|
confirmPassword: string, |
||||
|
incorrectPassword: boolean, |
||||
|
onSubmit: Function, |
||||
|
onChange: Function, |
||||
|
} |
||||
|
|
||||
|
class PasswordForm extends PureComponent<Props> { |
||||
|
render() { |
||||
|
const { |
||||
|
t, |
||||
|
isPasswordEnabled, |
||||
|
currentPassword, |
||||
|
newPassword, |
||||
|
incorrectPassword, |
||||
|
confirmPassword, |
||||
|
onChange, |
||||
|
onSubmit, |
||||
|
} = this.props |
||||
|
|
||||
|
return ( |
||||
|
<form onSubmit={onSubmit}> |
||||
|
<Box px={7} mt={4} flow={3}> |
||||
|
{isPasswordEnabled && ( |
||||
|
<Box flow={1}> |
||||
|
<Label htmlFor="currentPassword">{t('password:currentPassword.label')}</Label> |
||||
|
<InputPassword |
||||
|
autoFocus |
||||
|
type="password" |
||||
|
placeholder={t('password:currentPassword.placeholder')} |
||||
|
id="currentPassword" |
||||
|
onChange={onChange('currentPassword')} |
||||
|
value={currentPassword} |
||||
|
/> |
||||
|
{incorrectPassword && ( |
||||
|
<ErrorMessageInput>{t('password:errorMessageIncorrectPassword')}</ErrorMessageInput> |
||||
|
)} |
||||
|
</Box> |
||||
|
)} |
||||
|
<Box flow={1}> |
||||
|
{isPasswordEnabled && ( |
||||
|
<Label htmlFor="newPassword">{t('password:newPassword.label')}</Label> |
||||
|
)} |
||||
|
<InputPassword |
||||
|
style={{ mt: 4, width: 240 }} |
||||
|
autoFocus |
||||
|
placeholder={t('password:newPassword.placeholder')} |
||||
|
id="newPassword" |
||||
|
onChange={onChange('newPassword')} |
||||
|
value={newPassword} |
||||
|
// withStrength
|
||||
|
/> |
||||
|
</Box> |
||||
|
<Box flow={1}> |
||||
|
{isPasswordEnabled && ( |
||||
|
<Label htmlFor="confirmPassword">{t('password:confirmPassword.label')}</Label> |
||||
|
)} |
||||
|
<InputPassword |
||||
|
style={{ width: 240 }} |
||||
|
placeholder={t('password:confirmPassword.placeholder')} |
||||
|
id="confirmPassword" |
||||
|
onChange={onChange('confirmPassword')} |
||||
|
value={confirmPassword} |
||||
|
// withStrength
|
||||
|
/> |
||||
|
</Box> |
||||
|
</Box> |
||||
|
</form> |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default PasswordForm |
Loading…
Reference in new issue