Merge pull request #1948 from ethereum/yann300-patch-32

Don't web3().personal.getListAccounts if connected to injected provider
pull/3094/head
yann300 6 years ago committed by GitHub
commit 93cd54a7a5
  1. 31
      src/universal-dapp.js

@ -134,9 +134,19 @@ module.exports = class UniversalDApp extends UdappApi {
getAccounts (cb) {
return new Promise((resolve, reject) => {
if (!executionContext.isVM()) {
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
// See: https://github.com/ethereum/web3.js/issues/442
const provider = executionContext.getProvider()
switch (provider) {
case 'vm': {
if (!this.accounts) {
if (cb) cb('No accounts?')
reject('No accounts?')
return
}
if (cb) cb(null, Object.keys(this.accounts))
resolve(Object.keys(this.accounts))
}
break
case 'web3': {
if (this._deps.config.get('settings/personal-mode')) {
return executionContext.web3().personal.getListAccounts((error, accounts) => {
if (cb) cb(error, accounts)
@ -150,14 +160,15 @@ module.exports = class UniversalDApp extends UdappApi {
resolve(accounts)
})
}
} else {
if (!this.accounts) {
if (cb) cb('No accounts?')
reject('No accounts?')
return
}
if (cb) cb(null, Object.keys(this.accounts))
resolve(Object.keys(this.accounts))
break
case 'injected': {
executionContext.web3().eth.getAccounts((error, accounts) => {
if (cb) cb(error, accounts)
if (error) return reject(error)
resolve(accounts)
})
}
}
})
}

Loading…
Cancel
Save