-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec28161
commit 150c904
Showing
21 changed files
with
431 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useEffect } from 'react'; | ||
import { Alert } from 'react-native'; | ||
import { useSelector } from 'react-redux'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { selectIsFirstSignIn } from '../store/selectors/account'; | ||
import { isBiometricSupported } from '../util/biometric'; | ||
|
||
export default () => { | ||
const isFirstSignIn = useSelector(selectIsFirstSignIn); | ||
const navigation = useNavigation<any>(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const isBiometricSupport = await isBiometricSupported(); | ||
if (isBiometricSupport && isFirstSignIn) { | ||
Alert.alert( | ||
'Login with Biometric', | ||
'Would you want to use FaceID for login?', | ||
[ | ||
{ | ||
text: 'No', | ||
style: 'default', | ||
}, | ||
{ | ||
text: 'Yes', | ||
onPress: () => handleUseFaceID(), | ||
style: 'default', | ||
}, | ||
], | ||
); | ||
} | ||
})(); | ||
}, [isFirstSignIn]); | ||
|
||
const handleUseFaceID = () => { | ||
navigation.navigate('biometricSettings'); | ||
}; | ||
}; |
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,95 @@ | ||
import React, { useEffect, useLayoutEffect, useState } from 'react'; | ||
import { Switch, Text, View } from 'react-native'; | ||
import * as LocalAuthentication from 'expo-local-authentication'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import backArrow from '../../navigators/utils/backArrow'; | ||
import { updateBiometricUseStatus } from '../../store/account'; | ||
import { | ||
selectBiometricUseStatus, | ||
selectLastLoggedUsername, | ||
} from '../../store/selectors/account'; | ||
import { useAppDispatch, useAppSelector } from '../../hooks'; | ||
import { storeAsyncStorageBiometricUseStatus } from '../../util/asyncStorage'; | ||
import { isBiometricSupported } from '../../util/biometric'; | ||
import { colors } from '../../util/colors'; | ||
import styles from './styles'; | ||
|
||
const BiometricSettings = ({ navigation }) => { | ||
const [isBiometricSupport, setIsBiometricSupport] = useState<boolean>(false); | ||
const [usingStatus, setUsingStatus] = useState<boolean>(false); | ||
const dispatch = useAppDispatch(); | ||
const lastLoggedUsername = useAppSelector(selectLastLoggedUsername); | ||
const biometricUseStatus = useAppSelector(selectBiometricUseStatus); | ||
|
||
useLayoutEffect(() => { | ||
navigation.setOptions({ | ||
...backArrow({ | ||
navigation: navigation, | ||
color: colors.primaryDark, | ||
}), | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const isBiometricSupportResult = await isBiometricSupported(); | ||
setIsBiometricSupport(isBiometricSupportResult); | ||
if (lastLoggedUsername) { | ||
setUsingStatus(!!biometricUseStatus?.[lastLoggedUsername]); | ||
} | ||
})(); | ||
}, [biometricUseStatus, lastLoggedUsername]); | ||
|
||
const handleUsingStatusChange = async (updatedStatus: boolean) => { | ||
setUsingStatus(updatedStatus); | ||
if ((isBiometricSupport && lastLoggedUsername) || 1) { | ||
await LocalAuthentication.authenticateAsync({ | ||
promptMessage: | ||
'To change Telios uses settings, you must have identity verification.', | ||
cancelLabel: 'Cancel', | ||
disableDeviceFallback: false, | ||
}).then(async res => { | ||
if (res?.success && lastLoggedUsername) { | ||
const newBiometricUseStatus = cloneDeep(biometricUseStatus); | ||
newBiometricUseStatus[lastLoggedUsername] = updatedStatus; | ||
dispatch(updateBiometricUseStatus(newBiometricUseStatus)); | ||
await storeAsyncStorageBiometricUseStatus( | ||
lastLoggedUsername, | ||
updatedStatus, | ||
); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<View style={styles.settingContainer}> | ||
<View> | ||
<Text style={styles.settingText}>Using status</Text> | ||
{!isBiometricSupport && ( | ||
<Text style={styles.errorText}> | ||
{'Your device does not include this feature.'} | ||
</Text> | ||
)} | ||
</View> | ||
<Switch | ||
value={usingStatus} | ||
trackColor={{ | ||
false: colors.inkLighter, | ||
true: colors.primaryBase, | ||
}} | ||
disabled={!isBiometricSupport} | ||
onValueChange={handleUsingStatusChange} | ||
/> | ||
</View> | ||
<Text style={styles.description}> | ||
{ | ||
'Allows you to login to your Telios account with biometric verification. \n\nWhen you want to log in to your account after closing the Telios application, you must log in with biometric verification again. \n\n *Biometric verification allows you to log into your account using whatever security method is defined on your phone.' | ||
} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
export default BiometricSettings; |
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,31 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { colors } from '../../util/colors'; | ||
import { fonts } from '../../util/fonts'; | ||
import { spacing } from '../../util/spacing'; | ||
|
||
export default StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
padding: spacing.lg, | ||
backgroundColor: colors.white, | ||
}, | ||
settingContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
paddingBottom: spacing.md, | ||
borderBottomWidth: 1, | ||
borderColor: colors.skyBase, | ||
}, | ||
settingText: { | ||
...fonts.large.bold, | ||
}, | ||
description: { | ||
...fonts.tiny.regular, | ||
marginTop: spacing.md, | ||
}, | ||
errorText: { | ||
...fonts.tiny.regular, | ||
color: colors.error, | ||
}, | ||
}); |
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.