Skip to content

Commit

Permalink
fourth Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratnesh4193 committed Oct 29, 2023
1 parent ba0da05 commit cc7d8d8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/Screens/CreateProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/Screens/CreateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion src/Screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -18,7 +20,7 @@ const HomeScreen = () => {
.call();
setProjectList(newProjectList);
} catch (err) {
console.log(err.message);
console.log(err);
}
setIsLoading(0);
};
Expand Down Expand Up @@ -64,6 +66,7 @@ const HomeScreen = () => {
<div className="display-6 text-success">{projectList.length}</div>
<div>projects funded</div>
</Container>
{error && <Message>{error}</Message>}
{isLoading ? (
<Loader />
) : (
Expand Down
6 changes: 4 additions & 2 deletions src/Screens/ProjectScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
7 changes: 5 additions & 2 deletions src/Screens/RequestScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -174,7 +178,6 @@ const RequestScreen = () => {

<tbody>
{requests.map((req, i) => {
console.log(req);
return (
<tr key={i}>
<th>{req.id}</th>
Expand Down
7 changes: 3 additions & 4 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
};
Expand Down
1 change: 0 additions & 1 deletion src/ethereum/defaultFactory.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 9 additions & 16 deletions src/ethereum/web3.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit cc7d8d8

Please sign in to comment.