Skip to content
Snippets Groups Projects
Commit 0a957044 authored by mashazyu's avatar mashazyu Committed by Sofiya Tepikin
Browse files

Reuse ConfirmWithPassword component in DeletePassword component

parent 5d29bcdc
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react' import React, { Component } from 'react'
import {
View,
TouchableOpacity
} from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import AppText from '../../app-text'
import styles from '../../../styles'
import labels from '../../../i18n/en/settings' import labels from '../../../i18n/en/settings'
import { requestHash, changeEncryptionAndRestartApp } from '../../../db' import { changeEncryptionAndRestartApp } from '../../../db'
import PasswordField from './password-field' import ConfirmWithPassword from '../common/confirm-with-password'
import showBackUpReminder from './show-backup-reminder' import SettingsButton from '../settings-button'
import checkCurrentPassword from './check-current-password'
export default class DeletePassword extends Component { export default class DeletePassword extends Component {
constructor() { constructor() {
super() super()
this.state = { this.state = {
enteringCurrentPassword: false, enteringCurrentPassword: false
currentPassword: null
} }
nodejs.channel.addListener(
'pre-delete-pw-check',
this.removeEncryption,
this
)
} }
componentWillUnmount() { startConfirmWithPassword = () => {
nodejs.channel.removeListener('pre-delete-pw-check', this.removeEncryption) this.setState({ enteringCurrentPassword: true })
} }
removeEncryption = async hash => { startDeletePassword = async () => {
const passwordIsCorrect = await checkCurrentPassword({ await changeEncryptionAndRestartApp()
hash, }
onTryAgain: () => this.setState({currentPassword: null}),
onCancel: () => this.setState({
enteringCurrentPassword: false,
currentPassword: null
})
})
if (passwordIsCorrect) await changeEncryptionAndRestartApp() cancelConfirmationWithPassword = () => {
this.setState({ enteringCurrentPassword: false })
} }
render() { render() {
const { enteringCurrentPassword } = this.state
if (enteringCurrentPassword) {
return (
<ConfirmWithPassword
onSuccess={this.startDeletePassword}
onCancel={this.cancelConfirmationWithPassword}
/>
)
}
return ( return (
<View> <SettingsButton onPress={this.startConfirmWithPassword} >
{this.state.enteringCurrentPassword && {labels.passwordSettings.deletePassword}
<PasswordField </SettingsButton>
onChangeText={val => this.setState({ currentPassword: val })}
value={this.state.currentPassword}
placeholder={labels.passwordSettings.enterCurrent}
/>
}
<TouchableOpacity
onPress={() => {
if (!this.state.enteringCurrentPassword) {
showBackUpReminder(() => {
this.setState({ enteringCurrentPassword: true })
}, true)
} else {
requestHash('pre-delete-pw-check', this.state.currentPassword)
}
}}
disabled={
this.state.enteringCurrentPassword &&
!this.state.currentPassword
}
style={styles.settingsButton}
>
<AppText style={styles.settingsButtonText}>
{labels.passwordSettings.deletePassword}
</AppText>
</TouchableOpacity>
</View>
) )
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment