Use jshashes on Confirmation with password

This commit is contained in:
Sofiya Tepikin
2022-09-19 15:07:03 +02:00
parent 0ebadbc92a
commit afc177cb53
@@ -1,12 +1,12 @@
import React, { useState, useEffect } from 'react' import React, { useState } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Alert, KeyboardAvoidingView, StyleSheet, View } from 'react-native' 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 AppTextInput from '../../common/app-text-input'
import Button from '../../common/button' import Button from '../../common/button'
import { requestHash, openDb } from '../../../db' import { openDb } from '../../../db'
import { Containers } from '../../../styles' import { Containers } from '../../../styles'
import settings from '../../../i18n/en/settings' import settings from '../../../i18n/en/settings'
import { shared } from '../../../i18n/en/labels' import { shared } from '../../../i18n/en/labels'
@@ -14,7 +14,8 @@ import { shared } from '../../../i18n/en/labels'
const ConfirmWithPassword = ({ onSuccess, onCancel }) => { const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
const [password, setPassword] = useState(null) const [password, setPassword] = useState(null)
const checkPassword = async (hash) => { const checkPassword = async () => {
const hash = new SHA512().hex(password)
try { try {
await openDb(hash) await openDb(hash)
onSuccess() onSuccess()
@@ -23,15 +24,6 @@ const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
} }
} }
useEffect(() => {
const listener = nodejs.channel.addListener(
'password-check',
checkPassword,
this
)
return () => listener.remove()
}, [])
const onIncorrectPassword = () => { const onIncorrectPassword = () => {
Alert.alert(shared.incorrectPassword, shared.incorrectPasswordMessage, [ 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 labels = settings.passwordSettings
const isPassword = password !== null const isPassword = password !== null
@@ -65,7 +53,7 @@ const ConfirmWithPassword = ({ onSuccess, onCancel }) => {
<Button <Button
disabled={!isPassword} disabled={!isPassword}
isCTA={isPassword} isCTA={isPassword}
onPress={initPasswordCheck} onPress={checkPassword}
> >
{shared.confirmToProceed} {shared.confirmToProceed}
</Button> </Button>