mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #8443 from MetaMask/return-promise-from-set-rpc-target
Return Promise from `setRpcTarget`
This commit is contained in:
commit
da373713da
@ -1105,31 +1105,27 @@ describe('Actions', function () {
|
|||||||
describe('#setRpcTarget', function () {
|
describe('#setRpcTarget', function () {
|
||||||
let setRpcTargetSpy
|
let setRpcTargetSpy
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
setRpcTargetSpy = sinon.stub(background, 'setCustomRpc')
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
setRpcTargetSpy.restore()
|
setRpcTargetSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls setRpcTarget', function () {
|
it('calls setRpcTarget', async function () {
|
||||||
|
setRpcTargetSpy = sinon.stub(background, 'setCustomRpc')
|
||||||
|
.callsArgWith(4, null)
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
store.dispatch(actions.setRpcTarget('http://localhost:8545'))
|
await store.dispatch(actions.setRpcTarget('http://localhost:8545'))
|
||||||
assert(setRpcTargetSpy.calledOnce)
|
assert(setRpcTargetSpy.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('displays warning when setRpcTarget throws', function () {
|
it('displays warning when setRpcTarget throws', async function () {
|
||||||
|
setRpcTargetSpy = sinon.stub(background, 'setCustomRpc')
|
||||||
|
.callsArgWith(4, new Error('error'))
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: 'DISPLAY_WARNING', value: 'Had a problem changing networks!' },
|
{ type: 'DISPLAY_WARNING', value: 'Had a problem changing networks!' },
|
||||||
]
|
]
|
||||||
|
|
||||||
setRpcTargetSpy.callsFake((_, __, ___, ____, callback) => {
|
await store.dispatch(actions.setRpcTarget())
|
||||||
callback(new Error('error'))
|
|
||||||
})
|
|
||||||
|
|
||||||
store.dispatch(actions.setRpcTarget())
|
|
||||||
assert.deepEqual(store.getActions(), expectedActions)
|
assert.deepEqual(store.getActions(), expectedActions)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1492,15 +1492,17 @@ export function editRpc (oldRpc, newRpc, chainId, ticker = 'ETH', nickname, rpcP
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setRpcTarget (newRpc, chainId, ticker = 'ETH', nickname) {
|
export function setRpcTarget (newRpc, chainId, ticker = 'ETH', nickname) {
|
||||||
return (dispatch) => {
|
return async (dispatch) => {
|
||||||
log.debug(`background.setRpcTarget: ${newRpc} ${chainId} ${ticker} ${nickname}`)
|
log.debug(`background.setRpcTarget: ${newRpc} ${chainId} ${ticker} ${nickname}`)
|
||||||
background.setCustomRpc(newRpc, chainId, ticker, nickname || newRpc, (err) => {
|
|
||||||
if (err) {
|
try {
|
||||||
log.error(err)
|
await promisifiedBackground.setCustomRpc(newRpc, chainId, ticker, nickname || newRpc)
|
||||||
return dispatch(displayWarning('Had a problem changing networks!'))
|
} catch (error) {
|
||||||
}
|
log.error(error)
|
||||||
dispatch(setSelectedToken())
|
dispatch(displayWarning('Had a problem changing networks!'))
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
dispatch(setSelectedToken())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user