-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manual biometrics and background lock (#201)
Signed-off-by: Jan <[email protected]> Signed-off-by: Timo Glastra <[email protected]> Co-authored-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
56e64ac
commit a5f3cc5
Showing
20 changed files
with
214 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
apps/easypid/src/features/wallet/FunkePidConfirmationScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect, useState } from 'react' | ||
import { Platform } from 'react-native' | ||
import * as Keychain from 'react-native-keychain' | ||
|
||
export function useBiometricsType() { | ||
// Set initial state based on platform (iOS has higher probability for face id) | ||
const [biometryType, setBiometryType] = useState<'face' | 'fingerprint'>( | ||
Platform.OS === 'ios' ? 'face' : 'fingerprint' | ||
) | ||
|
||
useEffect(() => { | ||
async function checkBiometryType() { | ||
const supportedBiometryType = await Keychain.getSupportedBiometryType() | ||
if (supportedBiometryType) { | ||
setBiometryType(supportedBiometryType?.toLowerCase().includes('face') ? 'face' : 'fingerprint') | ||
} | ||
} | ||
|
||
checkBiometryType() | ||
}, []) | ||
|
||
return biometryType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { PropsWithChildren } from 'react' | ||
|
||
import { useSecureUnlock } from '@package/secure-store/secure-wallet-key/SecureUnlockProvider' | ||
import { useEffect, useRef } from 'react' | ||
import React from 'react' | ||
import { AppState, type AppStateStatus } from 'react-native' | ||
|
||
const BACKGROUND_TIME_THRESHOLD = 30000 // 30 seconds | ||
|
||
export function BackgroundLockProvider({ children }: PropsWithChildren) { | ||
const secureUnlock = useSecureUnlock() | ||
const backgroundTimeRef = useRef<Date | null>(null) | ||
|
||
useEffect(() => { | ||
const handleAppStateChange = (nextAppState: AppStateStatus) => { | ||
if (nextAppState === 'background' || nextAppState === 'inactive') { | ||
backgroundTimeRef.current = new Date() | ||
} else if (nextAppState === 'active') { | ||
if (backgroundTimeRef.current) { | ||
const timeInBackground = new Date().getTime() - backgroundTimeRef.current.getTime() | ||
|
||
if (timeInBackground > BACKGROUND_TIME_THRESHOLD && secureUnlock.state === 'unlocked') { | ||
console.log('App was in background for more than 30 seconds, locking') | ||
secureUnlock.lock() | ||
} | ||
backgroundTimeRef.current = null | ||
} | ||
} | ||
} | ||
|
||
const subscription = AppState.addEventListener('change', handleAppStateChange) | ||
|
||
return () => { | ||
subscription.remove() | ||
} | ||
}, [secureUnlock]) | ||
|
||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.