diff --git a/src/Screens/CreateProject.js b/src/Screens/CreateProject.js index 7dc4d9b..1d01def 100644 --- a/src/Screens/CreateProject.js +++ b/src/Screens/CreateProject.js @@ -36,7 +36,9 @@ const CreateProject = () => { ); } - const accounts = await web3.eth.getAccounts(); + const accounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); await factory.methods .createProject( diff --git a/src/Screens/CreateRequest.js b/src/Screens/CreateRequest.js index a87b6f5..043b689 100644 --- a/src/Screens/CreateRequest.js +++ b/src/Screens/CreateRequest.js @@ -28,7 +28,9 @@ const CreateRequest = () => { "Please Login with a metamask account to make a transaction." ); } - const accounts = await web3.eth.getAccounts(); + const accounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); const project = Project(projectAddress); await project.methods.createRequest(description, value, recipient).send({ from: accounts[0], diff --git a/src/Screens/HomeScreen.js b/src/Screens/HomeScreen.js index c8ab791..aef1003 100644 --- a/src/Screens/HomeScreen.js +++ b/src/Screens/HomeScreen.js @@ -6,9 +6,11 @@ import { Col, Container, Nav, Navbar, Row } from "react-bootstrap"; import Project from "../components/Project"; import Loader from "../components/Loader"; import { LinkContainer } from "react-router-bootstrap"; +import Message from "../components/Message"; const HomeScreen = () => { const [projectList, setProjectList] = useState([]); const [isLoading, setIsLoading] = useState(0); + const [error, setError] = useState(""); useEffect(() => { const loadData = async () => { setIsLoading(1); @@ -18,7 +20,7 @@ const HomeScreen = () => { .call(); setProjectList(newProjectList); } catch (err) { - console.log(err.message); + console.log(err); } setIsLoading(0); }; @@ -64,6 +66,7 @@ const HomeScreen = () => {
{projectList.length}
projects funded
+ {error && {error}} {isLoading ? ( ) : ( diff --git a/src/Screens/ProjectScreen.js b/src/Screens/ProjectScreen.js index 47d51ec..94b2e1a 100644 --- a/src/Screens/ProjectScreen.js +++ b/src/Screens/ProjectScreen.js @@ -74,12 +74,14 @@ const ProjectScreen = () => { "Amount must be greater than or equal to the minimum contribution." ); } - if (window.web3 == undefined) { + if (window.ethereum == undefined) { throw new Error( "Please Login with a metamask account to make a transaction." ); } - const accounts = await web3.eth.getAccounts(); + const accounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); const project = Project(projectAddress); await project.methods.contribute().send({ from: accounts[0], diff --git a/src/Screens/RequestScreen.js b/src/Screens/RequestScreen.js index d83d576..06b1d6e 100644 --- a/src/Screens/RequestScreen.js +++ b/src/Screens/RequestScreen.js @@ -42,7 +42,10 @@ const RequestScreen = () => { const currentManager = await project.methods.manager().call(); setManager(currentManager); - const currentAccounts = await web3.eth.getAccounts(); + const currentAccounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); + setAccounts(currentAccounts); const currentRequestCount = await project.methods @@ -90,6 +93,7 @@ const RequestScreen = () => { "Please Login with a metamask account to make a transaction." ); } + const project = Project(projectAddress); await project.methods.approveRequest(e.target.id).send({ @@ -174,7 +178,6 @@ const RequestScreen = () => { {requests.map((req, i) => { - console.log(req); return ( {req.id} diff --git a/src/components/Header.js b/src/components/Header.js index e4163a0..31331ec 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -8,11 +8,10 @@ const Header = () => { const [userInfo, setUserInfo] = useState(""); useEffect(() => { const loadData = async () => { - console.log("Header.js window.web3", window.web3); if (window.web3 != undefined) { - console.log("Header.js web3", web3); - const accounts = await web3.eth.getAccounts(); - console.log("Header.js accounts", accounts); + const accounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); setUserInfo(accounts[0]); } }; diff --git a/src/ethereum/defaultFactory.js b/src/ethereum/defaultFactory.js index ce31d17..3e5b341 100644 --- a/src/ethereum/defaultFactory.js +++ b/src/ethereum/defaultFactory.js @@ -1,7 +1,6 @@ import web3 from "./web3Default"; import ProjectFactory from "./build/ProjectFactory.json"; -console.log(process.env.REACT_APP_DEPLOYED_FACTORY_ADDRESS); const instance = new web3.eth.Contract( ProjectFactory.abi, process.env.REACT_APP_DEPLOYED_FACTORY_ADDRESS diff --git a/src/ethereum/web3.js b/src/ethereum/web3.js index 71b39f0..8cfa5a1 100644 --- a/src/ethereum/web3.js +++ b/src/ethereum/web3.js @@ -1,18 +1,11 @@ import Web3 from "web3"; -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); - } -}); +let web3; +if (window.web3 !== undefined) { + web3 = new Web3(window.web3.currentProvider); +} else { + const provider = new Web3.providers.HttpProvider( + process.env.REACT_APP_SEPOLIA + ); + web3 = new Web3(provider); +} export default web3;