popup - fix web3 plumbing

feature/default_network_editable
kumavis 9 years ago
parent 379294f164
commit 266e3c7ddb
  1. 19
      app/scripts/background.js
  2. 21
      app/scripts/lib/stream-utils.js
  3. 8
      app/scripts/popup.js

@ -1,6 +1,5 @@
const Dnode = require('dnode')
const Multiplex = require('multiplex')
const Through = require('through2')
const eos = require('end-of-stream')
const combineStreams = require('pumpify')
const extend = require('xtend')
@ -10,6 +9,8 @@ const MetaMaskProvider = require('./lib/zero.js')
const IdentityStore = require('./lib/idStore')
const createTxNotification = require('./lib/tx-notification.js')
const configManager = require('./lib/config-manager-singleton')
const jsonParseStream = require('./lib/stream-utils.js').jsonParseStream
const jsonStringifyStream = require('./lib/stream-utils.js').jsonStringifyStream
//
// connect to other contexts
@ -100,7 +101,7 @@ function handleInternalCommunication(portStream){
mx.destroy()
})
var dnodeStream = mx.createSharedStream('dnode')
var providerStream = combineStreams(
var providerStream = combineStreams.obj(
jsonStringifyStream(),
mx.createSharedStream('provider'),
jsonParseStream()
@ -191,18 +192,4 @@ function useEtherscanProvider() {
// util
function jsonParseStream(){
return Through.obj(function(serialized){
this.push(JSON.parse(serialized))
cb()
})
}
function jsonStringifyStream(){
return Through.obj(function(obj){
this.push(JSON.stringify(obj))
cb()
})
}
function noop(){}

@ -0,0 +1,21 @@
const Through = require('through2')
module.exports = {
jsonParseStream: jsonParseStream,
jsonStringifyStream: jsonStringifyStream,
}
function jsonParseStream(){
return Through.obj(function(serialized, encoding, cb){
this.push(JSON.parse(serialized))
cb()
})
}
function jsonStringifyStream(){
return Through.obj(function(obj, encoding, cb){
this.push(JSON.stringify(obj))
cb()
})
}

@ -9,6 +9,8 @@ const MetaMaskUiCss = require('metamask-ui/css')
const injectCss = require('inject-css')
const PortStream = require('./lib/port-stream.js')
const StreamProvider = require('./lib/stream-provider.js')
const jsonParseStream = require('./lib/stream-utils.js').jsonParseStream
const jsonStringifyStream = require('./lib/stream-utils.js').jsonStringifyStream
// setup app
var css = MetaMaskUiCss()
@ -42,7 +44,11 @@ function connectToAccountManager(cb){
function linkWeb3(stream){
var remoteProvider = new StreamProvider()
remoteProvider.pipe(stream).pipe(remoteProvider)
remoteProvider
.pipe(jsonStringifyStream())
.pipe(stream)
.pipe(jsonParseStream())
.pipe(remoteProvider)
stream.on('error', console.error.bind(console))
remoteProvider.on('error', console.error.bind(console))
global.web3 = new Web3(remoteProvider)

Loading…
Cancel
Save