From 07ba5f067756e96b252b4231c10b8d49e5df8621 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Mon, 11 Jun 2018 16:54:54 +0200 Subject: [PATCH] password related changes --- src/components/IsUnlocked.js | 19 +------ src/components/Onboarding/steps/Analytics.js | 34 ++++++----- .../Onboarding/steps/SetPassword.js | 45 +++++---------- .../SettingsPage/DisablePasswordModal.js | 21 +++---- src/components/SettingsPage/PasswordForm.js | 47 ++++++++-------- src/components/SettingsPage/PasswordModal.js | 56 ++++++++++--------- src/components/base/Input/index.js | 7 --- .../modals/AccountSettingRenderBody.js | 6 +- static/i18n/en/common.yml | 1 + static/i18n/en/password.yml | 30 +++++++--- static/i18n/en/settings.yml | 13 ----- 11 files changed, 120 insertions(+), 159 deletions(-) diff --git a/src/components/IsUnlocked.js b/src/components/IsUnlocked.js index 7de2bdf3..562898b9 100644 --- a/src/components/IsUnlocked.js +++ b/src/components/IsUnlocked.js @@ -11,8 +11,6 @@ import type { SettingsState as Settings } from 'reducers/settings' import type { T } from 'types/common' import IconLockScreen from 'icons/LockScreen' -import { ErrorMessageInput } from 'components/base/Input' - import get from 'lodash/get' import { setEncryptionKey } from 'helpers/db' @@ -119,21 +117,13 @@ class IsUnlocked extends Component { } } - handleFocusInput = () => { - if (this._input && this._input !== null) { - this._input.focus() - } - } - - _input: ?HTMLInputElement - render() { const { inputValue, incorrectPassword } = this.state const { isLocked, t } = this.props if (isLocked) { return ( - +
@@ -146,17 +136,12 @@ class IsUnlocked extends Component { (this._input = n)} placeholder={t('common:lockScreen.inputPlaceholder')} type="password" onChange={this.handleChangeInput('password')} value={inputValue.password} + error={incorrectPassword && t('password:errorMessageIncorrectPassword')} /> - {incorrectPassword && ( - - {t('password:errorMessageIncorrectPassword')} - - )}
diff --git a/src/components/Onboarding/steps/Analytics.js b/src/components/Onboarding/steps/Analytics.js index 34584285..2719d2cc 100644 --- a/src/components/Onboarding/steps/Analytics.js +++ b/src/components/Onboarding/steps/Analytics.js @@ -2,8 +2,6 @@ import React, { PureComponent } from 'react' import styled from 'styled-components' -import { connect } from 'react-redux' -import { saveSettings } from 'actions/settings' import Box from 'components/base/Box' import CheckBox from 'components/base/CheckBox' @@ -12,19 +10,21 @@ import OnboardingFooter from '../OnboardingFooter' import type { StepProps } from '..' -const mapDispatchToProps = { saveSettings } - type State = { analyticsToggle: boolean, termsConditionsToggle: boolean, sentryLogsToggle: boolean, } + +const INITIAL_STATE = { + analyticsToggle: false, + termsConditionsToggle: false, + sentryLogsToggle: false, +} + class Analytics extends PureComponent { - state = { - analyticsToggle: false, - termsConditionsToggle: false, - sentryLogsToggle: false, - } + state = INITIAL_STATE + handleSentryLogsToggle = (isChecked: boolean) => { this.setState({ sentryLogsToggle: !this.state.sentryLogsToggle }) this.props.saveSettings({ @@ -40,8 +40,15 @@ class Analytics extends PureComponent { handleTermsToggle = () => { this.setState({ termsConditionsToggle: !this.state.termsConditionsToggle }) } + + handleNavBack = () => { + const { savePassword, prevStep } = this.props + savePassword(undefined) + prevStep() + } + render() { - const { nextStep, prevStep, t } = this.props + const { nextStep, t } = this.props const { analyticsToggle, termsConditionsToggle, sentryLogsToggle } = this.state return ( @@ -85,7 +92,7 @@ class Analytics extends PureComponent { flow={2} t={t} nextStep={nextStep} - prevStep={prevStep} + prevStep={this.handleNavBack} isContinueDisabled={!termsConditionsToggle} />
@@ -93,10 +100,7 @@ class Analytics extends PureComponent { } } -export default connect( - null, - mapDispatchToProps, -)(Analytics) +export default Analytics export const AnalyticsText = styled(Box).attrs({ ff: 'Open Sans|Regular', diff --git a/src/components/Onboarding/steps/SetPassword.js b/src/components/Onboarding/steps/SetPassword.js index 8a50a77d..cbaf9635 100644 --- a/src/components/Onboarding/steps/SetPassword.js +++ b/src/components/Onboarding/steps/SetPassword.js @@ -2,31 +2,26 @@ import React, { PureComponent, Fragment } from 'react' import bcrypt from 'bcryptjs' -import { colors } from 'styles/theme' +import { colors, radii } from 'styles/theme' import styled from 'styled-components' -import { radii } from 'styles/theme' import { setEncryptionKey } from 'helpers/db' import Box from 'components/base/Box' import Button from 'components/base/Button' -import PasswordModal from 'components/SettingsPage/PasswordModal' -import OnboardingFooter from '../OnboardingFooter' import IconChevronRight from 'icons/ChevronRight' -import { ErrorMessageInput } from 'components/base/Input' import PasswordForm from '../../SettingsPage/PasswordForm' import type { StepProps } from '..' -import { Title, Description, DisclaimerBox, Inner } from '../helperComponents' +import { Title, Description, DisclaimerBox } from '../helperComponents' type State = { currentPassword: string, newPassword: string, confirmPassword: string, incorrectPassword: boolean, - submitError: boolean, } const INITIAL_STATE = { @@ -34,7 +29,6 @@ const INITIAL_STATE = { newPassword: '', confirmPassword: '', incorrectPassword: false, - submitError: false, } class SetPassword extends PureComponent { @@ -45,15 +39,15 @@ class SetPassword extends PureComponent { e.preventDefault() } if (!this.isValid()) { - this.setState({ submitError: true }) return } const { newPassword } = this.state - const { nextStep } = this.props + const { nextStep, savePassword } = this.props setEncryptionKey('accounts', newPassword) const hash = newPassword ? bcrypt.hashSync(newPassword, 8) : undefined - this.props.savePassword(hash) + savePassword(hash) + this.handleReset() nextStep() } @@ -68,18 +62,12 @@ class SetPassword extends PureComponent { isValid = () => { const { newPassword, confirmPassword } = this.state - return newPassword === confirmPassword ? true : false + return newPassword === confirmPassword } render() { - const { nextStep, prevStep, t, savePassword, settings } = this.props - const { - newPassword, - currentPassword, - incorrectPassword, - confirmPassword, - submitError, - } = this.state + const { nextStep, prevStep, t, settings } = this.props + const { newPassword, currentPassword, incorrectPassword, confirmPassword } = this.state const isPasswordEnabled = settings.password.isEnabled === true @@ -87,17 +75,17 @@ class SetPassword extends PureComponent { { key: 'note1', icon: , - desc: t('onboarding:writeSeed.disclaimer.note1'), + desc: t('onboarding:setPassword.disclaimer.note1'), }, { key: 'note2', icon: , - desc: t('onboarding:writeSeed.disclaimer.note2'), + desc: t('onboarding:setPassword.disclaimer.note2'), }, { key: 'note3', icon: , - desc: t('onboarding:writeSeed.disclaimer.note3'), + desc: t('onboarding:setPassword.disclaimer.note3'), }, ] @@ -119,15 +107,12 @@ class SetPassword extends PureComponent { currentPassword={currentPassword} confirmPassword={confirmPassword} incorrectPassword={incorrectPassword} + isValid={this.isValid} onChange={this.handleInputChange} t={t} /> - {!this.isValid() && ( - - {t('password:errorMessageNotMatchingPassword')} - - )} - + +
@@ -138,7 +123,7 @@ class SetPassword extends PureComponent { diff --git a/src/components/SettingsPage/PasswordForm.js b/src/components/SettingsPage/PasswordForm.js index c64217b9..29b3e7cd 100644 --- a/src/components/SettingsPage/PasswordForm.js +++ b/src/components/SettingsPage/PasswordForm.js @@ -1,26 +1,22 @@ // @flow -import React, { PureComponent, Fragment } from 'react' -import { connect } from 'react-redux' -import bcrypt from 'bcryptjs' +import React, { PureComponent } from 'react' 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, + isValid: () => boolean, onChange: Function, } @@ -33,54 +29,55 @@ class PasswordForm extends PureComponent { newPassword, incorrectPassword, confirmPassword, + isValid, onChange, onSubmit, } = this.props - + // TODO: adjust design to separate 3 fields return ( {isPasswordEnabled && ( - - + + - {incorrectPassword && ( - {t('password:errorMessageIncorrectPassword')} - )} )} - {isPasswordEnabled && ( - - )} + - {isPasswordEnabled && ( - - )} + 0 && + t('password:errorMessageNotMatchingPassword') + } /> diff --git a/src/components/SettingsPage/PasswordModal.js b/src/components/SettingsPage/PasswordModal.js index 84f6f0a0..d3f6c3ed 100644 --- a/src/components/SettingsPage/PasswordModal.js +++ b/src/components/SettingsPage/PasswordModal.js @@ -1,32 +1,22 @@ // @flow import React, { PureComponent } from 'react' -import { connect } from 'react-redux' import bcrypt from 'bcryptjs' -import { unlock } from 'reducers/application' +import type { T } from 'types/common' 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 { Modal, ModalContent, ModalBody, ModalTitle, ModalFooter } from 'components/base/Modal' -import { ErrorMessageInput } from 'components/base/Input' import PasswordForm from './PasswordForm' -import type { T } from 'types/common' - -const mapDispatchToProps = { - unlock, -} type Props = { t: T, - onClose: Function, - unlock: Function, + onClose: () => void, + onChangePassword: (?string) => void, isPasswordEnabled: boolean, currentPasswordHash: string, - onChangePassword: Function, } type State = { @@ -47,13 +37,15 @@ class PasswordModal extends PureComponent { state = INITIAL_STATE handleSave = (e: SyntheticEvent) => { + const { currentPassword, newPassword } = this.state + if (e) { e.preventDefault() } if (!this.isValid()) { return } - const { currentPassword, newPassword, confirmPassword } = this.state + const { isPasswordEnabled, currentPasswordHash, onChangePassword } = this.props if (isPasswordEnabled) { if (!bcrypt.compareSync(currentPassword, currentPasswordHash)) { @@ -76,14 +68,13 @@ class PasswordModal extends PureComponent { handleReset = () => this.setState(INITIAL_STATE) isValid = () => { - const { newPassword } = this.state - return newPassword + const { newPassword, confirmPassword } = this.state + return newPassword === confirmPassword } render() { const { t, isPasswordEnabled, onClose, ...props } = this.props const { currentPassword, newPassword, incorrectPassword, confirmPassword } = this.state - const isValid = this.isValid() return ( { onClose={onClose} render={({ onClose }) => ( - {t('settings:profile.passwordModalTitle')} + {isPasswordEnabled ? ( + {t('password:changePassword.title')} + ) : ( + {t('password:setPassword.title')} + )} - {t('settings:profile.passwordModalSubtitle')} + {isPasswordEnabled + ? t('password:changePassword.subTitle') + : t('password:setPassword.subTitle')} - {t('settings:profile.passwordModalDesc')} + {isPasswordEnabled + ? t('password:changePassword.desc') + : t('password:setPassword.desc')} { currentPassword={currentPassword} confirmPassword={confirmPassword} incorrectPassword={incorrectPassword} + isValid={this.isValid} onChange={this.handleInputChange} t={t} /> - - @@ -125,7 +130,4 @@ class PasswordModal extends PureComponent { } } -export default connect( - null, - mapDispatchToProps, -)(PasswordModal) +export default PasswordModal diff --git a/src/components/base/Input/index.js b/src/components/base/Input/index.js index b7611c99..62f92a80 100644 --- a/src/components/base/Input/index.js +++ b/src/components/base/Input/index.js @@ -48,13 +48,6 @@ const Base = styled.input.attrs({ } ` -export const ErrorMessageInput = styled(Box).attrs({ - alignItems: 'flex-start', - color: 'alertRed', - ff: 'Open Sans|SemiBold', - fontSize: 3, -})`` - export const Textarea = styled.textarea.attrs({ p: 2, fontSize: 4, diff --git a/src/components/modals/AccountSettingRenderBody.js b/src/components/modals/AccountSettingRenderBody.js index 1ce382ad..4e584e99 100644 --- a/src/components/modals/AccountSettingRenderBody.js +++ b/src/components/modals/AccountSettingRenderBody.js @@ -18,7 +18,7 @@ import Spoiler from 'components/base/Spoiler' import CryptoCurrencyIcon from 'components/CryptoCurrencyIcon' import Box from 'components/base/Box' import Button from 'components/base/Button' -import Input, { ErrorMessageInput } from 'components/base/Input' +import Input from 'components/base/Input' import Select from 'components/base/LegacySelect' import { ModalBody, ModalTitle, ModalFooter, ModalContent } from 'components/base/Modal' @@ -143,10 +143,8 @@ class HelperComp extends PureComponent { onChange={this.handleChangeName} renderLeft={} onFocus={e => this.handleFocus(e, 'accountName')} + error={accountNameError && t('account:settings.accountName.error')} /> - {accountNameError && ( - {t('account:settings.accountName.error')} - )} diff --git a/static/i18n/en/common.yml b/static/i18n/en/common.yml index c5add684..bef533ac 100644 --- a/static/i18n/en/common.yml +++ b/static/i18n/en/common.yml @@ -6,6 +6,7 @@ confirm: Confirm cancel: Cancel delete: Delete continue: Continue +skipThisStep: Skip This Step chooseWalletPlaceholder: Choose a wallet... currency: Currency selectAccount: Select an account diff --git a/static/i18n/en/password.yml b/static/i18n/en/password.yml index a5464044..86148b07 100644 --- a/static/i18n/en/password.yml +++ b/static/i18n/en/password.yml @@ -5,12 +5,24 @@ warning_3: Warning 3 warning_4: Warning 4 errorMessageIncorrectPassword: The password you entered is incorrect. errorMessageNotMatchingPassword: Passwords don't match. -newPassword: - label: New Password - placeholder: New Password -confirmPassword: - label: Confirm Password - placeholder: Confirm Password -currentPassword: - label: Current Password - placeholder: Current Password +inputFields: + newPassword: + label: Password + placeholder: Password + confirmPassword: + label: Confirm Password + placeholder: Confirm Password + currentPassword: + label: Current Password + placeholder: Current Password +changePassword: + title: Edit Password + subTitle: Change your password + desc: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nibh diam. In eget ipsum arcu donec finibus +setPassword: + title: Set Password + subTitle: Set a password to lock your application + desc: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nibh diam. In eget ipsum arcu donec finibus +disablePassword: + title: Disable Password + desc: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nibh diam. diff --git a/static/i18n/en/settings.yml b/static/i18n/en/settings.yml index 2a48bb9d..d28f2a94 100644 --- a/static/i18n/en/settings.yml +++ b/static/i18n/en/settings.yml @@ -23,22 +23,9 @@ currencies: explorer: Blockchain explorer explorerDesc: Lorem ipsum dolor sit amet profile: - username: Username - usernameDesc: Lorem ipsum dolor sit amet password: Password passwordDesc: Lorem ipsum dolor sit amet changePassword: Change password - passwordModalTitle: Password - passwordModalSubtitle: Set a password to lock your application - passwordModalDesc: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nibh diam. - passwordModalPasswordInput: Current password - passwordModalNewPasswordInput: New password - passwordModalRepeatPasswordInput: Repeat password - passwordModalSave: Save - disablePasswordModalTitle: Disable Password - disablePasswordModalDesc: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nibh diam. - disablePasswordModalInput: Current password - disablePasswordModalSave: Save sync: Sync accounts syncDesc: Lorem ipsum dolor sit amet export: Export logs