diff options
author | Bruno Barbieri <bruno.barbieri@consensys.net> | 2018-10-10 01:25:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 01:25:13 +0800 |
commit | 17b9f4c0dbfc5257c83a454f669e410856fedb9c (patch) | |
tree | 8519546920c1dd6caefab426d68ae5c2e9182193 /app/scripts/metamask-controller.js | |
parent | cd91b45686864c5d38fc95e3a561ca66b36ade7c (diff) | |
parent | 45feb43f306f4b21ef007e0c8897cda384c28fc5 (diff) | |
download | tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar.gz tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar.bz2 tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar.lz tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar.xz tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.tar.zst tangerine-wallet-browser-17b9f4c0dbfc5257c83a454f669e410856fedb9c.zip |
Merge pull request #5458 from MetaMask/provider-subs
Feature: Subscription support
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r-- | app/scripts/metamask-controller.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a04c63da6..493877345 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -15,6 +15,7 @@ const RpcEngine = require('json-rpc-engine') const debounce = require('debounce') const createEngineStream = require('json-rpc-middleware-stream/engineStream') const createFilterMiddleware = require('eth-json-rpc-filters') +const createSubscriptionManager = require('eth-json-rpc-filters/subscriptionManager') const createOriginMiddleware = require('./lib/createOriginMiddleware') const createLoggerMiddleware = require('./lib/createLoggerMiddleware') const createProviderMiddleware = require('./lib/createProviderMiddleware') @@ -1248,24 +1249,33 @@ module.exports = class MetamaskController extends EventEmitter { setupProviderConnection (outStream, origin) { // setup json rpc engine stack const engine = new RpcEngine() + const provider = this.provider + const blockTracker = this.blockTracker // create filter polyfill middleware - const filterMiddleware = createFilterMiddleware({ - provider: this.provider, - blockTracker: this.blockTracker, - }) + const filterMiddleware = createFilterMiddleware({ provider, blockTracker }) + // create subscription polyfill middleware + const subscriptionManager = createSubscriptionManager({ provider, blockTracker }) + subscriptionManager.events.on('notification', (message) => engine.emit('notification', message)) + // metadata engine.push(createOriginMiddleware({ origin })) engine.push(createLoggerMiddleware({ origin })) + // filter and subscription polyfills engine.push(filterMiddleware) + engine.push(subscriptionManager.middleware) + // watch asset engine.push(this.preferencesController.requestWatchAsset.bind(this.preferencesController)) + // sign typed data middleware engine.push(this.createTypedDataMiddleware('eth_signTypedData', 'V1').bind(this)) engine.push(this.createTypedDataMiddleware('eth_signTypedData_v1', 'V1').bind(this)) engine.push(this.createTypedDataMiddleware('eth_signTypedData_v3', 'V3', true).bind(this)) - engine.push(createProviderMiddleware({ provider: this.provider })) + // forward to metamask primary provider + engine.push(createProviderMiddleware({ provider })) // setup connection const providerStream = createEngineStream({ engine }) + pump( outStream, providerStream, |