From bd50dabad99472d7ba5a6b95ecc4d89953a63347 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 24 Apr 2020 09:48:59 -0300 Subject: [PATCH] Return Promise from `editRpc` thunk `editRpc` 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 | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index dcb7dca2d..64d08b27e 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1461,24 +1461,29 @@ export function updateAndSetCustomRpc (newRpc, chainId, ticker = 'ETH', nickname } export function editRpc (oldRpc, newRpc, chainId, ticker = 'ETH', nickname, rpcPrefs) { - return (dispatch) => { + return async (dispatch) => { log.debug(`background.delRpcTarget: ${oldRpc}`) - background.delCustomRpc(oldRpc, (err) => { - if (err) { - log.error(err) - return dispatch(displayWarning('Had a problem removing network!')) - } - dispatch(setSelectedToken()) - 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 { + promisifiedBackground.delCustomRpc(oldRpc) + } catch (error) { + log.error(error) + dispatch(displayWarning('Had a problem removing network!')) + return + } + + dispatch(setSelectedToken()) + + 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, }) } }