mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
ui - actions - importNewAccount - use async and pify for cleaner syntax
This commit is contained in:
parent
5736a1f46d
commit
bce7adac85
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user