Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -467,6 +468,7 @@ describe('MetaMaskController', function () {
metamaskController.onboardingController.setFirstTimeFlowType(
FirstTimeFlowType.socialCreate,
);
metamaskController.onboardingController.completeOnboarding();
jest
.spyOn(
metamaskController.seedlessOnboardingController,
Expand Down
9 changes: 5 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 =
Expand Down
13 changes: 12 additions & 1 deletion ui/pages/unlock-page/unlock-page.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -113,12 +118,18 @@ class UnlockPage extends Component {
}
}

componentDidMount() {
async componentDidMount() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we change this to async, do we need to change all calls to this function to using await?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @matthiasgeihs, we don't need to. componentDidMount is a react lifecyle method (https://react.dev/reference/react/Component#componentdidmount) which will be run when the component is mounted.

Regardless of using async or not, does not matter here (since the function returns void and react doesn't do anything with it).
I just add async to componentDidMount so that we can know if the passwordOutdatedCheck is failed. 4caa0fb#diff-f6f23f7c3cf523f0e66d1892bfd99b9179bae4978e855c4b6e683d5d0b21981dR128-R132

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) => {
Expand Down
3 changes: 3 additions & 0 deletions ui/pages/unlock-page/unlock-page.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
tryUnlockMetamask,
markPasswordForgotten,
forceUpdateMetamaskState,
checkIsSeedlessPasswordOutdated,
} from '../../store/actions';
import { getIsSocialLoginFlow } from '../../selectors';
import UnlockPage from './unlock-page.component';
Expand All @@ -32,6 +33,8 @@ const mapDispatchToProps = (dispatch) => {
tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)),
markPasswordForgotten: () => dispatch(markPasswordForgotten()),
forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch),
checkIsSeedlessPasswordOutdated: () =>
dispatch(checkIsSeedlessPasswordOutdated()),
};
};

Expand Down
14 changes: 5 additions & 9 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,11 @@ export function tryUnlockMetamask(
}

export function checkIsSeedlessPasswordOutdated(
skipCache = false,
skipCache = true,
): ThunkAction<boolean | undefined, MetaMaskReduxState, unknown, AnyAction> {
return async (dispatch: MetaMaskReduxDispatch) => {
dispatch(showLoadingIndication());

try {
const isPasswordOutdated = await submitRequestToBackground<boolean>(
'checkIsSeedlessPasswordOutdated',
Expand All @@ -472,6 +474,8 @@ export function checkIsSeedlessPasswordOutdated(
} catch (error) {
dispatch(displayWarning(error));
throw error;
} finally {
dispatch(hideLoadingIndication());
}
};
}
Expand Down Expand Up @@ -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)));
Expand Down
Loading