aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-10-08 23:55:07 +0800
committerkumavis <aaron@kumavis.me>2018-10-08 23:55:07 +0800
commit354f8c0d7de8ff2611988f9839c2072295c955ae (patch)
treeda69526eebd007857b6efedb5c0a3dc165318ad0 /app/scripts/metamask-controller.js
parentc500ef4a587c4d3eebbc1e392227aabbbf4f2b2e (diff)
downloadtangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.gz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.bz2
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.lz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.xz
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.tar.zst
tangerine-wallet-browser-354f8c0d7de8ff2611988f9839c2072295c955ae.zip
provider - enable subscription support (newHeads, logs)
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 34ca80dd7..a59be7744 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')
@@ -1246,24 +1247,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,