Newer
Older
import React, { Component } from 'react'
mashazyu
committed
import PropTypes from 'prop-types'
import { Alert, StyleSheet, View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import AppTextInput from '../../common/app-text-input'
import Button from '../../common/button'
import { requestHash, openDb } from '../../../db'
import settings from '../../../i18n/en/settings'
import { shared } from '../../../i18n/en/labels'
export default class ConfirmWithPassword extends Component {
constructor() {
super()
this.state = { password: null }
nodejs.channel.addListener('password-check', this.checkPassword, this)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
}
componentWillUnmount() {
nodejs.channel.removeListener('password-check', this.checkPassword)
}
resetPasswordInput = () => {
this.setState({ password: null })
}
onIncorrectPassword = () => {
Alert.alert(
shared.incorrectPassword,
shared.incorrectPasswordMessage,
[{
text: shared.cancel,
onPress: this.props.onCancel
}, {
text: shared.tryAgain,
onPress: this.resetPasswordInput
}]
)
}
checkPassword = async hash => {
try {
await openDb(hash)
this.props.onSuccess()
} catch (err) {
this.onIncorrectPassword()
}
}
handlePasswordInput = (password) => {
this.setState({ password })
}
initPasswordCheck = () => {
requestHash('password-check', this.state.password)
}
render() {
const { password } = this.state
const labels = settings.passwordSettings
const isPassword = password !== null
<React.Fragment>
<AppTextInput
onChangeText={this.handlePasswordInput}
placeholder={labels.enterCurrent}
value={password}
<View style={styles.container}>
<Button onPress={this.props.onCancel}>
<Button
disabled={!isPassword}
isCTA={isPassword}
onPress={this.initPasswordCheck}
>
mashazyu
committed
}
ConfirmWithPassword.propTypes = {
onSuccess: PropTypes.func,
onCancel: PropTypes.func