1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

inpage - defaultAccount - fix bug

This commit is contained in:
kumavis 2016-04-14 21:11:35 -07:00
parent 2f8a5d1c3a
commit 1e989fb8a4

View File

@ -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')