1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/pages/unlock-page/unlock-page.container.js
Mark Stacey 4598b1844e
Await completion of markPasswordForgotten (#8381)
`markPasswordForgotten` is an asynchronous function, but it was being
called synchronously. The page was redirected without waiting for the
operation to complete.

We now wait for the operation to complete before continuing. Failure is
still not being handled correctly, but that will be addressed in a
separate PR.
2020-04-22 16:15:22 -03:00

66 lines
1.9 KiB
JavaScript

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 '../../../../app/scripts/lib/enums'
import { DEFAULT_ROUTE, RESTORE_VAULT_ROUTE } from '../../helpers/constants/routes'
import {
tryUnlockMetamask,
forgotPassword,
markPasswordForgotten,
forceUpdateMetamaskState,
showModal,
} from '../../store/actions'
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()),
forceUpdateMetamaskState: () => forceUpdateMetamaskState(dispatch),
showOptInModal: () => dispatch(showModal({ name: 'METAMETRICS_OPT_IN_MODAL' })),
}
}
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { markPasswordForgotten, tryUnlockMetamask, ...restDispatchProps } = dispatchProps
const { history, onSubmit: ownPropsSubmit, ...restOwnProps } = ownProps
const onImport = async () => {
await markPasswordForgotten()
history.push(RESTORE_VAULT_ROUTE)
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
global.platform.openExtensionInBrowser(RESTORE_VAULT_ROUTE)
}
}
const onSubmit = async (password) => {
await tryUnlockMetamask(password)
history.push(DEFAULT_ROUTE)
}
return {
...stateProps,
...restDispatchProps,
...restOwnProps,
onImport,
onRestore: onImport,
onSubmit: ownPropsSubmit || onSubmit,
history,
}
}
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps, mergeProps)
)(UnlockPage)