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 May 2, 2020
1 parent bfd66fd commit 891aee7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import EthAddresses from './template'
const isValid = item => !isNil(item) && !isEmpty(item)

type StateType = {
checkSecondPassword: boolean
hasCheckedSecondPassword: boolean
showQrCode: boolean
}

Expand Down Expand Up @@ -41,7 +41,7 @@ type PropsType = LinkStatePropsType & LinkDispatchPropsType & OwnProps

class EthContainer extends Component<PropsType, StateType> {
state = {
checkSecondPassword: false,
hasCheckedSecondPassword: false,
showQrCode: false
}

Expand All @@ -57,32 +57,29 @@ class EthContainer extends Component<PropsType, StateType> {
}

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

checkQrCode = () => {
const { addressInfo, isLegacy, legacyAddressInfo } = this.props

return isLegacy
checkQrCode = ({ addressInfo, isLegacy, legacyAddressInfo }) =>
isLegacy
? isValid(prop('priv', legacyAddressInfo)) &&
isValid(prop('priv', addressInfo))
isValid(prop('priv', addressInfo))
: isValid(prop('priv', legacyAddressInfo)) ||
isValid(prop('priv', addressInfo))
}
isValid(prop('priv', addressInfo))

render () {
const { addressInfo, coin, isLegacy, legacyAddressInfo } = this.props
const checkQrCode = this.checkQrCode()
const checkQrCode = this.checkQrCode(this.props)

return (
<EthAddresses
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'react-redux'
import { isEmpty, isNil, path } from 'ramda'
import { isEmpty, isNil, prop } from 'ramda'
import React, { Component } from 'react'

import { actions } from 'data'
Expand All @@ -9,7 +9,7 @@ import XlmAddresses from './template'
const isValid = item => !isNil(item) && !isEmpty(item)

type StateType = {
checkSecondPassword: boolean
hasCheckedSecondPassword: boolean
showQrCode: boolean
}

Expand Down Expand Up @@ -39,7 +39,7 @@ type PropsType = LinkStatePropsType & LinkDispatchPropsType & OwnProps

class XlmContainer extends Component<PropsType, StateType> {
state = {
checkSecondPassword: false,
hasCheckedSecondPassword: false,
showQrCode: false
}

Expand All @@ -48,25 +48,22 @@ class XlmContainer extends Component<PropsType, StateType> {
}

toggleQrCode = () => {
if (!this.state.checkSecondPassword) {
this.props.showXlmPrivateKey()

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

checkQrCode = () => isValid(path(['addressInfo', 'priv'], this.props))

render () {
const { addressInfo, coin } = this.props
const checkQrCode = this.checkQrCode()
const checkQrCode = isValid(prop('priv', addressInfo))

return (
<XlmAddresses
Expand Down

0 comments on commit 891aee7

Please sign in to comment.