Skip to content

Commit

Permalink
refactor(component): clean up security center menus
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed Dec 12, 2018
1 parent acd85d0 commit 1948413
Show file tree
Hide file tree
Showing 48 changed files with 462 additions and 534 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PureComponent } from 'react'
import React from 'react'
import styled from 'styled-components'

import ActivityLogging from './ActivityLogging'
Expand All @@ -10,41 +10,16 @@ import WalletAccessTor from './WalletAccessTor'
import TwoStepVerificationRemember from './TwoStepVerificationRemember'
import WalletPassword from './WalletPassword'
import SecondPasswordWallet from './SecondPasswordWallet'
import { IconButton } from 'blockchain-info-components'
import { FormattedMessage } from 'react-intl'

const AdvancedContainer = styled.div`
margin-top: 0 !important;
margin-top: 20px;
border-top: 1px solid #eaeaea;
`
const BackButton = styled(IconButton)`
margin-bottom: 6px;
`

export default class Advanced extends PureComponent {
componentDidMount () {
if (!this.props.showTabs) {
const button = document.getElementById('advanced-button')
const alignToTop = false
button.scrollIntoView(alignToTop)
}
}

export default class Advanced extends React.PureComponent {
render () {
return (
<AdvancedContainer>
{!this.props.showTabs && (
<BackButton
name='left-arrow'
nature='empty'
onClick={() => this.props.setView('security')}
id='advanced-button'
>
<FormattedMessage
id='scenes.securitycenter.advanced.back'
defaultMessage='Back'
/>
</BackButton>
)}
<WalletPassword />
<SecondPasswordWallet />
<TwoStepVerificationRemember />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
IconContainer
} from 'components/Security'

import ChangeEmailSteps from '../Components/ChangeEmailSteps'
import ChangeEmailSteps from './ChangeEmailSteps'
import media from 'services/ResponsiveService'

const EmailExplanation = styled.div``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import GoogleAuth from './GoogleAuth'
import Yubikey from './Yubikey'
import SmsAuth from './SMS'
import { pulse } from 'react-animations'
import Choices from '../Components/Choices/index'
import Choices from './Choices'
import { spacing } from 'services/StyleService'
import media from 'services/ResponsiveService'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react'
import { withRouter } from 'react-router-dom'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { pathOr } from 'ramda'

import { actions, selectors } from 'data'
import BasicSettings from './template'

class SecurityCenterContainer extends React.PureComponent {
state = {
editing: false,
enabling: false,
changeEmail: pathOr(false, ['location', 'state', 'changeEmail'], this.props)
}

componentWillUnmount () {
this.onClose()
}

handleEnable = step => {
this.setState({ enabling: step })
}

onClose = () => {
if (this.state.enabling === 'recovery') {
this.props.settingsActions.removeRecoveryPhrase()
}
this.setState({ enabling: false })
}

render () {
return (
<BasicSettings
progress={1}
data={this.props}
editing={this.state.editing}
enabling={this.state.enabling}
handleEnable={this.handleEnable}
onClose={this.onClose}
changeEmail={this.state.changeEmail}
isMnemonicVerified={this.props.isMnemonicVerified}
/>
)
}
}

const mapStateToProps = state => ({
authType: selectors.core.settings.getAuthType(state),
emailVerified: selectors.core.settings.getEmailVerified(state),
isMnemonicVerified: selectors.core.wallet.isMnemonicVerified(state)
})

const mapDispatchToProps = dispatch => ({
settingsActions: bindActionCreators(actions.modules.settings, dispatch)
})

export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(SecurityCenterContainer)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react'
import styled from 'styled-components'
import { Icon } from 'blockchain-info-components'

import EmailAddress from './EmailAddress'
import TwoStepVerification from './TwoStepVerification'
import WalletRecoveryPhrase from './WalletRecoveryPhrase'

const BodyContainer = styled.div`
display: flex;
flex-direction: column;
justify-content: space-around;
width: 100%;
& > * {
margin-top: 20px;
}
`
const IconContainer = styled.div`
display: flex;
justify-content: flex-end;
margin-bottom: 15px;
`

const SecurityCenter = props => {
const { handleEnable, enabling, changeEmail, onClose } = props

const renderSteps = () => {
if (enabling === 'email') {
return (
<BodyContainer>
<EmailAddress alone={1} goBackOnSuccess={onClose} />
</BodyContainer>
)
}
if (enabling === '2fa') {
return (
<BodyContainer>
<TwoStepVerification alone={1} goBackOnSuccess={onClose} />
</BodyContainer>
)
}
if (enabling === 'recovery') {
return (
<BodyContainer>
<WalletRecoveryPhrase alone={1} goBackOnSuccess={onClose} />
</BodyContainer>
)
}
return (
<BodyContainer>
<EmailAddress
handleEnable={() => handleEnable('email')}
goBackOnSuccess={onClose}
changeEmail={changeEmail}
/>
<TwoStepVerification
handleEnable={() => handleEnable('2fa')}
goBackOnSuccess={onClose}
/>
<WalletRecoveryPhrase
handleEnable={() => handleEnable('recovery')}
goBackOnSuccess={onClose}
/>
</BodyContainer>
)
}

return (
<React.Fragment>
{enabling && (
<IconContainer>
<Icon
name='close'
size='20px'
weight={300}
color='gray-5'
cursor
onClick={onClose}
/>
</IconContainer>
)}
{renderSteps()}
</React.Fragment>
)
}

export default SecurityCenter
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'
import styled from 'styled-components'

import { Text } from 'blockchain-info-components'

const Wrapper = styled.div`
display: flex;
flex-direction: row;
background-color: ${props => props.theme['white-blue']};
width: 100%;
height: 50px;
border-bottom: 1px solid #eaeaea;
padding: 0 30px;
`
const TabList = styled.div`
display: flex;
flex-direction: row;
align-items: center;
div:first-of-type {
margin-right: 25px;
}
`
const Tab = styled(Text)`
cursor: pointer;
border-bottom: ${props => (props.active ? '1px solid black' : null)};
opacity: ${props => (props.active ? 1 : 0.3)};
text-transform: uppercase;
`

class MenuContainer extends React.PureComponent {
render () {
const { activeTab, setActiveTab } = this.props

return (
<Wrapper>
<TabList>
<Tab
active={activeTab === 'basic'}
onClick={() => {
setActiveTab('basic')
}}
>
<FormattedMessage
id='scenes.securitycenter.menu.basic'
defaultMessage='Basic'
/>
</Tab>
<Tab
active={activeTab === 'advanced'}
onClick={() => {
setActiveTab('advanced')
}}
>
<FormattedMessage
id='scenes.securitycenter.menu.advanced'
defaultMessage='Advanced'
/>
</Tab>
</TabList>
</Wrapper>
)
}
}

export default MenuContainer

0 comments on commit 1948413

Please sign in to comment.