You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.0 KiB
77 lines
2.0 KiB
4 years ago
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
|
import { compose } from 'redux';
|
||
4 years ago
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
||
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
|
||
4 years ago
|
import {
|
||
|
DEFAULT_ROUTE,
|
||
|
RESTORE_VAULT_ROUTE,
|
||
4 years ago
|
} from '../../helpers/constants/routes';
|
||
6 years ago
|
import {
|
||
7 years ago
|
tryUnlockMetamask,
|
||
|
forgotPassword,
|
||
|
markPasswordForgotten,
|
||
6 years ago
|
forceUpdateMetamaskState,
|
||
|
showModal,
|
||
4 years ago
|
} from '../../store/actions';
|
||
|
import UnlockPage from './unlock-page.component';
|
||
7 years ago
|
|
||
5 years ago
|
const mapStateToProps = (state) => {
|
||
4 years ago
|
const {
|
||
|
metamask: { isUnlocked },
|
||
4 years ago
|
} = state;
|
||
7 years ago
|
return {
|
||
|
isUnlocked,
|
||
4 years ago
|
};
|
||
|
};
|
||
7 years ago
|
|
||
5 years ago
|
const mapDispatchToProps = (dispatch) => {
|
||
7 years ago
|
return {
|
||
|
forgotPassword: () => dispatch(forgotPassword()),
|
||
5 years ago
|
tryUnlockMetamask: (password) => dispatch(tryUnlockMetamask(password)),
|
||
7 years ago
|
markPasswordForgotten: () => dispatch(markPasswordForgotten()),
|
||
6 years ago
|
forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch),
|
||
4 years ago
|
showOptInModal: () =>
|
||
|
dispatch(showModal({ name: 'METAMETRICS_OPT_IN_MODAL' })),
|
||
4 years ago
|
};
|
||
|
};
|
||
7 years ago
|
|
||
6 years ago
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
||
4 years ago
|
const {
|
||
|
// eslint-disable-next-line no-shadow
|
||
|
markPasswordForgotten,
|
||
|
// eslint-disable-next-line no-shadow
|
||
|
tryUnlockMetamask,
|
||
|
...restDispatchProps
|
||
4 years ago
|
} = dispatchProps;
|
||
|
const { history, onSubmit: ownPropsSubmit, ...restOwnProps } = ownProps;
|
||
6 years ago
|
|
||
5 years ago
|
const onImport = async () => {
|
||
4 years ago
|
await markPasswordForgotten();
|
||
|
history.push(RESTORE_VAULT_ROUTE);
|
||
6 years ago
|
|
||
5 years ago
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
||
4 years ago
|
global.platform.openExtensionInBrowser(RESTORE_VAULT_ROUTE);
|
||
6 years ago
|
}
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
5 years ago
|
const onSubmit = async (password) => {
|
||
4 years ago
|
await tryUnlockMetamask(password);
|
||
|
history.push(DEFAULT_ROUTE);
|
||
|
};
|
||
6 years ago
|
|
||
|
return {
|
||
|
...stateProps,
|
||
|
...restDispatchProps,
|
||
|
...restOwnProps,
|
||
|
onRestore: onImport,
|
||
|
onSubmit: ownPropsSubmit || onSubmit,
|
||
5 years ago
|
history,
|
||
4 years ago
|
};
|
||
|
};
|
||
6 years ago
|
|
||
7 years ago
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
||
4 years ago
|
)(UnlockPage);
|