Skip to content

Commit

Permalink
feat(wallet): add second password check
Browse files Browse the repository at this point in the history
  • Loading branch information
tbuchann committed Apr 24, 2020
1 parent 62c8a43 commit 1890ff8
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const CLEAR_SHOWN_BTC_PRIV_KEY = '@COMPONENT.CLEAR_SHOWN_BTC_PRIV_KEY'

export const CLEAR_SHOWN_ETH_PRIV_KEY = '@COMPONENT.CLEAR_SHOWN_ETH_PRIV_KEY'

export const CLEAR_SHOWN_ETH_LEGACY_PRIV_KEY =
'@COMPONENT.CLEAR_SHOWN_ETH_LEGACY_PRIV_KEY'

export const CLEAR_SHOWN_XLM_PRIV_KEY = '@COMPONENT.CLEAR_SHOWN_XLM_PRIV_KEY'

export const REMOVE_RECOVERY_PHRASE = '@COMPONENT.REMOVE_RECOVERY_PHRASE'
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ export const clearShownEthPrivateKey = () => ({
type: AT.CLEAR_SHOWN_ETH_PRIV_KEY
})

export const clearShownEthLegacyPrivateKey = () => ({
type: AT.CLEAR_SHOWN_ETH_LEGACY_PRIV_KEY
})

export const clearShownXlmPrivateKey = () => ({
type: AT.CLEAR_SHOWN_ETH_PRIV_KEY
type: AT.CLEAR_SHOWN_XLM_PRIV_KEY
})

export const removeRecoveryPhrase = () => ({ type: AT.REMOVE_RECOVERY_PHRASE })
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const settings = (state = INITIAL_STATE, action) => {
case AT.CLEAR_SHOWN_ETH_PRIV_KEY: {
return dissoc('shownEthPrivKey', state)
}
case AT.CLEAR_SHOWN_ETH_LEGACY_PRIV_KEY: {
return dissoc('shownEthLegacyPrivKey', state)
}
case AT.CLEAR_SHOWN_XLM_PRIV_KEY: {
return dissoc('shownXlmPrivKey', state)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { connect } from 'react-redux'
import { prop } from 'ramda'
import React, { Component } from 'react'

import { actions } from 'data'
Expand All @@ -7,30 +8,51 @@ import ShowEthPrivateKeyTemplate from './template'

class ShowEthPrivateKeyContainer extends Component {
state = {
checkSecondPassword: false,
showQrCode: false
}

componentDidMount () {
if (this.props.isLegacy) {
this.props.fetchLegacyBalance()
}
this.props.showEthPrivateKey(this.props.isLegacy)
this.props.isLegacy
? this.props.fetchLegacyBalance()
: this.props.showEthPrivateKey(this.props.isLegacy)
}

componentWillUnmount () {
this.props.clearShownEthPrivateKey()
this.props.clearShownEthLegacyPrivateKey()
}

toggleQrCode = () => {
if (this.props.secondPasswordEnabled && !this.state.checkSecondPassword) {
this.props.showEthPrivateKey(this.props.isLegacy)
this.setState(prevState => ({
checkSecondPassword: true,
showQrCode: !prevState.showQrCode
}))
} else {
this.setState(prevState => ({
showQrCode: !prevState.showQrCode
}))
}
}

toggleQrCode = () =>
this.setState(prevState => ({
showQrCode: !prevState.showQrCode
}))
checkQrCode = () =>
this.props.isLegacy
? this.state.showQrCode &&
prop('priv', this.props.legacyAddressInfo) &&
prop('priv', this.props.addressInfo)
: this.state.showQrCode &&
(prop('priv', this.props.legacyAddressInfo) ||
prop('priv', this.props.addressInfo))

render () {
const showQrCode = this.checkQrCode()
return (
<ShowEthPrivateKeyTemplate
addressInfo={this.props.addressInfo}
legacyAddressInfo={this.props.legacyAddressInfo}
showQrCode={this.state.showQrCode}
showQrCode={showQrCode}
toggleQrCode={this.toggleQrCode}
/>
)
Expand All @@ -44,6 +66,8 @@ const mapDispatchToProps = dispatch => ({
dispatch(actions.core.data.eth.fetchLegacyBalance()),
showEthPrivateKey: isLegacy =>
dispatch(actions.modules.settings.showEthPrivateKey(isLegacy)),
clearShownEthLegacyPrivateKey: () =>
dispatch(actions.modules.settings.clearShownEthLegacyPrivateKey()),
clearShownEthPrivateKey: () =>
dispatch(actions.modules.settings.clearShownEthPrivateKey())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ export const getData = (state, props) => {
priv: state.securityCenter.shownEthPrivKey
}

return legacyEthAddr
? {
legacyAddressInfo: legacyAddressInfo,
addressInfo: addressInfo,
isLegacy: true
}
: {
legacyAddressInfo: null,
addressInfo: addressInfo,
isLegacy: false
}
return {
addressInfo,
isLegacy: !!legacyEthAddr,
legacyAddressInfo: legacyEthAddr ? legacyAddressInfo : null,
secondPasswordEnabled: selectors.core.wallet.isSecondPasswordOn(state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ import XlmAddresses from './template'

class XlmAddressContainer extends Component {
state = {
checkSecondPassword: false,
showQrCode: false
}

componentDidMount () {
this.props.showXlmPrivateKey()
componentWillUnmount () {
this.props.clearShownXlmPrivateKey()
}

toggleQrCode = () =>
this.setState(prevState => ({
showQrCode: !prevState.showQrCode
}))
toggleQrCode = () => {
if (this.props.secondPasswordEnabled && !this.state.checkSecondPassword) {
this.props.showXlmPrivateKey()
this.setState(prevState => ({
checkSecondPassword: true,
showQrCode: !prevState.showQrCode
}))
} else {
this.setState(prevState => ({
showQrCode: !prevState.showQrCode
}))
}
}

render () {
return (
<XlmAddresses
{...this.props}
privateKey={this.props.priv}
showQrCode={this.state.showQrCode}
showQrCode={this.state.showQrCode && this.props.priv}
toggleQrCode={this.toggleQrCode}
/>
)
Expand All @@ -34,6 +44,8 @@ class XlmAddressContainer extends Component {
const mapStateToProps = (state, ownProps) => getData(state, ownProps)

const mapDispatchToProps = dispatch => ({
clearShownXlmPrivateKey: () =>
dispatch(actions.modules.settings.clearShownXlmPrivateKey()),
showXlmPrivateKey: isLegacy =>
dispatch(actions.modules.settings.showXlmPrivateKey(isLegacy))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export const getData = state => {
.getAccountBalance(accountId, state)
.getOrElse(0)
return {
addr: accountId,
balance: Exchange.convertCoinToCoin({
coin: 'XLM',
value: amount,
baseToStandard: false
}).value,
addr: accountId,
priv: state.securityCenter.shownXlmPrivKey
priv: state.securityCenter.shownXlmPrivKey,
secondPasswordEnabled: selectors.core.wallet.isSecondPasswordOn(state)
}
}

0 comments on commit 1890ff8

Please sign in to comment.