diff --git a/app/scripts/metamask-controller.actions.test.js b/app/scripts/metamask-controller.actions.test.js index f762f30e32ce..86f81c5c1b56 100644 --- a/app/scripts/metamask-controller.actions.test.js +++ b/app/scripts/metamask-controller.actions.test.js @@ -443,13 +443,14 @@ describe('MetaMaskController', function () { FirstTimeFlowType.create, ); const result = await metamaskController.checkIsSeedlessPasswordOutdated(); - expect(result).toBeUndefined(); + expect(result).toBeFalsy(); }); it('should return false if firstTimeFlowType is seedless and password is not outdated', async function () { metamaskController.onboardingController.setFirstTimeFlowType( FirstTimeFlowType.socialCreate, ); + metamaskController.onboardingController.completeOnboarding(); jest .spyOn( metamaskController.seedlessOnboardingController, @@ -467,6 +468,7 @@ describe('MetaMaskController', function () { metamaskController.onboardingController.setFirstTimeFlowType( FirstTimeFlowType.socialCreate, ); + metamaskController.onboardingController.completeOnboarding(); jest .spyOn( metamaskController.seedlessOnboardingController, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 9806d824c534..f88442213c31 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -4802,7 +4802,7 @@ export default class MetamaskController extends EventEmitter { // check if the password is outdated const isPasswordOutdated = isSocialLoginFlow ? await this.seedlessOnboardingController.checkIsPasswordOutdated({ - skipCache: true, + skipCache: false, }) : false; @@ -4909,10 +4909,11 @@ export default class MetamaskController extends EventEmitter { */ async checkIsSeedlessPasswordOutdated(skipCache = false) { const isSocialLoginFlow = this.onboardingController.getIsSocialLoginFlow(); + const { completedOnboarding } = this.onboardingController.state; - if (!isSocialLoginFlow) { - // this is only available for seedless onboarding flow - return undefined; + if (!isSocialLoginFlow || !completedOnboarding) { + // this is only available for seedless onboarding flow and completed onboarding + return false; } const isPasswordOutdated = diff --git a/ui/pages/unlock-page/unlock-page.component.js b/ui/pages/unlock-page/unlock-page.component.js index aeca6085d76a..df2bc6c412fe 100644 --- a/ui/pages/unlock-page/unlock-page.component.js +++ b/ui/pages/unlock-page/unlock-page.component.js @@ -2,6 +2,7 @@ import { EventEmitter } from 'events'; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { SeedlessOnboardingControllerErrorMessage } from '@metamask/seedless-onboarding-controller'; +import log from 'loglevel'; import { Text, FormTextField, @@ -70,6 +71,10 @@ class UnlockPage extends Component { * onSubmit handler when form is submitted */ onSubmit: PropTypes.func, + /** + * check password is outdated for social login flow + */ + checkIsSeedlessPasswordOutdated: PropTypes.func, /** * Force update metamask data state */ @@ -113,12 +118,18 @@ class UnlockPage extends Component { } } - componentDidMount() { + async componentDidMount() { this.passwordLoginAttemptTraceCtx = this.context.bufferedTrace?.({ name: TraceName.OnboardingPasswordLoginAttempt, op: TraceOperation.OnboardingUserJourney, parentContext: this.props.onboardingParentContext?.current, }); + + try { + await this.props.checkIsSeedlessPasswordOutdated(); + } catch (error) { + log.error('unlock page - checkIsSeedlessPasswordOutdated error', error); + } } handleSubmit = async (event) => { diff --git a/ui/pages/unlock-page/unlock-page.container.js b/ui/pages/unlock-page/unlock-page.container.js index 9205f40fbee2..acdfaed5e37f 100644 --- a/ui/pages/unlock-page/unlock-page.container.js +++ b/ui/pages/unlock-page/unlock-page.container.js @@ -13,6 +13,7 @@ import { tryUnlockMetamask, markPasswordForgotten, forceUpdateMetamaskState, + checkIsSeedlessPasswordOutdated, } from '../../store/actions'; import { getIsSocialLoginFlow } from '../../selectors'; import UnlockPage from './unlock-page.component'; @@ -32,6 +33,8 @@ const mapDispatchToProps = (dispatch) => { tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)), markPasswordForgotten: () => dispatch(markPasswordForgotten()), forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch), + checkIsSeedlessPasswordOutdated: () => + dispatch(checkIsSeedlessPasswordOutdated()), }; }; diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 59892039e403..6a84192fef5a 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -457,9 +457,11 @@ export function tryUnlockMetamask( } export function checkIsSeedlessPasswordOutdated( - skipCache = false, + skipCache = true, ): ThunkAction { return async (dispatch: MetaMaskReduxDispatch) => { + dispatch(showLoadingIndication()); + try { const isPasswordOutdated = await submitRequestToBackground( 'checkIsSeedlessPasswordOutdated', @@ -472,6 +474,8 @@ export function checkIsSeedlessPasswordOutdated( } catch (error) { dispatch(displayWarning(error)); throw error; + } finally { + dispatch(hideLoadingIndication()); } }; } @@ -2192,14 +2196,6 @@ export function lockMetamask(): ThunkAction< dispatch(showLoadingIndication()); return backgroundSetLocked() - .then(() => { - // check seedless password outdated when lock app - dispatch(checkIsSeedlessPasswordOutdated(true)); - return Promise.resolve(); - }) - .catch((error) => { - return Promise.reject(error); - }) .then(() => forceUpdateMetamaskState(dispatch)) .catch((error) => { dispatch(displayWarning(getErrorMessage(error)));