aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2016-04-15 02:31:46 +0800
committerkumavis <kumavis@users.noreply.github.com>2016-04-15 02:31:46 +0800
commit9be7bebbb3f5450a7ddf82ccb4e07e49725e8cf7 (patch)
tree33f7722e09ae98e8fbc71f321727ad9648f673dd
parent5694a116725dad3d3bb9878c9c7059f1870d2e29 (diff)
parent38582f6aae949fdbfd48d28e496fc3f217f9c585 (diff)
downloadtangerine-wallet-browser-9be7bebbb3f5450a7ddf82ccb4e07e49725e8cf7.tar.gz
tangerine-wallet-browser-9be7bebbb3f5450a7ddf82ccb4e07e49725e8cf7.tar.zst
tangerine-wallet-browser-9be7bebbb3f5450a7ddf82ccb4e07e49725e8cf7.zip
Merge pull request #108 from MetaMask/i32
set defaultAccount on web3
-rw-r--r--app/scripts/inpage.js77
1 files changed, 4 insertions, 73 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 065f69629..121246d6a 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -1,6 +1,4 @@
const XHR = window.XMLHttpRequest
-// const fauxJax = require('faux-jax')
-// fauxJax.install()
// bring in web3 but rename on window
const Web3 = require('web3')
@@ -34,7 +32,9 @@ remoteProvider.on('error', console.error.bind(console))
//
// handle accounts cache
-var accountsCache = []
+var accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
+web3.eth.defaultAccount = accounts[0]
+
setInterval(populateAccountsCache, 4000)
function populateAccountsCache(){
remoteProvider.sendAsync(createPayload({
@@ -46,6 +46,7 @@ function populateAccountsCache(){
// update localStorage
var accounts = response.result
if (accounts.toString() !== accountsCache.toString()) {
+ web3.eth.defaultAccount = accounts[0]
accountsCache = accounts
localStorage['MetaMask-Accounts'] = JSON.stringify(accounts)
}
@@ -60,13 +61,11 @@ remoteProvider.send = function(payload){
case 'eth_accounts':
// read from localStorage
- accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
result = accountsCache
break
case 'eth_coinbase':
// read from localStorage
- accountsCache = JSON.parse(localStorage['MetaMask-Accounts'] || '[]')
result = accountsCache[0] || '0x0000000000000000000000000000000000000000'
break
@@ -94,71 +93,3 @@ web3.setProvider = function(){
console.log('MetaMask - overrode web3.setProvider')
}
console.log('MetaMask - injected web3')
-
-
-//
-// intercept local node requests
-//
-
-
-// console.log('MetaMask - intercepting localhost:8545 requests')
-
-// fauxJax.on('request', function(req){
-// // check if local node request
-// if (req.requestURL.indexOf('localhost:8545') !== -1) {
-// var rpcReq = JSON.parse(req.requestBody)
-// if (req.async) {
-// remoteProvider.sendAsync(rpcReq, function(err, result){
-// // console.log('intercepted request (async):', rpcReq, result)
-// handleResult(result)
-// })
-// } else {
-// var result = remoteProvider.send(rpcReq)
-// // console.log('intercepted request (sync):', rpcReq, result)
-// handleResult(result)
-// }
-// } else {
-// // console.log('request continuing normally:', req.requestURL)
-// continueRequestNormally(req)
-// }
-
-// function handleResult(result){
-// var serializedResult = JSON.stringify(result)
-// req.respond(200, {
-// 'content-type': 'application/json',
-// }, serializedResult)
-// }
-// })
-
-// function continueRequestNormally(req){
-// var xhr = new XHR()
-// // set target url and method
-// xhr.open(req.requestMethod, req.requestURL, req.async)
-// // set headers
-// Object.keys(req.requestHeaders || {}).forEach(function(headerKey){
-// xhr.setRequestHeader(headerKey, req.requestHeaders[headerKey])
-// })
-// // send and call completion handler
-// if (req.async) {
-// xhr.onload = copyResult
-// xhr.send(req.requestBody)
-// } else {
-// xhr.send(req.requestBody)
-// copyResult()
-// }
-
-// function copyResult() {
-// var headers = extractResponseHeaders(xhr.getAllResponseHeaders())
-// req.respond(xhr.status, headers, xhr.response)
-// }
-// }
-
-// function extractResponseHeaders(rawHeaders){
-// var headers = {}
-// var headerKeyValues = rawHeaders.split('\r\n').filter(Boolean)
-// headerKeyValues.forEach(function(keyValue){
-// var data = keyValue.split(': ')
-// headers[data[0]] = data[1]
-// })
-// return headers
-// }