aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/controllers/network/createInfuraClient.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/scripts/controllers/network/createInfuraClient.js b/app/scripts/controllers/network/createInfuraClient.js
index 326bcb355..c70fa9e38 100644
--- a/app/scripts/controllers/network/createInfuraClient.js
+++ b/app/scripts/controllers/network/createInfuraClient.js
@@ -1,4 +1,5 @@
const mergeMiddleware = require('json-rpc-engine/src/mergeMiddleware')
+const createScaffoldMiddleware = require('json-rpc-engine/src/createScaffoldMiddleware')
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')
@@ -16,6 +17,7 @@ function createInfuraClient ({ network }) {
const blockTracker = new BlockTracker({ provider: infuraProvider })
const networkMiddleware = mergeMiddleware([
+ createNetworkAndChainIdMiddleware({ network }),
createBlockCacheMiddleware({ blockTracker }),
createInflightMiddleware(),
createBlockReRefMiddleware({ blockTracker, provider: infuraProvider }),
@@ -25,3 +27,34 @@ function createInfuraClient ({ network }) {
])
return { networkMiddleware, blockTracker }
}
+
+function createNetworkAndChainIdMiddleware({ network }) {
+ let chainId
+ let netId
+
+ switch (network) {
+ case 'mainnet':
+ netId = '1'
+ chainId = '0x01'
+ break
+ case 'ropsten':
+ netId = '3'
+ chainId = '0x03'
+ break
+ case 'rinkeby':
+ netId = '4'
+ chainId = '0x04'
+ break
+ case 'kovan':
+ netId = '42'
+ chainId = '0x2a'
+ break
+ default:
+ throw new Error(`createInfuraClient - unknown network "${network}"`)
+ }
+
+ return createScaffoldMiddleware({
+ eth_chainId: chainId,
+ net_version: netId,
+ })
+}