Skip to content

Commit

Permalink
[FIX] iOS FaceID Deny Handler (#3371)
Browse files Browse the repository at this point in the history
* added method to catch deny biometric pop-up and reset view

* Updated function comment

* remove android check and simplified setState
  • Loading branch information
sethkfman authored Nov 16, 2021
1 parent f3d1787 commit e08af6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions app/components/Views/ChoosePassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ const styles = StyleSheet.create({
});

const PASSCODE_NOT_SET_ERROR = 'Error: Passcode not set.';
const IOS_DENY_BIOMETRIC_ERROR = 'The user name or passphrase you entered is not correct.';

/**
* View where users can set their password for the first time
Expand Down Expand Up @@ -341,7 +342,12 @@ class ChoosePassword extends PureComponent {
// Set state in app as it was with password
await SecureKeychain.resetGenericPassword();
if (this.state.biometryType && this.state.biometryChoice) {
await SecureKeychain.setGenericPassword(password, SecureKeychain.TYPES.BIOMETRICS);
try {
await SecureKeychain.setGenericPassword(password, SecureKeychain.TYPES.BIOMETRICS);
} catch (error) {
if (Device.isIos) await this.handleRejectedOsBiometricPrompt(error);
throw error;
}
} else if (this.state.rememberMe) {
await SecureKeychain.setGenericPassword(password, SecureKeychain.TYPES.REMEMBER_ME);
} else {
Expand All @@ -351,7 +357,6 @@ class ChoosePassword extends PureComponent {
await AsyncStorage.removeItem(SEED_PHRASE_HINTS);
this.props.passwordSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);

this.setState({ loading: false });
this.props.navigation.navigate('AccountBackupStep1');
InteractionManager.runAfterInteractions(() => {
Expand Down Expand Up @@ -391,6 +396,23 @@ class ChoosePassword extends PureComponent {
}
};

/**
* This function handles the case when the user rejects the OS prompt for allowing use of biometrics.
* It resets the state and and prompts the user to both set the "Remember Me" state and to try again.
* @param {*} error - error provide from try catch wrapping the biometric set password attempt
*/
handleRejectedOsBiometricPrompt = async (error) => {
const biometryType = await SecureKeychain.getSupportedBiometryType();
if (error.toString().includes(IOS_DENY_BIOMETRIC_ERROR) && !biometryType) {
this.setState({
biometryType,
biometryChoice: true,
});
this.updateBiometryChoice();
throw Error(strings('choose_password.disable_biometric_error'));
}
};

/**
* Recreates a vault
*
Expand Down
3 changes: 2 additions & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"i_understand": "I understand that MetaMask cannot recover this password for me.",
"learn_more": "Learn more.",
"secure": "Secure wallet",
"confirm": "Confirm Secret Recovery Phrase"
"confirm": "Confirm Secret Recovery Phrase",
"disable_biometric_error": "You have disabled biometrics for the app. Update Remember Me settings and try again."
},
"reset_password": {
"title": "Change password",
Expand Down

0 comments on commit e08af6a

Please sign in to comment.