mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
network - infura - hardcode net_version and eth_chainId (#5670)
* network - infura - hardcode net_version and eth_chainId * network - infura - add rinkeby handling * lint fix
This commit is contained in:
parent
4489a57f2f
commit
86f09e6bb5
@ -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,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user