import React, { Component } from 'react';
import { View, Image, TouchableOpacity } from 'react-native';
import { Icon } from 'react-native-elements';
import Biometric from './class/biometrics';
import PropTypes from 'prop-types';
import Biometrics from 'react-native-biometrics';
import { SafeAreaView } from 'react-navigation';
/** @type {AppStorage} */
const BlueApp = require('./BlueApp');
export default class UnlockWith extends Component {
state = { biometricType: false, isStorageEncrypted: false, isAuthenticating: false };
async componentDidMount() {
let biometricType = false;
const isStorageEncrypted = await BlueApp.storageIsEncrypted();
if ((await Biometric.isBiometricUseCapableAndEnabled()) && !isStorageEncrypted) {
biometricType = await Biometric.biometricType();
}
this.setState({ biometricType, isStorageEncrypted }, async () => {
if (!biometricType) {
await BlueApp.startAndDecrypt();
this.props.onSuccessfullyAuthenticated();
} else if (!isStorageEncrypted && typeof biometricType === 'string') this.unlockWithBiometrics();
});
}
successfullyAuthenticated = () => {
this.props.onSuccessfullyAuthenticated();
};
unlockWithBiometrics = () => {
this.setState({ isAuthenticating: true }, async () => {
if (await Biometric.unlockWithBiometrics()) {
await BlueApp.startAndDecrypt();
return this.props.onSuccessfullyAuthenticated();
}
this.setState({ isAuthenticating: false });
});
};
render() {
if (!this.state.biometricType && !this.state.isStorageEncrypted) {
return ;
}
return (
{this.state.biometricType === Biometrics.TouchID && (
<>
>
)}
{this.state.biometricType === Biometrics.FaceID && (
<>
>
)}
{this.state.biometricType !== false && this.state.isStorageEncrypted && (
)}
{this.state.isStorageEncrypted && (
<>
{
this.setState({ isAuthenticating: true }, async () => {
await BlueApp.startAndDecrypt();
this.props.onSuccessfullyAuthenticated();
});
}}
>
>
)}
);
}
}
UnlockWith.propTypes = {
onSuccessfullyAuthenticated: PropTypes.func,
};