From fdf8b0d6c8d27f4ea187fa6da83591b620e88578 Mon Sep 17 00:00:00 2001 From: Tomas Date: Tue, 16 Jul 2024 20:42:49 -0300 Subject: [PATCH] [fix] added web3ModalConfig por sepolia/alpha --- src/context/Web3Context.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/context/Web3Context.js b/src/context/Web3Context.js index a911e3e6..fda45a9e 100644 --- a/src/context/Web3Context.js +++ b/src/context/Web3Context.js @@ -117,9 +117,7 @@ function Web3ContextProvider({ children }) { const isValidNetworkForAlpha = () => { const network = NETWORKS['sepolia'] - return ( - network.config.chainId === chainIdHex - ) + return network.config.chainId === chainIdHex } if (isValidNetwork) { @@ -130,7 +128,7 @@ function Web3ContextProvider({ children }) { setWeb3Error('account_invalid_network') } - if(isValidNetworkForAlpha()) { + if (isValidNetworkForAlpha()) { connectContractsForAlpha(web3Provider.getSigner()) setIsValidNetworkForAlpha(true) } else { @@ -163,8 +161,16 @@ function Web3ContextProvider({ children }) { } function getCurrentNetworkForAlpha() { - const network = NETWORKS['sepolia'].config.chainId === decToHex(chainId) - return network ? NETWORKS['sepolia'] : null + const sepolia = NETWORKS['sepolia'] + const network = sepolia.config.chainId === decToHex(chainId) + sepolia.web3ModalConfig = { + chainId: hexToDec(sepolia.config.chainId), + name: sepolia.config.chainName, + currency: sepolia.config.chainCurrency, + explorerUrl: sepolia.config.chainExplorerUrl, + rpcUrl: sepolia.config.ChainRpcUrl + } + return network ? sepolia : null } function connectContracts(_signer) { @@ -261,7 +267,7 @@ function Web3ContextProvider({ children }) { } } - function connectContractsForAlpha (_signer) { + function connectContractsForAlpha(_signer) { try { const _contracts = getCurrentNetworkForAlpha().contracts @@ -319,7 +325,7 @@ function Web3ContextProvider({ children }) { setIsValidNetwork(true) } - if(_chanIdHex === NETWORKS['sepolia'].config.chainId) { + if (_chanIdHex === NETWORKS['sepolia'].config.chainId) { const provider = new ethers.providers.Web3Provider(window.ethereum, 'any') const signer = provider.getSigner() connectContractsForAlpha(signer)