From 86f09e6bb53bb90e524366c1f225cc9005e01a2a Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 5 Nov 2018 14:13:37 -0500 Subject: network - infura - hardcode net_version and eth_chainId (#5670) * network - infura - hardcode net_version and eth_chainId * network - infura - add rinkeby handling * lint fix --- .../controllers/network/createInfuraClient.js | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'app/scripts') 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, + }) +} -- cgit v1.2.3