@ -304,86 +304,79 @@ export function importNewAccount (strategy, args) {
export function addNewAccount ( ) {
export function addNewAccount ( ) {
log . debug ( ` background.addNewAccount ` )
log . debug ( ` background.addNewAccount ` )
return ( dispatch , getState ) => {
return async ( dispatch , getState ) => {
const oldIdentities = getState ( ) . metamask . identities
const oldIdentities = getState ( ) . metamask . identities
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
background . addNewAccount ( ( err , { identities : newIdentities } ) => {
let newIdentities
if ( err ) {
try {
dispatch ( displayWarning ( err . message ) )
const { identities } = await promisifiedBackground . addNewAccount ( )
return reject ( err )
newIdentities = identities
} catch ( error ) {
dispatch ( displayWarning ( error . message ) )
throw error
}
}
const newAccountAddress = Object . keys ( newIdentities ) . find ( ( address ) => ! oldIdentities [ address ] )
const newAccountAddress = Object . keys ( newIdentities ) . find ( ( address ) => ! oldIdentities [ address ] )
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
forceUpdateMetamaskState ( dispatch )
forceUpdateMetamaskState ( dispatch )
return resolve ( newAccountAddress )
return newAccountAddress
} )
} )
}
}
}
}
export function checkHardwareStatus ( deviceName , hdPath ) {
export function checkHardwareStatus ( deviceName , hdPath ) {
log . debug ( ` background.checkHardwareStatus ` , deviceName , hdPath )
log . debug ( ` background.checkHardwareStatus ` , deviceName , hdPath )
return ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
background . checkHardwareStatus ( deviceName , hdPath , ( err , unlocked ) => {
let unlocked
if ( err ) {
try {
log . error ( err )
unlocked = await promisifiedBackground . checkHardwareStatus ( deviceName , hdPath )
dispatch ( displayWarning ( err . message ) )
} catch ( error ) {
return reject ( err )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
throw error
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
forceUpdateMetamaskState ( dispatch )
forceUpdateMetamaskState ( dispatch )
return resolve ( unlocked )
return unlocked
} )
} )
}
}
}
}
export function forgetDevice ( deviceName ) {
export function forgetDevice ( deviceName ) {
log . debug ( ` background.forgetDevice ` , deviceName )
log . debug ( ` background.forgetDevice ` , deviceName )
return ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
try {
b ackground. forgetDevice ( deviceName , ( err ) => {
await promisifiedB ackground. forgetDevice ( deviceName )
if ( err ) {
} catch ( erro r ) {
log . error ( err )
log . error ( erro r )
dispatch ( displayWarning ( err . message ) )
dispatch ( displayWarning ( erro r . message ) )
return reject ( err )
throw error
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
forceUpdateMetamaskState ( dispatch )
forceUpdateMetamaskState ( dispatch )
return resolve ( )
} )
} )
}
}
}
}
export function connectHardware ( deviceName , page , hdPath ) {
export function connectHardware ( deviceName , page , hdPath ) {
log . debug ( ` background.connectHardware ` , deviceName , page , hdPath )
log . debug ( ` background.connectHardware ` , deviceName , page , hdPath )
return ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
background . connectHardware ( deviceName , page , hdPath , ( err , accounts ) => {
if ( err ) {
log . error ( err )
dispatch ( displayWarning ( err . message ) )
return reject ( err )
}
let accounts
try {
accounts = await promisifiedBackground . connectHardware ( deviceName , page , hdPath )
} catch ( error ) {
log . error ( error )
dispatch ( displayWarning ( error . message ) )
throw error
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
forceUpdateMetamaskState ( dispatch )
forceUpdateMetamaskState ( dispatch )
return resolve ( accounts )
} )
return accounts
} )
}
}
}
}