From f409c828367fe2d9887bbba870667ed2b05b72df Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Mon, 29 Nov 2021 20:11:44 +0400 Subject: [PATCH] Web3Modal: getNetId function refactoring --- .../block_scout_web/assets/js/pages/stakes.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/stakes.js b/apps/block_scout_web/assets/js/pages/stakes.js index b2ec7b3545..88e0977f32 100644 --- a/apps/block_scout_web/assets/js/pages/stakes.js +++ b/apps/block_scout_web/assets/js/pages/stakes.js @@ -376,16 +376,21 @@ async function getAccounts () { } async function getNetId (web3) { - let netId = window.ethereum.chainId - if (!netId) { - netId = await window.ethereum.request({ method: 'eth_chainId' }) - } - if (!netId) { - console.error(`Cannot get chainId. ${constants.METAMASK_VERSION_WARNING}`) + if (window.web3 && window.web3.currentProvider && window.web3.currentProvider.wc) { + return window.web3.currentProvider.chainId } else { - netId = web3.utils.isHex(netId) ? web3.utils.hexToNumber(netId) : netId + let netId = window.ethereum.chainId + if (!netId) { + netId = await window.ethereum.request({ method: 'eth_chainId' }) + } + if (!netId) { + const msg = `Cannot get chainId. ${constants.METAMASK_VERSION_WARNING}` + console.error(msg) + } else { + netId = web3.utils.isHex(netId) ? web3.utils.hexToNumber(netId) : netId + } + return netId } - return netId } function hideCurrentModal () {