2018-05-11 01:51:26 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import { compose } from 'recompose'
|
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'
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const { metamask: { isUnlocked } } = state
|
|
|
|
return {
|
|
|
|
isUnlocked,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
forgotPassword: () => dispatch(forgotPassword()),
|
|
|
|
tryUnlockMetamask: password => dispatch(tryUnlockMetamask(password)),
|
|
|
|
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
|
|
|
|
|
|
|
|
const onImport = () => {
|
|
|
|
markPasswordForgotten()
|
|
|
|
history.push(RESTORE_VAULT_ROUTE)
|
|
|
|
|
|
|
|
if (getEnvironmentType(window.location.href) === 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const onSubmit = async password => {
|
|
|
|
await tryUnlockMetamask(password)
|
|
|
|
history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...stateProps,
|
|
|
|
...restDispatchProps,
|
|
|
|
...restOwnProps,
|
|
|
|
onImport,
|
|
|
|
onRestore: onImport,
|
|
|
|
onSubmit: ownPropsSubmit || onSubmit,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:51:26 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2019-01-23 16:25:34 +01:00
|
|
|
connect(mapStateToProps, mapDispatchToProps, mergeProps)
|
2018-05-11 01:51:26 +02:00
|
|
|
)(UnlockPage)
|