mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 11:51:52 +03:00
enabled biometric app unlock
This commit is contained in:
parent
9b7d2baaad
commit
be0806f3c8
@ -4,6 +4,7 @@ import { connect } from 'react-redux';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import Config from 'react-native-config';
|
||||
import get from 'lodash/get';
|
||||
import FingerprintScanner from 'react-native-fingerprint-scanner';
|
||||
|
||||
//Contstants
|
||||
import AUTH_TYPE from '../../../constants/authType';
|
||||
@ -47,6 +48,8 @@ import { getUnreadNotificationCount } from '../../../providers/ecency/ecency';
|
||||
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
|
||||
|
||||
class PinCodeContainer extends Component {
|
||||
screenRef = null;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@ -80,6 +83,8 @@ class PinCodeContainer extends Component {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this._processBiometric();
|
||||
}
|
||||
|
||||
_getDataFromStorage = () =>
|
||||
@ -94,6 +99,33 @@ class PinCodeContainer extends Component {
|
||||
});
|
||||
});
|
||||
|
||||
_processBiometric = async () => {
|
||||
try {
|
||||
const {
|
||||
pinCodeParams: { isReset },
|
||||
applicationPinCode,
|
||||
} = this.props;
|
||||
|
||||
if (isReset) {
|
||||
return;
|
||||
}
|
||||
|
||||
const biometryType = await FingerprintScanner.isSensorAvailable();
|
||||
console.log('biometryType is => ', biometryType);
|
||||
|
||||
await FingerprintScanner.authenticate({ description: 'Scan your biometric to continue' });
|
||||
console.log('successfully passed biometric auth');
|
||||
|
||||
//code gets here means biometeric succeeded
|
||||
if (this.screenRef) {
|
||||
const verifiedPin = decryptKey(applicationPinCode, Config.PIN_KEY, this._onDecryptFail);
|
||||
this.screenRef.setPinThroughBiometric(verifiedPin);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Failed to process biometric', err);
|
||||
}
|
||||
};
|
||||
|
||||
//this function updates realm with appropriate master key required for encyrption
|
||||
//this function is important: must run while chaning pin
|
||||
//and even logging in with existing pin code
|
||||
@ -515,12 +547,14 @@ class PinCodeContainer extends Component {
|
||||
|
||||
return (
|
||||
<PinCodeScreen
|
||||
ref={(ref) => (this.screenRef = ref)}
|
||||
informationText={informationText}
|
||||
setPinCode={(pin) => this._setPinCode(pin, isReset)}
|
||||
showForgotButton={!isOldPinVerified}
|
||||
username={currentAccount.name}
|
||||
intl={intl}
|
||||
handleForgotButton={() => this._handleForgotButton()}
|
||||
isReset={isReset}
|
||||
{...this.props}
|
||||
/>
|
||||
);
|
||||
|
@ -1,27 +1,39 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { Text, TouchableOpacity, View } from 'react-native';
|
||||
|
||||
import { NumericKeyboard, PinAnimatedInput, UserAvatar } from '../../../components';
|
||||
|
||||
import styles from './pinCodeStyles';
|
||||
|
||||
const PinCodeScreen = ({
|
||||
const PinCodeScreen = forwardRef(({
|
||||
informationText,
|
||||
showForgotButton,
|
||||
username,
|
||||
handleForgotButton,
|
||||
setPinCode,
|
||||
}) => {
|
||||
}, ref) => {
|
||||
const [pin, setPin] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const intl = useIntl();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
setPinThroughBiometric(bioPin){
|
||||
if(bioPin && bioPin.length === 4){
|
||||
setLoading(true);
|
||||
setPin(bioPin)
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
_handlePinComplete();
|
||||
}, [pin]);
|
||||
|
||||
|
||||
|
||||
const _handlePinComplete = async () => {
|
||||
if (pin.length === 4) {
|
||||
setLoading(true);
|
||||
@ -31,6 +43,7 @@ const PinCodeScreen = ({
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const _handleKeyboardOnPress = async (value) => {
|
||||
try {
|
||||
if (loading) {
|
||||
@ -82,6 +95,6 @@ const PinCodeScreen = ({
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
})
|
||||
|
||||
export default PinCodeScreen;
|
Loading…
Reference in New Issue
Block a user