diff --git a/packages/embark-blockchain-connector/src/provider.js b/packages/embark-blockchain-connector/src/provider.js index 5f0ff2dd7..fa2376700 100644 --- a/packages/embark-blockchain-connector/src/provider.js +++ b/packages/embark-blockchain-connector/src/provider.js @@ -96,7 +96,8 @@ class Provider { self.web3.eth.accounts.wallet.add(account); } }); - self.addresses = [...new Set(self.addresses)]; // Remove duplicates + // Normalize addresses and remove duplicates + self.addresses = [...new Set(self.addresses.map(ethUtil.toChecksumAddress))]; if (self.accounts.length) { self.web3.eth.defaultAccount = self.addresses[0]; @@ -132,13 +133,18 @@ class Provider { }, 1); self.provider.send = function(payload, cb) { - if (payload.method === 'eth_accounts') { + if (payload.method === 'eth_accounts' || payload.method === 'personal_listAccounts') { return realSend(payload, function(err, result) { if (err) { return cb(err); } if (self.accounts.length) { - result.result = self.addresses; + result.result = [ + ...new Set([ + ...self.addresses, + ...result.result.map(ethUtil.toChecksumAddress) + ]) + ]; } cb(null, result); }); diff --git a/packages/embark-blockchain-process/src/proxy.js b/packages/embark-blockchain-process/src/proxy.js index 6e2c70128..7ab76ad67 100644 --- a/packages/embark-blockchain-process/src/proxy.js +++ b/packages/embark-blockchain-process/src/proxy.js @@ -16,17 +16,26 @@ const modifyResponse = require('node-http-proxy-json'); const Transaction = require('ethereumjs-tx'); const ethUtil = require('ethereumjs-util'); import { pingEndpoint } from './utils'; +import Web3 from 'web3'; -const METHODS_TO_MODIFY = {accounts: 'eth_accounts'}; +const METHODS_TO_MODIFY = { + accounts: 'eth_accounts', + personalAccounts: 'personal_listAccounts' +}; const REQUEST_TIMEOUT = 5000; const modifyPayload = (toModifyPayloads, body, accounts) => { - switch (toModifyPayloads[body.id]) { - case METHODS_TO_MODIFY.accounts: - delete toModifyPayloads[body.id]; - body.result = Array.isArray(body.result) && body.result.concat(accounts); - break; - default: + if (toModifyPayloads[body.id] === METHODS_TO_MODIFY.accounts || + toModifyPayloads[body.id] === METHODS_TO_MODIFY.personalAccounts) { + delete toModifyPayloads[body.id]; + if (Array.isArray(body.result)) { + body.result = [ + ...new Set([ + ...accounts, + ...body.result.map(ethUtil.toChecksumAddress) + ]) + ]; + } } return body; }; @@ -226,6 +235,10 @@ export class Proxy { }); }()); + const web3 = new Web3(`${ws ? 'ws' : 'http'}://${canonicalHost(host)}:${port}`); + accounts = (await web3.eth.getAccounts() || []).concat(accounts || []); + accounts = [...new Set(accounts.map(ethUtil.toChecksumAddress))]; + let proxy = httpProxy.createProxyServer({ ssl: certOptions, target: {