1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

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.
This commit is contained in:
Mark Stacey 2020-04-22 16:15:22 -03:00 committed by GitHub
parent 01985b2cff
commit 4598b1844e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -1481,11 +1481,11 @@ describe('Actions', function () {
})
describe('#markPasswordForgotten', function () {
it('calls markPasswordForgotten', function () {
it('calls markPasswordForgotten', async function () {
const store = mockStore()
const markPasswordForgottenSpy = sinon.stub(background, 'markPasswordForgotten').callsArg(0)
store.dispatch(actions.markPasswordForgotten())
await store.dispatch(actions.markPasswordForgotten())
const resultantActions = store.getActions()
assert.deepEqual(resultantActions[1], { type: 'FORGOT_PASSWORD', value: true })

View File

@ -34,8 +34,8 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { markPasswordForgotten, tryUnlockMetamask, ...restDispatchProps } = dispatchProps
const { history, onSubmit: ownPropsSubmit, ...restOwnProps } = ownProps
const onImport = () => {
markPasswordForgotten()
const onImport = async () => {
await markPasswordForgotten()
history.push(RESTORE_VAULT_ROUTE)
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {

View File

@ -1083,12 +1083,22 @@ export function cancelTxs (txDataList) {
}
export function markPasswordForgotten () {
return (dispatch) => {
return background.markPasswordForgotten(() => {
return async (dispatch) => {
try {
await new Promise((resolve, reject) => {
return background.markPasswordForgotten((error) => {
if (error) {
return reject(error)
}
return resolve()
})
})
} finally {
// TODO: handle errors
dispatch(hideLoadingIndication())
dispatch(forgotPassword())
forceUpdateMetamaskState(dispatch)
})
}
}
}