From 47b785ad7ef344f721b1112ce6e8f10437dd8ebd Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 28 Apr 2020 13:56:18 -0300 Subject: [PATCH] Return Promise from `updateAndSetCustomRpc` thunk (#8440) `updateAndSetCustomRpc` returned a thunk that didn't return a Promise, despite doing async work. It now returns a Promise. In the one place where this is used, it didn't seem important to update the callsite to block on this finishing. Only one call followed it in the event handler, and it didn't seem to depend on this. --- ui/app/store/actions.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index dcb7dca2d..0a7ac8cae 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1445,17 +1445,20 @@ export function setPreviousProvider (type) { } export function updateAndSetCustomRpc (newRpc, chainId, ticker = 'ETH', nickname, rpcPrefs) { - return (dispatch) => { + return async (dispatch) => { log.debug(`background.updateAndSetCustomRpc: ${newRpc} ${chainId} ${ticker} ${nickname}`) - background.updateAndSetCustomRpc(newRpc, chainId, ticker, nickname || newRpc, rpcPrefs, (err) => { - if (err) { - log.error(err) - return dispatch(displayWarning('Had a problem changing networks!')) - } - dispatch({ - type: actionConstants.SET_RPC_TARGET, - value: newRpc, - }) + + try { + await promisifiedBackground.updateAndSetCustomRpc(newRpc, chainId, ticker, nickname || newRpc, rpcPrefs) + } catch (error) { + log.error(error) + dispatch(displayWarning('Had a problem changing networks!')) + return + } + + dispatch({ + type: actionConstants.SET_RPC_TARGET, + value: newRpc, }) } }