1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 20:02:58 +01:00

Fix Infura network chain IDs (#8629)

This commit is contained in:
Erik Marks 2020-12-07 11:39:39 -08:00 committed by GitHub
parent 33b15b5c6f
commit 4839e31e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,8 @@ import createBlockTrackerInspectorMiddleware from 'eth-json-rpc-middleware/block
import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware'
import createInfuraMiddleware from 'eth-json-rpc-infura'
import BlockTracker from 'eth-block-tracker'
import * as networkEnums from './enums'
import { NETWORK_TYPE_TO_ID_MAP } from './enums'
export default function createInfuraClient({ network, projectId }) {
const infuraMiddleware = createInfuraMiddleware({
@ -32,36 +33,14 @@ export default function createInfuraClient({ network, projectId }) {
}
function createNetworkAndChainIdMiddleware({ network }) {
let chainId
let netId
switch (network) {
case 'mainnet':
netId = networkEnums.MAINNET_NETWORK_ID
chainId = '0x01'
break
case 'ropsten':
netId = networkEnums.ROPSTEN_NETWORK_ID
chainId = '0x03'
break
case 'rinkeby':
netId = networkEnums.RINKEBY_NETWORK_ID
chainId = '0x04'
break
case 'kovan':
netId = networkEnums.KOVAN_NETWORK_ID
chainId = networkEnums.KOVAN_CHAIN_ID
break
case 'goerli':
netId = networkEnums.GOERLI_NETWORK_ID
chainId = '0x05'
break
default:
throw new Error(`createInfuraClient - unknown network "${network}"`)
if (!NETWORK_TYPE_TO_ID_MAP[network]) {
throw new Error(`createInfuraClient - unknown network "${network}"`)
}
const { chainId, networkId } = NETWORK_TYPE_TO_ID_MAP[network]
return createScaffoldMiddleware({
eth_chainId: chainId,
net_version: netId,
net_version: networkId,
})
}