From 9cda2fa9e34b503496d01c05817e4c03c4207a64 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 May 2019 10:52:00 +0200 Subject: [PATCH] Update universal-dapp.js --- src/universal-dapp.js | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 10de36ce9b..d57aaf7160 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -134,30 +134,41 @@ 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 - if (this._deps.config.get('settings/personal-mode')) { - return executionContext.web3().personal.getListAccounts((error, accounts) => { - if (cb) cb(error, accounts) - if (error) return reject(error) - resolve(accounts) - }) - } else { + 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) + if (error) return reject(error) + resolve(accounts) + }) + } else { + executionContext.web3().eth.getAccounts((error, accounts) => { + if (cb) cb(error, accounts) + if (error) return reject(error) + resolve(accounts) + }) + } + } + break + case 'injected': { executionContext.web3().eth.getAccounts((error, accounts) => { if (cb) cb(error, accounts) if (error) return reject(error) 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)) } }) }