mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Force background state update after removing an account (#7840)
The e2e tests were failing intermittently after removing an account because the account was shown as not deleted after the removal. I suspect this was because the account _had_ been removed, but that change to the background state hadn't yet propagated to the UI. The background state is now synced before the loading overlay for removing the account is removed, ensuring that the removed account cannot be seen in the UI after removal.
This commit is contained in:
parent
8225bbe126
commit
20a7b8fa36
@ -239,25 +239,29 @@ describe('Actions', () => {
|
|||||||
const store = mockStore(devState)
|
const store = mockStore(devState)
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
'SHOW_LOADING_INDICATION',
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
'UPDATE_METAMASK_STATE',
|
||||||
{ type: 'SHOW_ACCOUNTS_PAGE' },
|
'HIDE_LOADING_INDICATION',
|
||||||
|
'SHOW_ACCOUNTS_PAGE',
|
||||||
]
|
]
|
||||||
|
|
||||||
removeAccountSpy = sinon.spy(background, 'removeAccount')
|
removeAccountSpy = sinon.spy(background, 'removeAccount')
|
||||||
|
|
||||||
await store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
|
await store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
|
||||||
assert(removeAccountSpy.calledOnce)
|
assert(removeAccountSpy.calledOnce)
|
||||||
assert.deepEqual(store.getActions(), expectedActions)
|
const actionTypes = store
|
||||||
|
.getActions()
|
||||||
|
.map(action => action.type)
|
||||||
|
assert.deepEqual(actionTypes, expectedActions)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('displays warning error message when removeAccount callback errors', async () => {
|
it('displays warning error message when removeAccount callback errors', async () => {
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
|
'SHOW_LOADING_INDICATION',
|
||||||
{ type: 'HIDE_LOADING_INDICATION' },
|
'DISPLAY_WARNING',
|
||||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
'HIDE_LOADING_INDICATION',
|
||||||
]
|
]
|
||||||
|
|
||||||
removeAccountSpy = sinon.stub(background, 'removeAccount')
|
removeAccountSpy = sinon.stub(background, 'removeAccount')
|
||||||
@ -269,7 +273,10 @@ describe('Actions', () => {
|
|||||||
await store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
|
await store.dispatch(actions.removeAccount('0xe18035bf8712672935fdb4e5e431b1a0183d2dfc'))
|
||||||
assert.fail('Should have thrown error')
|
assert.fail('Should have thrown error')
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
assert.deepEqual(store.getActions(), expectedActions)
|
const actionTypes = store
|
||||||
|
.getActions()
|
||||||
|
.map(action => action.type)
|
||||||
|
assert.deepEqual(actionTypes, expectedActions)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -380,22 +380,28 @@ export function resetAccount () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function removeAccount (address) {
|
export function removeAccount (address) {
|
||||||
return dispatch => {
|
return async dispatch => {
|
||||||
dispatch(showLoadingIndication())
|
dispatch(showLoadingIndication())
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
try {
|
||||||
background.removeAccount(address, (err, account) => {
|
await new Promise((resolve, reject) => {
|
||||||
dispatch(hideLoadingIndication())
|
background.removeAccount(address, (error, account) => {
|
||||||
if (err) {
|
if (error) {
|
||||||
dispatch(displayWarning(err.message))
|
return reject(error)
|
||||||
return reject(err)
|
}
|
||||||
}
|
return resolve(account)
|
||||||
|
})
|
||||||
log.info('Account removed: ' + account)
|
|
||||||
dispatch(showAccountsPage())
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
await forceUpdateMetamaskState(dispatch)
|
||||||
|
} catch (error) {
|
||||||
|
dispatch(displayWarning(error.message))
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
dispatch(hideLoadingIndication())
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info('Account removed: ' + address)
|
||||||
|
dispatch(showAccountsPage())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user