Skip to content

Commit 03f4911

Browse files
sethkfmanieow
andauthored
fix: biometric on create srp wallet (#24695) (#24951)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Recent added check against the passcodePreviouslyDisable for the biometric in #23917 is causing new user not being prompted biometric when they create new wallet after fresh install metamask This pr update the function componentAuthenticationType in Authentication.js to Changes it priotize REMEMBER_ME if both biometric choise and remember_me are both true. if biometric choise is true and biometric is available It will fallback to PassCode if bioemetric is disabled. else it will return Biometric if biometric choise or biometric is not available it will return Password This PR scope down #24480 fixes to the `componentAuthenticationType` only <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: Biometric choice logic update ## **Related issues** Fixes: #24553 ## **Manual testing steps** ```gherkin Feature: prompt biometric on create new srp wallet Scenario: uninstall MM and then reinstall new app Given user create new srp wallet When user successful create wallet Then user should be prompted biometric ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Updates authentication selection logic for components. > > - **Auth precedence changes**: Return `REMEMBER_ME` when enabled; if `biometryChoice` is true and biometrics available, return `BIOMETRIC` unless `BIOMETRY_CHOICE_DISABLED` is `TRUE` (then `PASSCODE`), with a temporary case returning `BIOMETRIC` when both biometric and passcode are disabled; otherwise default to `PASSWORD`. > - **Storage flags**: Now reads `PASSCODE_DISABLED` and `BIOMETRY_CHOICE_DISABLED` (replacing prior `passcodePreviouslyDisabled`). > - **Tests**: Adjusts expectations/comments to return `BIOMETRIC` for new users selecting biometrics and aligns unit tests with the new logic. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 6941ad1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. Co-authored-by: ieow <4881057+ieow@users.noreply.github.com>
1 parent 6d3411e commit 03f4911

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

app/core/Authentication/Authentication.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,12 @@ describe('Authentication', () => {
589589
expect(result.currentAuthType).toEqual(AUTHENTICATION_TYPE.BIOMETRIC);
590590
});
591591

592-
it('returns PASSCODE type for components when no previous auth choice exists (new user choosing biometrics)', async () => {
592+
it('returns BIOMETRIC type for components when no previous auth choice exists (new user choosing biometrics)', async () => {
593593
SecureKeychain.getSupportedBiometryType = jest
594594
.fn()
595595
.mockReturnValue(Keychain.BIOMETRY_TYPE.FINGERPRINT);
596596
// No storage flags set - represents new user or first-time choice
597-
// With new logic, this defaults to PASSCODE when biometryChoice is true
597+
// With new logic, this defaults to BIOMETRIC when biometryChoice is true
598598

599599
// Mock Redux store to return allowLoginWithRememberMe: false
600600
jest.spyOn(ReduxService, 'store', 'get').mockReturnValue({
@@ -606,7 +606,7 @@ describe('Authentication', () => {
606606
false,
607607
);
608608
expect(result.availableBiometryType).toEqual('Fingerprint');
609-
expect(result.currentAuthType).toEqual(AUTHENTICATION_TYPE.PASSCODE);
609+
expect(result.currentAuthType).toEqual(AUTHENTICATION_TYPE.BIOMETRIC);
610610
});
611611

612612
it('returns PASSWORD type when biometryChoice is false', async () => {

app/core/Authentication/Authentication.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -555,36 +555,53 @@ class AuthenticationService {
555555
// eslint-disable-next-line @typescript-eslint/no-explicit-any
556556
const availableBiometryType: any =
557557
await SecureKeychain.getSupportedBiometryType();
558-
const passcodePreviouslyDisabled =
559-
await StorageWrapper.getItem(PASSCODE_DISABLED);
558+
559+
const passcodeDisabled = await StorageWrapper.getItem(PASSCODE_DISABLED);
560+
561+
const biometryDisabled = await StorageWrapper.getItem(
562+
BIOMETRY_CHOICE_DISABLED,
563+
);
560564

561565
if (
562-
availableBiometryType &&
563-
biometryChoice &&
564-
passcodePreviouslyDisabled === TRUE
566+
rememberMe &&
567+
ReduxService.store.getState().security.allowLoginWithRememberMe
565568
) {
566569
return {
567-
currentAuthType: AUTHENTICATION_TYPE.BIOMETRIC,
570+
currentAuthType: AUTHENTICATION_TYPE.REMEMBER_ME,
568571
availableBiometryType,
569572
};
570573
} else if (
571-
rememberMe &&
572-
ReduxService.store.getState().security.allowLoginWithRememberMe
574+
biometryChoice &&
575+
availableBiometryType &&
576+
biometryDisabled === TRUE &&
577+
passcodeDisabled === TRUE
573578
) {
579+
// this case is where user disable both passcode and biometric
580+
// by right we should not show the login switch for this case, hence we should return PASSWORD type
581+
// however for the current behaviour, we are showing the login switch with BIOMETRIC type
582+
// return biometric type for now to prevent unexpected behaviour
574583
return {
575-
currentAuthType: AUTHENTICATION_TYPE.REMEMBER_ME,
584+
currentAuthType: AUTHENTICATION_TYPE.BIOMETRIC,
576585
availableBiometryType,
577586
};
578587
} else if (
579-
availableBiometryType &&
580588
biometryChoice &&
581-
!(passcodePreviouslyDisabled && passcodePreviouslyDisabled === TRUE)
589+
availableBiometryType &&
590+
biometryDisabled === TRUE
582591
) {
592+
// return passcode since biometric is disabled
583593
return {
584594
currentAuthType: AUTHENTICATION_TYPE.PASSCODE,
585595
availableBiometryType,
586596
};
597+
} else if (biometryChoice && availableBiometryType) {
598+
return {
599+
currentAuthType: AUTHENTICATION_TYPE.BIOMETRIC,
600+
availableBiometryType,
601+
};
587602
}
603+
604+
// if biometricChoice or availableBiometryType is false, return PASSWORD
588605
return {
589606
currentAuthType: AUTHENTICATION_TYPE.PASSWORD,
590607
availableBiometryType,

0 commit comments

Comments
 (0)