1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Allow background to handle forgotten password flow (#17501)

This commit is contained in:
Brad Decker 2023-02-02 10:46:22 -06:00 committed by GitHub
parent 33ee1e4f8c
commit 3f50243cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 3 additions and 37 deletions

View File

@ -4209,6 +4209,8 @@ export default class MetamaskController extends EventEmitter {
}; };
}); });
this.unMarkPasswordForgotten();
// In the current implementation, this handler is triggered by a // In the current implementation, this handler is triggered by a
// KeyringController event. Other controllers subscribe to the 'unlock' // KeyringController event. Other controllers subscribe to the 'unlock'
// event of the MetaMaskController itself. // event of the MetaMaskController itself.

View File

@ -146,12 +146,6 @@ export default function reduceApp(state = {}, action) {
accountDetail: {}, accountDetail: {},
}; };
case actionConstants.FORGOT_PASSWORD:
return {
...appState,
forgottenPassword: action.value,
};
case actionConstants.SHOW_SEND_TOKEN_PAGE: case actionConstants.SHOW_SEND_TOKEN_PAGE:
return { return {
...appState, ...appState,
@ -180,9 +174,6 @@ export default function reduceApp(state = {}, action) {
case actionConstants.SHOW_ACCOUNT_DETAIL: case actionConstants.SHOW_ACCOUNT_DETAIL:
return { return {
...appState, ...appState,
forgottenPassword: appState.forgottenPassword
? !appState.forgottenPassword
: null,
accountDetail: { accountDetail: {
subview: 'transactions', subview: 'transactions',
accountExport: 'none', accountExport: 'none',
@ -196,7 +187,6 @@ export default function reduceApp(state = {}, action) {
isLoading: false, isLoading: false,
warning: null, warning: null,
scrollToBottom: false, scrollToBottom: false,
forgottenPassword: false,
}; };
case actionConstants.SHOW_CONF_TX_PAGE: case actionConstants.SHOW_CONF_TX_PAGE:

View File

@ -132,7 +132,6 @@ describe('App State', () => {
type: actions.SHOW_ACCOUNT_DETAIL, type: actions.SHOW_ACCOUNT_DETAIL,
value: 'context address', value: 'context address',
}); });
expect(state.forgottenPassword).toBeNull(); // default
expect(state.accountDetail.subview).toStrictEqual('transactions'); // default expect(state.accountDetail.subview).toStrictEqual('transactions'); // default
expect(state.accountDetail.accountExport).toStrictEqual('none'); // default expect(state.accountDetail.accountExport).toStrictEqual('none'); // default
expect(state.accountDetail.privateKey).toStrictEqual(''); // default expect(state.accountDetail.privateKey).toStrictEqual(''); // default
@ -163,7 +162,6 @@ describe('App State', () => {
expect(state.isLoading).toStrictEqual(false); expect(state.isLoading).toStrictEqual(false);
expect(state.warning).toBeNull(); expect(state.warning).toBeNull();
expect(state.scrollToBottom).toStrictEqual(false); expect(state.scrollToBottom).toStrictEqual(false);
expect(state.forgottenPassword).toStrictEqual(false);
}); });
it('shows confirm tx page', () => { it('shows confirm tx page', () => {

View File

@ -76,7 +76,7 @@ const mapStateToProps = (state) => {
firstTimeFlowType, firstTimeFlowType,
completedOnboarding, completedOnboarding,
} = metamask; } = metamask;
const { forgottenPassword } = appState; const { forgottenPassword } = metamask;
const totalUnapprovedCount = getTotalUnapprovedCount(state); const totalUnapprovedCount = getTotalUnapprovedCount(state);
const swapsEnabled = getSwapsFeatureIsLive(state); const swapsEnabled = getSwapsFeatureIsLive(state);
const pendingConfirmations = getUnapprovedTemplatedConfirmations(state); const pendingConfirmations = getUnapprovedTemplatedConfirmations(state);

View File

@ -9,7 +9,6 @@ import {
} from '../../helpers/constants/routes'; } from '../../helpers/constants/routes';
import { import {
tryUnlockMetamask, tryUnlockMetamask,
forgotPassword,
markPasswordForgotten, markPasswordForgotten,
forceUpdateMetamaskState, forceUpdateMetamaskState,
showModal, showModal,
@ -27,7 +26,6 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
forgotPassword: () => dispatch(forgotPassword()),
tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)), tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)),
markPasswordForgotten: () => dispatch(markPasswordForgotten()), markPasswordForgotten: () => dispatch(markPasswordForgotten()),
forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch), forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch),

View File

@ -17,7 +17,6 @@ export const ACCOUNT_CHANGED = 'ACCOUNT_CHANGED';
export const CHAIN_CHANGED = 'CHAIN_CHANGED'; export const CHAIN_CHANGED = 'CHAIN_CHANGED';
export const ADDRESS_BOOK_UPDATED = 'ADDRESS_BOOK_UPDATED'; export const ADDRESS_BOOK_UPDATED = 'ADDRESS_BOOK_UPDATED';
export const GAS_FEE_ESTIMATES_UPDATED = 'GAS_FEE_ESTIMATES_UPDATED'; export const GAS_FEE_ESTIMATES_UPDATED = 'GAS_FEE_ESTIMATES_UPDATED';
export const FORGOT_PASSWORD = 'FORGOT_PASSWORD';
export const CLOSE_WELCOME_SCREEN = 'CLOSE_WELCOME_SCREEN'; export const CLOSE_WELCOME_SCREEN = 'CLOSE_WELCOME_SCREEN';
// unlock screen // unlock screen
export const UNLOCK_IN_PROGRESS = 'UNLOCK_IN_PROGRESS'; export const UNLOCK_IN_PROGRESS = 'UNLOCK_IN_PROGRESS';

View File

@ -1392,7 +1392,6 @@ export function markPasswordForgotten() {
} finally { } finally {
// TODO: handle errors // TODO: handle errors
dispatch(hideLoadingIndication()); dispatch(hideLoadingIndication());
dispatch(forgotPassword());
await forceUpdateMetamaskState(dispatch); await forceUpdateMetamaskState(dispatch);
} }
}; };
@ -1402,20 +1401,12 @@ export function unMarkPasswordForgotten() {
return (dispatch) => { return (dispatch) => {
return new Promise((resolve) => { return new Promise((resolve) => {
callBackgroundMethod('unMarkPasswordForgotten', [], () => { callBackgroundMethod('unMarkPasswordForgotten', [], () => {
dispatch(forgotPassword(false));
resolve(); resolve();
}); });
}).then(() => forceUpdateMetamaskState(dispatch)); }).then(() => forceUpdateMetamaskState(dispatch));
}; };
} }
export function forgotPassword(forgotPasswordState = true) {
return {
type: actionConstants.FORGOT_PASSWORD,
value: forgotPasswordState,
};
}
export function closeWelcomeScreen() { export function closeWelcomeScreen() {
return { return {
type: actionConstants.CLOSE_WELCOME_SCREEN, type: actionConstants.CLOSE_WELCOME_SCREEN,

View File

@ -130,7 +130,6 @@ describe('Actions', () => {
const expectedActions = [ const expectedActions = [
{ type: 'SHOW_LOADING_INDICATION', value: undefined }, { type: 'SHOW_LOADING_INDICATION', value: undefined },
{ type: 'FORGOT_PASSWORD', value: false },
{ {
type: 'UPDATE_METAMASK_STATE', type: 'UPDATE_METAMASK_STATE',
value: baseMockState, value: baseMockState,
@ -1674,11 +1673,6 @@ describe('Actions', () => {
await store.dispatch(actions.markPasswordForgotten()); await store.dispatch(actions.markPasswordForgotten());
const resultantActions = store.getActions();
expect(resultantActions[1]).toStrictEqual({
type: 'FORGOT_PASSWORD',
value: true,
});
expect(background.markPasswordForgotten.callCount).toStrictEqual(1); expect(background.markPasswordForgotten.callCount).toStrictEqual(1);
}); });
@ -1693,7 +1687,6 @@ describe('Actions', () => {
const expectedActions = [ const expectedActions = [
{ type: 'HIDE_LOADING_INDICATION' }, { type: 'HIDE_LOADING_INDICATION' },
{ type: 'FORGOT_PASSWORD', value: true },
{ {
type: 'UPDATE_METAMASK_STATE', type: 'UPDATE_METAMASK_STATE',
value: baseMockState, value: baseMockState,
@ -1718,11 +1711,6 @@ describe('Actions', () => {
store.dispatch(actions.unMarkPasswordForgotten()); store.dispatch(actions.unMarkPasswordForgotten());
const resultantActions = store.getActions();
expect(resultantActions[0]).toStrictEqual({
type: 'FORGOT_PASSWORD',
value: false,
});
expect(background.unMarkPasswordForgotten.callCount).toStrictEqual(1); expect(background.unMarkPasswordForgotten.callCount).toStrictEqual(1);
}); });
}); });