diff --git a/components/app-wrapper.js b/components/app-wrapper.js
new file mode 100644
index 0000000..889161c
--- /dev/null
+++ b/components/app-wrapper.js
@@ -0,0 +1,26 @@
+import React, { Component } from 'react'
+import { View } from 'react-native'
+import nodejs from 'nodejs-mobile-react-native'
+import App from './app'
+import PasswordPrompt from './password-prompt'
+
+export default class AppWrapper extends Component {
+ constructor() {
+ super()
+ this.state = {}
+ nodejs.start('main.js')
+ }
+ render() {
+ return (
+
+ {this.state.showApp ?
+
+ :
+ this.setState({showApp: true})}
+ />
+ }
+
+ )
+ }
+}
\ No newline at end of file
diff --git a/components/password-prompt.js b/components/password-prompt.js
index 847859e..d2e7b36 100644
--- a/components/password-prompt.js
+++ b/components/password-prompt.js
@@ -5,25 +5,25 @@ import { AppText } from './app-text'
import { hasEncryptionObservable } from '../local-storage'
import styles from '../styles'
import { passwordPrompt, shared } from './labels'
-import { openDbConnection, requestHash, deleteDbAndOpenNew, openDb } from '../db'
-import App from './app'
+import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
export default class PasswordPrompt extends Component {
- constructor() {
- super()
+ constructor(props) {
+ super(props)
this.state = {
password: null
}
- hasEncryptionObservable.once((hasEncryption) => {
+ hasEncryptionObservable.once(async hasEncryption => {
+ hasEncryption = JSON.parse(hasEncryption)
if (hasEncryption) {
this.setState({showPasswordPrompt: true})
} else {
- openDbConnection('something-wrong')
- this.setState({showApp: true})
+ await openDb({persistConnection: true})
+ console.log(this.props)
+ this.props.onCorrectPassword()
}
})
- nodejs.start('main.js')
nodejs.channel.addListener(
'message',
this.passHashToDb,
@@ -35,8 +35,8 @@ export default class PasswordPrompt extends Component {
msg = JSON.parse(msg)
if (msg.type != 'sha512') return
try {
+ console.log('password prompt opening db')
await openDb({hash: msg.message, persistConnection: true })
- this.setState({ showApp: true })
} catch (err) {
Alert.alert(
shared.incorrectPassword,
@@ -46,7 +46,9 @@ export default class PasswordPrompt extends Component {
onPress: () => this.setState({password: null})
}]
)
+ return
}
+ this.setState({ showApp: true })
}
componentWillUnmount() {
@@ -55,40 +57,34 @@ export default class PasswordPrompt extends Component {
render() {
return (
-
- {this.state.showApp ?
-
- :
-
- {this.state.showPasswordPrompt &&
-
- this.setState({password: val})}
- style={styles.passwordField}
- />
- {
- requestHash(this.state.password)
- }}
- >
-
- { passwordPrompt.title }
-
-
- {
- await deleteDbAndOpenNew()
- this.setState({showApp: true})
- }}
- >
-
- {'Delete old db and make unencrypted new'}
-
-
-
- }
+
+ {this.state.showPasswordPrompt &&
+
+ this.setState({ password: val })}
+ style={styles.passwordField}
+ />
+ {
+ requestHash(this.state.password)
+ }}
+ >
+
+ {passwordPrompt.title}
+
+
+ {
+ await deleteDbAndOpenNew()
+ this.setState({ showApp: true })
+ }}
+ >
+
+ {'Delete old db and make unencrypted new'}
+
+
}
diff --git a/index.js b/index.js
index b17ba73..9ff353c 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,4 @@
import { AppRegistry } from 'react-native'
-import PasswordPrompt from './components/password-prompt'
+import AppWrapper from './components/app-wrapper'
-AppRegistry.registerComponent('home', () => PasswordPrompt)
\ No newline at end of file
+AppRegistry.registerComponent('home', () => AppWrapper)
\ No newline at end of file