1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Return a Promise from showAccountDetail thunk (#8427)

`showAccountDetail` returned a thunk that didn't return a Promise,
despite doing async work. Now it returns a Promise.

This action is only called in one place, and it looks like the actions
dispatched alongside it were meant to be run in parallel, so no changes
were made there.
This commit is contained in:
Mark Stacey 2020-04-27 18:17:28 -03:00 committed by GitHub
parent 306f04be8d
commit f11a5b4808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 22 deletions

View File

@ -985,33 +985,30 @@ describe('Actions', function () {
describe('#showAccountDetail', function () {
let setSelectedAddressSpy
beforeEach(function () {
setSelectedAddressSpy = sinon.stub(background, 'setSelectedAddress')
})
afterEach(function () {
setSelectedAddressSpy.restore()
})
it('#showAccountDetail', function () {
it('#showAccountDetail', async function () {
setSelectedAddressSpy = sinon.stub(background, 'setSelectedAddress')
.callsArgWith(1, null)
const store = mockStore()
store.dispatch(actions.showAccountDetail())
await store.dispatch(actions.showAccountDetail())
assert(setSelectedAddressSpy.calledOnce)
})
it('displays warning if setSelectedAddress throws', function () {
it('displays warning if setSelectedAddress throws', async function () {
setSelectedAddressSpy = sinon.stub(background, 'setSelectedAddress')
.callsArgWith(1, new Error('error'))
const store = mockStore()
const expectedActions = [
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
{ type: 'HIDE_LOADING_INDICATION' },
{ type: 'DISPLAY_WARNING', value: 'error' },
]
setSelectedAddressSpy.callsFake((_, callback) => {
callback(new Error('error'))
})
store.dispatch(actions.showAccountDetail())
await store.dispatch(actions.showAccountDetail())
assert.deepEqual(store.getActions(), expectedActions)
})
})

View File

@ -1191,21 +1191,25 @@ export function setSelectedAddress (address) {
}
export function showAccountDetail (address) {
return (dispatch) => {
return async (dispatch) => {
dispatch(showLoadingIndication())
log.debug(`background.setSelectedAddress`)
background.setSelectedAddress(address, (err, tokens) => {
let tokens
try {
tokens = await promisifiedBackground.setSelectedAddress(address)
} catch (error) {
dispatch(hideLoadingIndication())
if (err) {
return dispatch(displayWarning(err.message))
}
dispatch(updateTokens(tokens))
dispatch({
type: actionConstants.SHOW_ACCOUNT_DETAIL,
value: address,
})
dispatch(setSelectedToken())
dispatch(displayWarning(error.message))
return
}
dispatch(hideLoadingIndication())
dispatch(updateTokens(tokens))
dispatch({
type: actionConstants.SHOW_ACCOUNT_DETAIL,
value: address,
})
dispatch(setSelectedToken())
}
}