Web3Modal: getNetId function refactoring

pull/4931/head
Viktor Baranov 3 years ago
parent ec85c23ffa
commit f409c82836
  1. 7
      apps/block_scout_web/assets/js/pages/stakes.js

@ -376,17 +376,22 @@ async function getAccounts () {
} }
async function getNetId (web3) { async function getNetId (web3) {
if (window.web3 && window.web3.currentProvider && window.web3.currentProvider.wc) {
return window.web3.currentProvider.chainId
} else {
let netId = window.ethereum.chainId let netId = window.ethereum.chainId
if (!netId) { if (!netId) {
netId = await window.ethereum.request({ method: 'eth_chainId' }) netId = await window.ethereum.request({ method: 'eth_chainId' })
} }
if (!netId) { if (!netId) {
console.error(`Cannot get chainId. ${constants.METAMASK_VERSION_WARNING}`) const msg = `Cannot get chainId. ${constants.METAMASK_VERSION_WARNING}`
console.error(msg)
} else { } else {
netId = web3.utils.isHex(netId) ? web3.utils.hexToNumber(netId) : netId netId = web3.utils.isHex(netId) ? web3.utils.hexToNumber(netId) : netId
} }
return netId return netId
} }
}
function hideCurrentModal () { function hideCurrentModal () {
const $modal = currentModal() const $modal = currentModal()

Loading…
Cancel
Save