Merge branch 'chore/retire-nodejs-mobile' into 'main'

Retire nodejs mobile

See merge request bloodyhealth/drip!541
This commit is contained in:
Lisa
2022-09-25 17:14:15 +00:00
14 changed files with 38 additions and 369 deletions
-2
View File
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react'
import nodejs from 'nodejs-mobile-react-native'
import { getLicenseFlag, saveEncryptionFlag } from '../local-storage'
import { openDb } from '../db'
@@ -28,7 +27,6 @@ export default function AppWrapper() {
}
useEffect(() => {
nodejs.start('main.js')
checkIsLicenseAccepted()
checkIsDbEncrypted()
}, [])
+6 -12
View File
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { Alert, KeyboardAvoidingView, StyleSheet, View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import { SHA512 } from 'jshashes'
import AppPage from './common/app-page'
import AppTextInput from './common/app-text-input'
@@ -9,7 +9,7 @@ import Button from './common/button'
import Header from './header'
import { saveEncryptionFlag } from '../local-storage'
import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
import { deleteDbAndOpenNew, openDb } from '../db'
import { passwordPrompt as labels, shared } from '../i18n/en/labels'
import { Containers, Spacing } from '../styles'
@@ -17,9 +17,10 @@ const cancelButton = { text: shared.cancel, style: 'cancel' }
const PasswordPrompt = ({ enableShowApp }) => {
const [password, setPassword] = useState(null)
const unlockApp = () => requestHash('check-pw', password)
const isPasswordEntered = Boolean(password)
const passHashToDb = async (hash) => {
const unlockApp = async () => {
const hash = new SHA512().hex(password)
const connected = await openDb(hash)
if (!connected) {
@@ -31,16 +32,9 @@ const PasswordPrompt = ({ enableShowApp }) => {
])
return
}
enableShowApp()
}
useEffect(() => {
const listener = nodejs.channel.addListener('check-pw', passHashToDb, this)
return () => listener.remove()
}, [])
const onDeleteDataConfirmation = async () => {
await deleteDbAndOpenNew()
await saveEncryptionFlag(false)
@@ -1,12 +1,12 @@
import React, { useState, useEffect } from 'react'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { Alert, KeyboardAvoidingView, StyleSheet, View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import { SHA512 } from 'jshashes'
import AppTextInput from '../../common/app-text-input'
import Button from '../../common/button'
import { requestHash, openDb } from '../../../db'
import { openDb } from '../../../db'
import { Containers } from '../../../styles'
import settings from '../../../i18n/en/settings'
import { shared } from '../../../i18n/en/labels'
@@ -14,7 +14,8 @@ import { shared } from '../../../i18n/en/labels'
const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
const [password, setPassword] = useState(null)
const checkPassword = async (hash) => {
const checkPassword = async () => {
const hash = new SHA512().hex(password)
try {
await openDb(hash)
onSuccess()
@@ -23,15 +24,6 @@ const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
}
}
useEffect(() => {
const listener = nodejs.channel.addListener(
'password-check',
checkPassword,
this
)
return () => listener.remove()
}, [])
const onIncorrectPassword = () => {
Alert.alert(shared.incorrectPassword, shared.incorrectPasswordMessage, [
{
@@ -45,10 +37,6 @@ const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
])
}
const initPasswordCheck = () => {
requestHash('password-check', password)
}
const labels = settings.passwordSettings
const isPassword = password !== null
@@ -65,7 +53,7 @@ const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
<Button
disabled={!isPassword}
isCTA={isPassword}
onPress={initPasswordCheck}
onPress={checkPassword}
>
{shared.confirmToProceed}
</Button>
@@ -1,35 +1,24 @@
import React, { useState, useEffect } from 'react'
import React, { useState } from 'react'
import { KeyboardAvoidingView, StyleSheet } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import PropTypes from 'prop-types'
import { SHA512 } from 'jshashes'
import AppText from '../../common/app-text'
import AppTextInput from '../../common/app-text-input'
import Button from '../../common/button'
import { requestHash } from '../../../db'
import { Colors, Spacing } from '../../../styles'
import settings from '../../../i18n/en/settings'
const LISTENER_TYPE = 'create-or-change-pw'
const EnterNewPassword = ({ changeEncryptionAndRestart }) => {
const [password, setPassword] = useState('')
const [passwordConfirmation, setPasswordConfirmation] = useState('')
const [shouldShowErrorMessage, setShouldShowErrorMessage] = useState(false)
useEffect(() => {
const listener = nodejs.channel.addListener(
LISTENER_TYPE,
changeEncryptionAndRestart,
this
)
return () => listener.remove()
}, [])
const savePassword = () => {
if (comparePasswords()) {
requestHash(LISTENER_TYPE, password)
const hash = new SHA512().hex(password)
changeEncryptionAndRestart(hash)
} else {
setShouldShowErrorMessage(true)
}