diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-05-01 06:02:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-01 06:02:40 +0800 |
commit | a93237a4cd8c5aa11f8db634ca65658e4f2b784f (patch) | |
tree | cf1f2c6cd1c5d92ee2f3e72907f8dd6f60fa6391 | |
parent | 5736a1f46d71872dee21efa3a167e4cfe12d5c0c (diff) | |
parent | bce7adac8528b71402d515374983b811a56ddf57 (diff) | |
download | tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar.gz tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar.bz2 tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar.lz tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar.xz tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.tar.zst tangerine-wallet-browser-a93237a4cd8c5aa11f8db634ca65658e4f2b784f.zip |
Merge pull request #4144 from MetaMask/ui-actions-pify-importNewAccount
ui - actions - importNewAccount - use async and pify for cleaner syntax
-rw-r--r-- | ui/app/actions.js | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 62875c629..e817fa907 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -1,4 +1,5 @@ const abi = require('human-standard-token-abi') +const pify = require('pify') const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url') const { getTokenAddressFromTokenObject } = require('./util') const ethUtil = require('ethereumjs-util') @@ -523,31 +524,26 @@ function addNewKeyring (type, opts) { } function importNewAccount (strategy, args) { - return (dispatch) => { - dispatch(actions.showLoadingIndication('This may take a while, be patient.')) - log.debug(`background.importAccountWithStrategy`) - return new Promise((resolve, reject) => { - background.importAccountWithStrategy(strategy, args, (err) => { - if (err) { - dispatch(actions.displayWarning(err.message)) - return reject(err) - } - log.debug(`background.getState`) - background.getState((err, newState) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - dispatch(actions.displayWarning(err.message)) - return reject(err) - } - dispatch(actions.updateMetamaskState(newState)) - dispatch({ - type: actions.SHOW_ACCOUNT_DETAIL, - value: newState.selectedAddress, - }) - resolve(newState) - }) - }) + return async (dispatch) => { + let newState + dispatch(actions.showLoadingIndication('This may take a while, please be patient.')) + try { + log.debug(`background.importAccountWithStrategy`) + await pify(background.importAccountWithStrategy).call(background, strategy, args) + log.debug(`background.getState`) + newState = await pify(background.getState).call(background) + } catch (err) { + dispatch(actions.hideLoadingIndication()) + dispatch(actions.displayWarning(err.message)) + return + } + dispatch(actions.hideLoadingIndication()) + dispatch(actions.updateMetamaskState(newState)) + dispatch({ + type: actions.SHOW_ACCOUNT_DETAIL, + value: newState.selectedAddress, }) + return newState } } |