Skip to content

Commit

Permalink
enable biometric auth progress in ios
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidHaji-zada committed Dec 13, 2023
1 parent dce2442 commit b82d025
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/hooks/usePasscodeEntryRevealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AirDAOEventType, RootNavigationProp } from '@appTypes';
import { useAppState } from './useAppState';
import usePasscode from '@contexts/Passcode';
import { Cache, CacheKey } from '@lib/cache';
import { DeviceUtils } from '@utils/device';
import { AirDAOEventDispatcher } from '@lib';

export const usePasscodeEntryRevealer = () => {
Expand All @@ -25,8 +24,7 @@ export const usePasscodeEntryRevealer = () => {
return;
}

// hack around old android devices
if (DeviceUtils.isAndroid && isBiometricAuthenticationInProgress) {
if (isBiometricAuthenticationInProgress) {
await Cache.setItem(CacheKey.isBiometricAuthenticationInProgress, false);
return;
}
Expand Down
37 changes: 14 additions & 23 deletions src/screens/PasscodeEntry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { COLORS } from '@constants/colors';
import usePasscode from '@contexts/Passcode';
import { RootNavigationProp } from '@appTypes';
import { Cache, CacheKey } from '@lib/cache';
import { DeviceUtils } from '@utils/device';

export const PasscodeEntry = () => {
const isAuthSuccessfulRef = useRef(false);
Expand All @@ -28,7 +27,7 @@ export const PasscodeEntry = () => {
const { isFaceIDEnabled } = usePasscode();
const supportedBiometrics = useSupportedBiometrics();
const passcodeRef = useRef<TextInput>(null);
const { appState, prevState } = useAppState();
const { appState } = useAppState();
const automaticFaceIdCalled = useRef(false);

const closePasscodeEntry = useCallback(() => {
Expand All @@ -44,10 +43,7 @@ export const PasscodeEntry = () => {

const authenticateWithFaceID = useCallback(async () => {
automaticFaceIdCalled.current = true;
// This is a hack around older Android versions. They unmounts and remounts app after fingerprint prompt. By holding the value in cache, we can check if app comes from Biometric check
if (DeviceUtils.isAndroid) {
await Cache.setItem(CacheKey.isBiometricAuthenticationInProgress, true);
}
await Cache.setItem(CacheKey.isBiometricAuthenticationInProgress, true);
try {
const result = await LocalAuthentication.authenticateAsync({
promptMessage: t('security.authenticate.with.face.id'),
Expand All @@ -62,33 +58,28 @@ export const PasscodeEntry = () => {
} catch (error) {
// ignore
} finally {
if (DeviceUtils.isAndroid) {
await Cache.setItem(
CacheKey.isBiometricAuthenticationInProgress,
false
);
}
await Cache.setItem(CacheKey.isBiometricAuthenticationInProgress, false);
}
}, [closePasscodeEntry, t]);

useEffect(() => {
if (appState === 'active' && prevState !== 'inactive') {
if (isFaceIDEnabled) {
authenticateWithFaceID();
} else {
passcodeRef.current?.focus();
}
}
// if (automaticFaceIdCalled.current) {
// return;
// }
// if (appState === 'active') {
// if (appState === 'active' && prevState !== 'inactive') {
// if (isFaceIDEnabled) {
// authenticateWithFaceID();
// } else {
// passcodeRef.current?.focus();
// }
// }
if (automaticFaceIdCalled.current) {
return;
}
if (appState === 'active') {
if (isFaceIDEnabled) {
authenticateWithFaceID();
} else {
passcodeRef.current?.focus();
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [appState]);

Expand Down

0 comments on commit b82d025

Please sign in to comment.