diff options
author | kumavis <kumavis@users.noreply.github.com> | 2016-04-16 04:06:28 +0800 |
---|---|---|
committer | kumavis <kumavis@users.noreply.github.com> | 2016-04-16 04:06:28 +0800 |
commit | 83b8741bbb335ad1629b72180616835dbb3f5433 (patch) | |
tree | b8adfc80551c1032dc6fc43aa3a5055169446143 /app/scripts/popup.js | |
parent | 81fc1e5f7dc958af40d8113b80c8cfb38c2016ef (diff) | |
parent | d6114292d0c05b42b1d28d75baad8af0c06509a1 (diff) | |
download | tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar.gz tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar.bz2 tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar.lz tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar.xz tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.tar.zst tangerine-wallet-browser-83b8741bbb335ad1629b72180616835dbb3f5433.zip |
Merge pull request #113 from MetaMask/i53
publicConfigStore for sync provider and selected address
Diffstat (limited to 'app/scripts/popup.js')
-rw-r--r-- | app/scripts/popup.js | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/app/scripts/popup.js b/app/scripts/popup.js index 3049ff2c3..85b3e30f9 100644 --- a/app/scripts/popup.js +++ b/app/scripts/popup.js @@ -1,7 +1,6 @@ const url = require('url') const EventEmitter = require('events').EventEmitter const async = require('async') -const ObjectMultiplex = require('./lib/obj-multiplex') const Dnode = require('dnode') const Web3 = require('web3') const MetaMaskUi = require('../../ui') @@ -9,6 +8,7 @@ const MetaMaskUiCss = require('../../ui/css') const injectCss = require('inject-css') const PortStream = require('./lib/port-stream.js') const StreamProvider = require('./lib/stream-provider.js') +const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex // setup app var css = MetaMaskUiCss() @@ -24,21 +24,13 @@ function connectToAccountManager(cb){ var pluginPort = chrome.runtime.connect({name: 'popup'}) var portStream = new PortStream(pluginPort) // setup multiplexing - var mx = ObjectMultiplex() - 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() - }) - linkDnode(mx.createStream('dnode'), cb) - linkWeb3(mx.createStream('provider')) + var mx = setupMultiplex(portStream) + // connect features + setupControllerConnection(mx.createStream('controller'), cb) + setupWeb3Connection(mx.createStream('provider')) } -function linkWeb3(stream){ +function setupWeb3Connection(stream){ var remoteProvider = new StreamProvider() remoteProvider.pipe(stream).pipe(remoteProvider) stream.on('error', console.error.bind(console)) @@ -46,7 +38,7 @@ function linkWeb3(stream){ global.web3 = new Web3(remoteProvider) } -function linkDnode(stream, cb){ +function setupControllerConnection(stream, cb){ var eventEmitter = new EventEmitter() var background = Dnode({ sendUpdate: function(state){ |