From 26817392406b15904e74775e76254d022a968cfc Mon Sep 17 00:00:00 2001 From: Ratnesh Date: Mon, 30 Oct 2023 01:38:11 +0530 Subject: [PATCH] Third5 Deployment --- src/ethereum/web3.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ethereum/web3.js b/src/ethereum/web3.js index 465617e..71b39f0 100644 --- a/src/ethereum/web3.js +++ b/src/ethereum/web3.js @@ -1,11 +1,18 @@ import Web3 from "web3"; -let web3; -if (window.web3 !== undefined) { - web3 = new Web3(window.web3.currentProvider); -} else { - const provider = new Web3.providers.HttpProvider( - "https://sepolia.infura.io/v3/ad38a519efd04371b5e1dc45843d733c" - ); - web3 = new Web3(provider); -} +const web3 = new Web3(window.web3.currentProvider); +window.addEventListener("load", async () => { + if (window.ethereum) { + window.web3 = new Web3(window.ethereum); + try { + await window.ethereum.enable(); + } catch (error) {} + } else if (window.web3) { + window.web3 = new Web3(web3.currentProvider); + } else { + const provider = new Web3.providers.HttpProvider( + "https://sepolia.infura.io/v3/ad38a519efd04371b5e1dc45843d733c" + ); + web3 = new Web3(provider); + } +}); export default web3;