2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
RESTORE_VAULT_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
2019-01-23 16:25:34 +01:00
|
|
|
import {
|
2018-05-11 01:51:26 +02:00
|
|
|
tryUnlockMetamask,
|
|
|
|
forgotPassword,
|
|
|
|
markPasswordForgotten,
|
2019-03-05 16:45:01 +01:00
|
|
|
forceUpdateMetamaskState,
|
|
|
|
showModal,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
|
|
|
import UnlockPage from './unlock-page.component';
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
metamask: { isUnlocked },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = state;
|
2018-05-11 01:51:26 +02:00
|
|
|
return {
|
|
|
|
isUnlocked,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-05-11 01:51:26 +02:00
|
|
|
return {
|
|
|
|
forgotPassword: () => dispatch(forgotPassword()),
|
2020-02-15 21:34:12 +01:00
|
|
|
tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)),
|
2018-05-11 01:51:26 +02:00
|
|
|
markPasswordForgotten: () => dispatch(markPasswordForgotten()),
|
2019-03-05 16:45:01 +01:00
|
|
|
forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch),
|
2020-11-03 00:41:28 +01:00
|
|
|
showOptInModal: () =>
|
|
|
|
dispatch(showModal({ name: 'METAMETRICS_OPT_IN_MODAL' })),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
markPasswordForgotten,
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
tryUnlockMetamask,
|
|
|
|
...restDispatchProps
|
2021-02-04 19:15:23 +01:00
|
|
|
} = dispatchProps;
|
|
|
|
const { history, onSubmit: ownPropsSubmit, ...restOwnProps } = ownProps;
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-04-22 21:15:22 +02:00
|
|
|
const onImport = async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await markPasswordForgotten();
|
|
|
|
history.push(RESTORE_VAULT_ROUTE);
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
2021-02-04 19:15:23 +01:00
|
|
|
global.platform.openExtensionInBrowser(RESTORE_VAULT_ROUTE);
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const onSubmit = async (password) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await tryUnlockMetamask(password);
|
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
...stateProps,
|
|
|
|
...restDispatchProps,
|
|
|
|
...restOwnProps,
|
|
|
|
onRestore: onImport,
|
|
|
|
onSubmit: ownPropsSubmit || onSubmit,
|
2020-02-10 18:42:59 +01:00
|
|
|
history,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
|
2018-05-11 01:51:26 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(UnlockPage);
|