mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #4144 from MetaMask/ui-actions-pify-importNewAccount
ui - actions - importNewAccount - use async and pify for cleaner syntax
This commit is contained in:
commit
a93237a4cd
@ -1,4 +1,5 @@
|
|||||||
const abi = require('human-standard-token-abi')
|
const abi = require('human-standard-token-abi')
|
||||||
|
const pify = require('pify')
|
||||||
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
||||||
const { getTokenAddressFromTokenObject } = require('./util')
|
const { getTokenAddressFromTokenObject } = require('./util')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
@ -523,31 +524,26 @@ function addNewKeyring (type, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function importNewAccount (strategy, args) {
|
function importNewAccount (strategy, args) {
|
||||||
return (dispatch) => {
|
return async (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
|
let newState
|
||||||
|
dispatch(actions.showLoadingIndication('This may take a while, please be patient.'))
|
||||||
|
try {
|
||||||
log.debug(`background.importAccountWithStrategy`)
|
log.debug(`background.importAccountWithStrategy`)
|
||||||
return new Promise((resolve, reject) => {
|
await pify(background.importAccountWithStrategy).call(background, strategy, args)
|
||||||
background.importAccountWithStrategy(strategy, args, (err) => {
|
|
||||||
if (err) {
|
|
||||||
dispatch(actions.displayWarning(err.message))
|
|
||||||
return reject(err)
|
|
||||||
}
|
|
||||||
log.debug(`background.getState`)
|
log.debug(`background.getState`)
|
||||||
background.getState((err, newState) => {
|
newState = await pify(background.getState).call(background)
|
||||||
|
} catch (err) {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) {
|
|
||||||
dispatch(actions.displayWarning(err.message))
|
dispatch(actions.displayWarning(err.message))
|
||||||
return reject(err)
|
return
|
||||||
}
|
}
|
||||||
|
dispatch(actions.hideLoadingIndication())
|
||||||
dispatch(actions.updateMetamaskState(newState))
|
dispatch(actions.updateMetamaskState(newState))
|
||||||
dispatch({
|
dispatch({
|
||||||
type: actions.SHOW_ACCOUNT_DETAIL,
|
type: actions.SHOW_ACCOUNT_DETAIL,
|
||||||
value: newState.selectedAddress,
|
value: newState.selectedAddress,
|
||||||
})
|
})
|
||||||
resolve(newState)
|
return newState
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user