mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
popup - fix web3 plumbing
This commit is contained in:
parent
379294f164
commit
266e3c7ddb
@ -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(){}
|
||||
|
21
app/scripts/lib/stream-utils.js
Normal file
21
app/scripts/lib/stream-utils.js
Normal file
@ -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…
Reference in New Issue
Block a user