2018-05-11 01:51:26 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { withRouter } from 'react-router-dom'
|
2020-02-24 23:58:26 +01:00
|
|
|
import { compose } from 'redux'
|
2019-03-22 00:03:30 +01:00
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums'
|
|
|
|
import { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } 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,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../store/actions'
|
2018-05-11 01:51:26 +02:00
|
|
|
import UnlockPage from './unlock-page.component'
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2018-05-11 01:51:26 +02:00
|
|
|
const { metamask: { isUnlocked } } = state
|
|
|
|
return {
|
|
|
|
isUnlocked,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
showOptInModal: () => dispatch(showModal({ name: 'METAMETRICS_OPT_IN_MODAL' })),
|
2018-05-11 01:51:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 16:25:34 +01:00
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|
|
|
const { markPasswordForgotten, tryUnlockMetamask, ...restDispatchProps } = dispatchProps
|
|
|
|
const { history, onSubmit: ownPropsSubmit, ...restOwnProps } = ownProps
|
|
|
|
|
2020-04-22 21:15:22 +02:00
|
|
|
const onImport = async () => {
|
|
|
|
await markPasswordForgotten()
|
2019-01-23 16:25:34 +01:00
|
|
|
history.push(RESTORE_VAULT_ROUTE)
|
|
|
|
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
2019-03-27 07:35:29 +01:00
|
|
|
global.platform.openExtensionInBrowser(RESTORE_VAULT_ROUTE)
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const onSubmit = async (password) => {
|
2019-01-23 16:25:34 +01:00
|
|
|
await tryUnlockMetamask(password)
|
|
|
|
history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...stateProps,
|
|
|
|
...restDispatchProps,
|
|
|
|
...restOwnProps,
|
|
|
|
onImport,
|
|
|
|
onRestore: onImport,
|
|
|
|
onSubmit: ownPropsSubmit || onSubmit,
|
2020-02-10 18:42:59 +01:00
|
|
|
history,
|
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),
|
2018-05-11 01:51:26 +02:00
|
|
|
)(UnlockPage)
|