diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index 794493694..6015408eb 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -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 ( (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} /> ); diff --git a/src/screens/pinCode/screen/pinCodeScreen.js b/src/screens/pinCode/screen/pinCodeScreen.tsx similarity index 87% rename from src/screens/pinCode/screen/pinCodeScreen.js rename to src/screens/pinCode/screen/pinCodeScreen.tsx index db18685a4..318bfc73c 100644 --- a/src/screens/pinCode/screen/pinCodeScreen.js +++ b/src/screens/pinCode/screen/pinCodeScreen.tsx @@ -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 = ({ )} ); -}; +}) export default PinCodeScreen;