aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/popup.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-03-10 10:33:30 +0800
committerkumavis <aaron@kumavis.me>2016-03-11 04:28:42 +0800
commitf64e4a518b1c692a2be0dea0391aaa34f5b0756b (patch)
treeb06364cd967f136739a43c47a39ee07f609609e1 /app/scripts/popup.js
parente056148a60817c872f57c7514bb77feb4486c996 (diff)
downloadtangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar.gz
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar.bz2
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar.lz
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar.xz
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.tar.zst
tangerine-wallet-browser-f64e4a518b1c692a2be0dea0391aaa34f5b0756b.zip
plumbing - pipe web3 to the popup.js
Diffstat (limited to 'app/scripts/popup.js')
-rw-r--r--app/scripts/popup.js32
1 files changed, 29 insertions, 3 deletions
diff --git a/app/scripts/popup.js b/app/scripts/popup.js
index 77c27c6b5..0110f81b6 100644
--- a/app/scripts/popup.js
+++ b/app/scripts/popup.js
@@ -1,11 +1,13 @@
const url = require('url')
const EventEmitter = require('events').EventEmitter
const async = require('async')
+const Multiplex = require('multiplex')
const Dnode = require('dnode')
const MetaMaskUi = require('metamask-ui')
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')
// setup app
var css = MetaMaskUiCss()
@@ -19,15 +21,39 @@ async.parallel({
function connectToAccountManager(cb){
// setup communication with background
var pluginPort = chrome.runtime.connect({name: 'popup'})
- var duplex = new PortStream(pluginPort)
+ var portStream = new PortStream(pluginPort)
+ // setup multiplexing
+ var mx = Multiplex()
+ portStream.pipe(mx).pipe(portStream)
+ mx.on('error', function(err) {
+ console.error(err)
+ portStream.destroy()
+ })
+ portStream.on('error', function(err) {
+ console.error(err)
+ mx.destroy()
+ })
+ var dnodeStream = mx.createSharedStream('dnode')
+ var providerStream = mx.createSharedStream('provider')
+ linkDnode(dnodeStream, cb)
+ linkWeb3(providerStream)
+}
+
+function linkWeb3(stream){
+ var remoteProvider = new StreamProvider()
+ remoteProvider.pipe(stream).pipe(remoteProvider)
+ stream.on('error', console.error.bind(console))
+ remoteProvider.on('error', console.error.bind(console))
+}
+
+function linkDnode(stream, cb){
var eventEmitter = new EventEmitter()
var background = Dnode({
- // setUnconfirmedTxs: setUnconfirmedTxs,
sendUpdate: function(state){
eventEmitter.emit('update', state)
},
})
- duplex.pipe(background).pipe(duplex)
+ stream.pipe(background).pipe(stream)
background.once('remote', function(accountManager){
// setup push events
accountManager.on = eventEmitter.on.bind(eventEmitter)