Skip to content
Snippets Groups Projects
Commit 80f08c06 authored by Julia Friesel's avatar Julia Friesel
Browse files

Don't rely on local storage knowing about encryption state

parent 49b1110d
No related branches found
No related tags found
Loading
import React, { Component } from 'react' import React, { Component } from 'react'
import { View, TextInput, TouchableOpacity, Alert, Image } from 'react-native' import { View, TextInput, TouchableOpacity, Alert, Image } from 'react-native'
import nodejs from 'nodejs-mobile-react-native' import nodejs from 'nodejs-mobile-react-native'
import { saveEncryptionFlag } from '../local-storage'
import { AppText } from './app-text' import { AppText } from './app-text'
import { hasEncryptionObservable } from '../local-storage'
import styles from '../styles' import styles from '../styles'
import { passwordPrompt as labels, shared } from './labels' import { passwordPrompt as labels, shared } from './labels'
import { requestHash, deleteDbAndOpenNew, openDb } from '../db' import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
...@@ -13,21 +13,25 @@ export default class PasswordPrompt extends Component { ...@@ -13,21 +13,25 @@ export default class PasswordPrompt extends Component {
this.state = { this.state = {
password: null password: null
} }
hasEncryptionObservable.once(async hasEncryption => {
hasEncryption = JSON.parse(hasEncryption)
if (hasEncryption) {
this.setState({showPasswordPrompt: true})
} else {
await openDb({persistConnection: true})
this.props.showApp()
}
})
nodejs.channel.addListener( nodejs.channel.addListener(
'message', 'message',
this.passHashToDb, this.passHashToDb,
this this
) )
this.tryToOpenDb()
}
async tryToOpenDb() {
try {
await openDb({ persistConnection: true })
await saveEncryptionFlag(false)
} catch (err) {
this.setState({ showPasswordPrompt: true })
await saveEncryptionFlag(true)
return
}
} }
passHashToDb = async msg => { passHashToDb = async msg => {
......
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