mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Return a Promise from setProviderType
thunk (#8436)
`setProviderType` returned a thunk that didn't return a Promise, despite doing async work. It now returns a Promise. None of the callers of this action creator needed to know when it completed, so no changes to the call sites were made.
This commit is contained in:
parent
78fc024636
commit
e132998930
@ -1076,28 +1076,27 @@ describe('Actions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
store = mockStore({ metamask: { provider: {} } })
|
||||
setProviderTypeSpy = sinon.stub(background, 'setProviderType')
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
setProviderTypeSpy.restore()
|
||||
})
|
||||
|
||||
it('calls setProviderType', function () {
|
||||
store.dispatch(actions.setProviderType())
|
||||
it('calls setProviderType', async function () {
|
||||
setProviderTypeSpy = sinon.stub(background, 'setProviderType')
|
||||
.callsArgWith(1, null)
|
||||
await store.dispatch(actions.setProviderType())
|
||||
assert(setProviderTypeSpy.calledOnce)
|
||||
})
|
||||
|
||||
it('displays warning when setProviderType throws', function () {
|
||||
it('displays warning when setProviderType throws', async function () {
|
||||
setProviderTypeSpy = sinon.stub(background, 'setProviderType')
|
||||
.callsArgWith(1, new Error('error'))
|
||||
const expectedActions = [
|
||||
{ type: 'DISPLAY_WARNING', value: 'Had a problem changing networks!' },
|
||||
]
|
||||
|
||||
setProviderTypeSpy.callsFake((_, callback) => {
|
||||
callback(new Error('error'))
|
||||
})
|
||||
|
||||
store.dispatch(actions.setProviderType())
|
||||
await store.dispatch(actions.setProviderType())
|
||||
assert(setProviderTypeSpy.calledOnce)
|
||||
assert.deepEqual(store.getActions(), expectedActions)
|
||||
})
|
||||
|
@ -1402,19 +1402,20 @@ export function createRetryTransaction (txId, customGasPrice, customGasLimit) {
|
||||
//
|
||||
|
||||
export function setProviderType (type) {
|
||||
return (dispatch, getState) => {
|
||||
return async (dispatch, getState) => {
|
||||
const { type: currentProviderType } = getState().metamask.provider
|
||||
log.debug(`background.setProviderType`, type)
|
||||
background.setProviderType(type, (err) => {
|
||||
if (err) {
|
||||
log.error(err)
|
||||
return dispatch(displayWarning('Had a problem changing networks!'))
|
||||
}
|
||||
dispatch(setPreviousProvider(currentProviderType))
|
||||
dispatch(updateProviderType(type))
|
||||
dispatch(setSelectedToken())
|
||||
})
|
||||
|
||||
try {
|
||||
await promisifiedBackground.setProviderType(type)
|
||||
} catch (error) {
|
||||
log.error(error)
|
||||
dispatch(displayWarning('Had a problem changing networks!'))
|
||||
return
|
||||
}
|
||||
dispatch(setPreviousProvider(currentProviderType))
|
||||
dispatch(updateProviderType(type))
|
||||
dispatch(setSelectedToken())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user