Skip to content

Commit

Permalink
Make chainId available in the metamask-inpage-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Sep 5, 2019
1 parent 1e7b37d commit 1f80f3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/scripts/lib/select-chain-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const standardNetworkId = {
'1': '0x01',
'3': '0x03',
'4': '0x04',
'42': '0x2a',
'5': '0x05',
}

function selectChainId (metamaskState) {
const { network, provider: { chaindId } } = metamaskState
return standardNetworkId[network] || parseInt(chaindId, 10).toString(16)
}

module.exports = selectChainId
4 changes: 3 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ProviderApprovalController = require('./controllers/provider-approval')
const nodeify = require('./lib/nodeify')
const accountImporter = require('./account-import-strategies')
const getBuyEthUrl = require('./lib/buy-eth-url')
const selectChainId = require('./lib/select-chain-id')
const {Mutex} = require('await-semaphore')
const {version} = require('../manifest.json')
const {BN} = require('ethereumjs-util')
Expand Down Expand Up @@ -360,7 +361,7 @@ module.exports = class MetamaskController extends EventEmitter {
publicConfigStore.putState(publicState)
}

function selectPublicState ({ isUnlocked, selectedAddress, network, completedOnboarding }) {
function selectPublicState ({ isUnlocked, selectedAddress, network, completedOnboarding, provider }) {
const isEnabled = checkIsEnabled()
const isReady = isUnlocked && isEnabled
const result = {
Expand All @@ -369,6 +370,7 @@ module.exports = class MetamaskController extends EventEmitter {
selectedAddress: isReady ? selectedAddress : undefined,
networkVersion: network,
onboardingcomplete: completedOnboarding,
chainId: selectChainId({ network, provider }),
}
return result
}
Expand Down

0 comments on commit 1f80f3a

Please sign in to comment.