aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-05-01 05:46:53 +0800
committerkumavis <aaron@kumavis.me>2018-05-01 05:46:53 +0800
commitbce7adac8528b71402d515374983b811a56ddf57 (patch)
treecf1f2c6cd1c5d92ee2f3e72907f8dd6f60fa6391 /ui/app/actions.js
parent5736a1f46d71872dee21efa3a167e4cfe12d5c0c (diff)
downloadtangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar.gz
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar.bz2
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar.lz
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar.xz
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.tar.zst
tangerine-wallet-browser-bce7adac8528b71402d515374983b811a56ddf57.zip
ui - actions - importNewAccount - use async and pify for cleaner syntax
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js44
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
}
}