aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorBruno Barbieri <bruno.barbieri@consensys.net>2018-10-10 01:25:13 +0800
committerGitHub <noreply@github.com>2018-10-10 01:25:13 +0800
commit17b9f4c0dbfc5257c83a454f669e410856fedb9c (patch)
tree8519546920c1dd6caefab426d68ae5c2e9182193 /app
parentcd91b45686864c5d38fc95e3a561ca66b36ade7c (diff)
parent45feb43f306f4b21ef007e0c8897cda384c28fc5 (diff)
downloadtangerine-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')
-rw-r--r--app/scripts/controllers/network/createInfuraClient.js10
-rw-r--r--app/scripts/controllers/network/createJsonRpcClient.js4
-rw-r--r--app/scripts/controllers/network/createLocalhostClient.js4
-rw-r--r--app/scripts/inpage.js13
-rw-r--r--app/scripts/metamask-controller.js20
5 files changed, 36 insertions, 15 deletions
diff --git a/app/scripts/controllers/network/createInfuraClient.js b/app/scripts/controllers/network/createInfuraClient.js
index 41af4d9f9..326bcb355 100644
--- a/app/scripts/controllers/network/createInfuraClient.js
+++ b/app/scripts/controllers/network/createInfuraClient.js
@@ -1,5 +1,6 @@
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
-const createBlockReEmitMiddleware = require('eth-json-rpc-middleware/block-reemit')
+const createBlockReRefMiddleware = require('eth-json-rpc-middleware/block-ref')
+const createRetryOnEmptyMiddleware = require('eth-json-rpc-middleware/retryOnEmpty')
const createBlockCacheMiddleware = require('eth-json-rpc-middleware/block-cache')
const createInflightMiddleware = require('eth-json-rpc-middleware/inflight-cache')
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
@@ -11,13 +12,14 @@ module.exports = createInfuraClient
function createInfuraClient ({ network }) {
const infuraMiddleware = createInfuraMiddleware({ network })
- const blockProvider = providerFromMiddleware(infuraMiddleware)
- const blockTracker = new BlockTracker({ provider: blockProvider })
+ const infuraProvider = providerFromMiddleware(infuraMiddleware)
+ const blockTracker = new BlockTracker({ provider: infuraProvider })
const networkMiddleware = mergeMiddleware([
createBlockCacheMiddleware({ blockTracker }),
createInflightMiddleware(),
- createBlockReEmitMiddleware({ blockTracker, provider: blockProvider }),
+ createBlockReRefMiddleware({ blockTracker, provider: infuraProvider }),
+ createRetryOnEmptyMiddleware({ blockTracker, provider: infuraProvider }),
createBlockTrackerInspectorMiddleware({ blockTracker }),
infuraMiddleware,
])
diff --git a/app/scripts/controllers/network/createJsonRpcClient.js b/app/scripts/controllers/network/createJsonRpcClient.js
index 40c353f7f..a8cbf2aaf 100644
--- a/app/scripts/controllers/network/createJsonRpcClient.js
+++ b/app/scripts/controllers/network/createJsonRpcClient.js
@@ -1,6 +1,6 @@
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
const createFetchMiddleware = require('eth-json-rpc-middleware/fetch')
-const createBlockRefMiddleware = require('eth-json-rpc-middleware/block-ref')
+const createBlockRefRewriteMiddleware = require('eth-json-rpc-middleware/block-ref-rewrite')
const createBlockCacheMiddleware = require('eth-json-rpc-middleware/block-cache')
const createInflightMiddleware = require('eth-json-rpc-middleware/inflight-cache')
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
@@ -15,7 +15,7 @@ function createJsonRpcClient ({ rpcUrl }) {
const blockTracker = new BlockTracker({ provider: blockProvider })
const networkMiddleware = mergeMiddleware([
- createBlockRefMiddleware({ blockTracker }),
+ createBlockRefRewriteMiddleware({ blockTracker }),
createBlockCacheMiddleware({ blockTracker }),
createInflightMiddleware(),
createBlockTrackerInspectorMiddleware({ blockTracker }),
diff --git a/app/scripts/controllers/network/createLocalhostClient.js b/app/scripts/controllers/network/createLocalhostClient.js
index fecc512e8..09b1d3c1c 100644
--- a/app/scripts/controllers/network/createLocalhostClient.js
+++ b/app/scripts/controllers/network/createLocalhostClient.js
@@ -1,6 +1,6 @@
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
const createFetchMiddleware = require('eth-json-rpc-middleware/fetch')
-const createBlockRefMiddleware = require('eth-json-rpc-middleware/block-ref')
+const createBlockRefRewriteMiddleware = require('eth-json-rpc-middleware/block-ref-rewrite')
const createBlockTrackerInspectorMiddleware = require('eth-json-rpc-middleware/block-tracker-inspector')
const providerFromMiddleware = require('eth-json-rpc-middleware/providerFromMiddleware')
const BlockTracker = require('eth-block-tracker')
@@ -13,7 +13,7 @@ function createLocalhostClient () {
const blockTracker = new BlockTracker({ provider: blockProvider, pollingInterval: 1000 })
const networkMiddleware = mergeMiddleware([
- createBlockRefMiddleware({ blockTracker }),
+ createBlockRefRewriteMiddleware({ blockTracker }),
createBlockTrackerInspectorMiddleware({ blockTracker }),
fetchMiddleware,
])
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index d924be516..431702d63 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -5,6 +5,7 @@ const log = require('loglevel')
const LocalMessageDuplexStream = require('post-message-stream')
const setupDappAutoReload = require('./lib/auto-reload.js')
const MetamaskInpageProvider = require('metamask-inpage-provider')
+
restoreContextAfterImports()
log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
@@ -44,7 +45,15 @@ inpageProvider.enable = function (options = {}) {
})
}
-window.ethereum = inpageProvider
+// Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound
+// `sendAsync` method on the prototype, causing `this` reference issues with drizzle
+const proxiedInpageProvider = new Proxy(inpageProvider, {
+ // straight up lie that we deleted the property so that it doesnt
+ // throw an error in strict mode
+ deleteProperty: () => true,
+})
+
+window.ethereum = proxiedInpageProvider
//
// setup web3
@@ -58,7 +67,7 @@ if (typeof window.web3 !== 'undefined') {
and try again.`)
}
-var web3 = new Web3(inpageProvider)
+var web3 = new Web3(proxiedInpageProvider)
web3.setProvider = function () {
log.debug('MetaMask - overrode web3.setProvider')
}
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,