Fix Infura network chain IDs (#8629)

feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent 33b15b5c6f
commit 4839e31e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      app/scripts/controllers/network/createInfuraClient.js

@ -7,7 +7,8 @@ import createBlockTrackerInspectorMiddleware from 'eth-json-rpc-middleware/block
import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware' import providerFromMiddleware from 'eth-json-rpc-middleware/providerFromMiddleware'
import createInfuraMiddleware from 'eth-json-rpc-infura' import createInfuraMiddleware from 'eth-json-rpc-infura'
import BlockTracker from 'eth-block-tracker' 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 }) { export default function createInfuraClient({ network, projectId }) {
const infuraMiddleware = createInfuraMiddleware({ const infuraMiddleware = createInfuraMiddleware({
@ -32,36 +33,14 @@ export default function createInfuraClient({ network, projectId }) {
} }
function createNetworkAndChainIdMiddleware({ network }) { function createNetworkAndChainIdMiddleware({ network }) {
let chainId if (!NETWORK_TYPE_TO_ID_MAP[network]) {
let netId throw new Error(`createInfuraClient - unknown network "${network}"`)
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}"`)
} }
const { chainId, networkId } = NETWORK_TYPE_TO_ID_MAP[network]
return createScaffoldMiddleware({ return createScaffoldMiddleware({
eth_chainId: chainId, eth_chainId: chainId,
net_version: netId, net_version: networkId,
}) })
} }

Loading…
Cancel
Save