From 1e989fb8a48e61a8dfb9cb3d1f82f46925b1239b Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 14 Apr 2016 21:11:35 -0700 Subject: inpage - defaultAccount - fix bug --- app/scripts/inpage.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 121246d6a..01f35d0fe 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -26,6 +26,17 @@ remoteProvider.pipe(pluginStream).pipe(remoteProvider) pluginStream.on('error', console.error.bind(console)) remoteProvider.on('error', console.error.bind(console)) +// +// global web3 +// + +var web3 = new Web3(remoteProvider) +window.web3 = web3 +web3.setProvider = function(){ + console.log('MetaMask - overrode web3.setProvider') +} +console.log('MetaMask - injected web3') + // // handle synchronous requests @@ -33,7 +44,7 @@ remoteProvider.on('error', console.error.bind(console)) // handle accounts cache var accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]') -web3.eth.defaultAccount = accounts[0] +web3.eth.defaultAccount = accountsCache[0] setInterval(populateAccountsCache, 4000) function populateAccountsCache(){ @@ -46,8 +57,8 @@ function populateAccountsCache(){ // update localStorage var accounts = response.result if (accounts.toString() !== accountsCache.toString()) { - web3.eth.defaultAccount = accounts[0] accountsCache = accounts + web3.eth.defaultAccount = accountsCache[0] localStorage['MetaMask-Accounts'] = JSON.stringify(accounts) } }) @@ -83,13 +94,3 @@ remoteProvider.send = function(payload){ } } -// -// global web3 -// - -var web3 = new Web3(remoteProvider) -window.web3 = web3 -web3.setProvider = function(){ - console.log('MetaMask - overrode web3.setProvider') -} -console.log('MetaMask - injected web3') -- cgit v1.2.3