From 92dfe77d5dcc86bb750a4cc1197106037dfe9ca2 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Fri, 29 Sep 2023 23:25:47 +0530 Subject: [PATCH 1/9] update: Home page with activity status --- src/component/Card.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/component/Card.js b/src/component/Card.js index 042b3b1..5f50cb7 100644 --- a/src/component/Card.js +++ b/src/component/Card.js @@ -44,15 +44,21 @@ const Card = ({userAddress}) => { const now = Date.now(); console.log("now is",now,Number(end)*1000) - if(now>=(Number(start)*1000)&&now<=(Number(end)*1000)){ - return(true); + if(now<(Number(start)*1000)){ + return("Upcoming"); + } + else if(now>(Number(start)*1000) && now<(Number(end)*1000)){ + return("Active"); + } + else if(now>(Number(end)*1000)){ + return("Ended"); } else{ - - return(false); + return("Not declared"); } + } const data = async ()=>{ const user = await contract.owner(); @@ -111,7 +117,7 @@ const Card = ({userAddress}) => { Status:{" "}

- {checkActive(item[1],item[2])?"Active":"Not Active"} + {checkActive(item[1],item[2])}

@@ -147,4 +153,4 @@ const Card = ({userAddress}) => { ); }; -export default Card; +export default Card; \ No newline at end of file From d61b38718a6a418f96e719837702822b984a44e7 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Sun, 1 Oct 2023 15:15:52 +0530 Subject: [PATCH 2/9] update: Contract address, Add: alert on error --- src/Signature.js | 2 +- src/component/Dashboard.js | 1 + src/connectContract.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Signature.js b/src/Signature.js index 42d121c..07d4093 100644 --- a/src/Signature.js +++ b/src/Signature.js @@ -8,7 +8,7 @@ function Signature() { name: "Abdul-DAO-8955", version: "675", chainId: 80001, - verifyingContract: "0x9C820370857E403aD50a687c6FDbAC4e2a763C97", + verifyingContract: "0x8B1150881d121e9a6f0c38e5E6CcF5732302394F", }; const value = { diff --git a/src/component/Dashboard.js b/src/component/Dashboard.js index 695697e..b395f82 100644 --- a/src/component/Dashboard.js +++ b/src/component/Dashboard.js @@ -56,6 +56,7 @@ const Dashboard = () => { window.location.href = "/" }catch(error){ console.log(error); + alert(error.reason); } } diff --git a/src/connectContract.js b/src/connectContract.js index ac735a6..d599c4e 100644 --- a/src/connectContract.js +++ b/src/connectContract.js @@ -4,7 +4,7 @@ let signer; let tokenContract; const connectContract = () => { try { - const Address = "0x9C820370857E403aD50a687c6FDbAC4e2a763C97"; + const Address = "0x8B1150881d121e9a6f0c38e5E6CcF5732302394F"; const Abi = [ { inputs: [ From fb9b0b88ba4af40f915bc29d126d59942dc74c64 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Mon, 9 Oct 2023 23:51:32 +0530 Subject: [PATCH 3/9] Update: connect deployed api --- src/component/Dashboard.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/component/Dashboard.js b/src/component/Dashboard.js index b395f82..00c1225 100644 --- a/src/component/Dashboard.js +++ b/src/component/Dashboard.js @@ -23,7 +23,7 @@ const Dashboard = () => { useEffect(() => { const user = Cookies.get("user"); setTotalInvestment(JSON.parse(user).total_investment); - const apiURL = "http://localhost:5000/getAmount/"+JSON.parse(user).user_id; + const apiURL = "http://93.188.163.252:5000/getAmount/"+JSON.parse(user).user_id; axios.get(apiURL).then((res)=>{ console.log(res.data.amount); setClaimAmount(res.data.amount); @@ -47,7 +47,7 @@ const Dashboard = () => { const res = await contract.redeem(voucher); const tx = await res.wait(); console.log(tx); - const update = axios.post("http://localhost:5000/update",{ + const update = axios.post("http://93.188.163.252:5000/update",{ user:username, amount:amount }) From 04ef1db153165bb7d357c9ec8c78d9d62558aec4 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Tue, 10 Oct 2023 16:19:12 +0530 Subject: [PATCH 4/9] Update: Add loader, fix progress bar in proposal --- src/component/Card.js | 14 +++++++++++++- src/component/Details.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/component/Card.js b/src/component/Card.js index 5f50cb7..9083718 100644 --- a/src/component/Card.js +++ b/src/component/Card.js @@ -7,6 +7,7 @@ const Card = ({userAddress}) => { const [isOwner,setIsOwner] = useState(); const [account, setAccount] = useState(''); const [isActive, setIsActive] = useState(); + const [loader, setLoader] = useState(false); //connect to metamask useEffect(() => { if(window.ethereum){ @@ -17,6 +18,7 @@ const Card = ({userAddress}) => { }, []); const getAllProposal = async () => { console.log("user is",userAddress) + setLoader(true); try{ const owner = await contract.owner(); console.log("owner is",owner,userAddress) @@ -29,9 +31,11 @@ const Card = ({userAddress}) => { proposals.push(element) }); setproposal(proposals); + setLoader(false); }catch(error){ console.log(error) alert(error) + setLoader(false); } } @@ -72,7 +76,13 @@ const Card = ({userAddress}) => { return ( <>
-
+ { + (loader)?
+ +
+ :
{proposal.map((item,index)=>(
@@ -148,6 +158,8 @@ const Card = ({userAddress}) => {
))}
+ } +
); diff --git a/src/component/Details.js b/src/component/Details.js index d68615c..5881eb2 100644 --- a/src/component/Details.js +++ b/src/component/Details.js @@ -62,7 +62,7 @@ export const Details = ({userAddress}) => { const element = data[5][i]; const adminelement = data[6][i]; votes.push((Number(element)+Number(adminelement))/10**18); - total = total +( Number(element) + Number(adminelement)/10**18); + total = total +( (Number(element) + Number(adminelement))/10**18); if(Number(element)>maxvalue) if(maxvalue===0){max =i;} maxvalue=Number(element); } From 01d7d7b46005b1778f2b2f66cc943d77159ec782 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Mon, 16 Oct 2023 16:01:14 +0530 Subject: [PATCH 5/9] Update: login and investment api and build command --- .gitignore | 3 ++- api/index.js | 2 +- package.json | 2 +- src/component/Dashboard.js | 4 ++-- src/component/Login.js | 36 +++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 29ad0af..9fa8569 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules -/_MACOSX \ No newline at end of file +/_MACOSX +/build diff --git a/api/index.js b/api/index.js index 582340d..133c5a1 100644 --- a/api/index.js +++ b/api/index.js @@ -8,7 +8,7 @@ const port = process.env.PORT || 5000; app.use(express.json()); app.use(cors()); -const dbURI = "mongodb+srv://dao:dao@cluster0.99uhnut.mongodb.net/?retryWrites=true&w=majority" ; +const dbURI = "mongodb+srv://ravi:ravi@cluster0.2rdjws6.mongodb.net/" ; mongoose.connect(dbURI, { diff --git a/package.json b/package.json index 9e40e0a..ab92184 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "set \"GENERATE_SOURCEMAP=false\" && react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/src/component/Dashboard.js b/src/component/Dashboard.js index 00c1225..093441a 100644 --- a/src/component/Dashboard.js +++ b/src/component/Dashboard.js @@ -23,7 +23,7 @@ const Dashboard = () => { useEffect(() => { const user = Cookies.get("user"); setTotalInvestment(JSON.parse(user).total_investment); - const apiURL = "http://93.188.163.252:5000/getAmount/"+JSON.parse(user).user_id; + const apiURL = "https://api.prpcommunity.net/getAmount/"+JSON.parse(user).user_id; axios.get(apiURL).then((res)=>{ console.log(res.data.amount); setClaimAmount(res.data.amount); @@ -47,7 +47,7 @@ const Dashboard = () => { const res = await contract.redeem(voucher); const tx = await res.wait(); console.log(tx); - const update = axios.post("http://93.188.163.252:5000/update",{ + const update = axios.post("https://api.prpcommunity.net/update",{ user:username, amount:amount }) diff --git a/src/component/Login.js b/src/component/Login.js index 9dad4f9..3b530f0 100644 --- a/src/component/Login.js +++ b/src/component/Login.js @@ -3,27 +3,29 @@ import axios from "axios"; import Cookies from 'js-cookie'; const Hero = ({userAddress}) => { - const [email, setEmail] = useState(""); + const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(); - - const apiUrl = 'https://dapps.12foxs.com/investement_api'; - const urlWithParams = `${apiUrl}?user_id=${email}&password=${password}`; + const url = "https://propertyrobots.com/api/ReturnSelfInvestment?AmbassadorID=123771&Password=1234&APIKey=DSFKJ47FDJK4S4998KS" + const apiUrl = 'https://propertyrobots.com/api/ReturnSelfInvestment'; + const urlWithParams = `${apiUrl}?AmbassadorID=${username}&Password=${password}&APIKey=DSFKJ47FDJK4S4998KS`; const handleSubmit = async (e) => { console.log(userAddress) if(!userAddress){alert("please connect wallet"); return;} - axios.get(urlWithParams).then(response =>{ - console.log(response.data) - if(response.data.total_investment){ - console.log(response.data.total_investment) - Cookies.set('user', JSON.stringify({user_id : email, total_investment : response.data.total_investment})) - window.location.href= "/" - }else{ - setError(response.data.error) - } + axios.get(url).then(response =>{ + console.log(response) + console.log(response.AmbassadorID); + // if(response.data.total_investment){ + // // console.log(response.data.total_investment) + // // Cookies.set('user', JSON.stringify({user_id : response.data.FullName, total_investment : response.data.SelfInvestment, AmbassadorID: response.data.AmbassadorID})) + // // window.location.href= "/" + // }else{ + // console.log(response.error) + // // setError(response.data.error) + // } }).catch(error=>{ console.log(error); setError(error); @@ -42,9 +44,9 @@ const Hero = ({userAddress}) => {
- {setEmail(e.target.value)}} - class="peer w-full h-full bg-transparent text-blue-gray-700 font-sans font-normal outline outline-0 focus:outline-0 disabled:bg-blue-gray-50 disabled:border-0 transition-all placeholder-shown:border placeholder-shown:border-blue-gray-200 placeholder-shown:border-t-blue-gray-200 border focus:border-2 border-t-transparent focus:border-t-transparent text-md px-3 py-3 rounded-md border-blue-gray-200 focus:border-blue-500" placeholder=" " /> + {setUsername(e.target.value)}} + class="peer w-full h-full bg-transparent text-blue-gray-700 font-sans font-normal outline outline-0 focus:outline-0 disabled:bg-blue-gray-50 disabled:border-0 transition-all placeholder-shown:border placeholder-shown:border-blue-gray-200 placeholder-shown:border-t-blue-gray-200 border focus:border-2 border-t-transparent focus:border-t-transparent text-md px-3 py-3 rounded-md border-blue-gray-200 focus:border-blue-500" placeholder=" " />
{ onClick = {handleSubmit} >Sign In {/* error */} - {error &&

{error}

} + {/* {error &&

{error}

} */}

Don't have an account? Signup From 4fcdd679d3a295f5ea4ca619bc15b2bbe3b7272b Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Fri, 20 Oct 2023 23:07:09 +0530 Subject: [PATCH 6/9] Update: integrate deployed api with all testing --- src/component/Dashboard.js | 8 ++++++-- src/component/Login.js | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/component/Dashboard.js b/src/component/Dashboard.js index 093441a..551cbf2 100644 --- a/src/component/Dashboard.js +++ b/src/component/Dashboard.js @@ -23,11 +23,15 @@ const Dashboard = () => { useEffect(() => { const user = Cookies.get("user"); setTotalInvestment(JSON.parse(user).total_investment); - const apiURL = "https://api.prpcommunity.net/getAmount/"+JSON.parse(user).user_id; + const apiURL = "https://api.prpcommunity.net/getAmount/"+JSON.parse(user).AmbassadorID; axios.get(apiURL).then((res)=>{ console.log(res.data.amount); setClaimAmount(res.data.amount); setRestAmount(totalInvestment-res.data.amount) + + }).catch(error=>{ + console.log(error); + setRestAmount(totalInvestment) }) }, [account]); @@ -39,7 +43,7 @@ const Dashboard = () => { try{ if(amount>restAmount){alert("You can't claim more than your investment");return} const user = Cookies.get("user"); - const username = JSON.parse(user).user_id; + const username = JSON.parse(user).AmbassadorID; const date = new Date(); const timestamp = date.getTime(); const signature = await signCreate(account,ethers.utils.parseEther(amount),timestamp); diff --git a/src/component/Login.js b/src/component/Login.js index 3b530f0..c0788e5 100644 --- a/src/component/Login.js +++ b/src/component/Login.js @@ -1,6 +1,7 @@ import React, { useEffect, useState } from "react" import axios from "axios"; import Cookies from 'js-cookie'; +import { json } from "react-router-dom"; const Hero = ({userAddress}) => { const [username, setUsername] = useState(""); @@ -15,17 +16,19 @@ const Hero = ({userAddress}) => { const handleSubmit = async (e) => { console.log(userAddress) if(!userAddress){alert("please connect wallet"); return;} - axios.get(url).then(response =>{ + axios.get(urlWithParams).then(response =>{ + const jsonData = JSON.parse(response.data); + console.log(jsonData); console.log(response) - console.log(response.AmbassadorID); - // if(response.data.total_investment){ - // // console.log(response.data.total_investment) - // // Cookies.set('user', JSON.stringify({user_id : response.data.FullName, total_investment : response.data.SelfInvestment, AmbassadorID: response.data.AmbassadorID})) - // // window.location.href= "/" - // }else{ - // console.log(response.error) - // // setError(response.data.error) - // } + + if(jsonData.SelfInvestment){ + + Cookies.set('user', JSON.stringify({user_id : jsonData.FullName, total_investment : jsonData.SelfInvestment, AmbassadorID: jsonData.AmbassadorID})) + window.location.href= "/" + }else{ + console.log(response.error) + setError(response.data.error) + } }).catch(error=>{ console.log(error); setError(error); From 96553a65774b36ecf73e6901a8a15dca9beb1ec6 Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Fri, 20 Oct 2023 23:19:16 +0530 Subject: [PATCH 7/9] fix: login error message issue --- src/component/Login.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/component/Login.js b/src/component/Login.js index c0788e5..ffed57d 100644 --- a/src/component/Login.js +++ b/src/component/Login.js @@ -7,7 +7,7 @@ const Hero = ({userAddress}) => { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(); - const url = "https://propertyrobots.com/api/ReturnSelfInvestment?AmbassadorID=123771&Password=1234&APIKey=DSFKJ47FDJK4S4998KS" + const apiUrl = 'https://propertyrobots.com/api/ReturnSelfInvestment'; const urlWithParams = `${apiUrl}?AmbassadorID=${username}&Password=${password}&APIKey=DSFKJ47FDJK4S4998KS`; @@ -19,19 +19,17 @@ const Hero = ({userAddress}) => { axios.get(urlWithParams).then(response =>{ const jsonData = JSON.parse(response.data); console.log(jsonData); - console.log(response) - - if(jsonData.SelfInvestment){ + if(jsonData.StatusCode===200){ Cookies.set('user', JSON.stringify({user_id : jsonData.FullName, total_investment : jsonData.SelfInvestment, AmbassadorID: jsonData.AmbassadorID})) window.location.href= "/" }else{ - console.log(response.error) - setError(response.data.error) + console.log(jsonData.StatusCode) + setError(jsonData.Message) } }).catch(error=>{ console.log(error); - setError(error); + setError("Username or password is incorrect"); }) } return ( @@ -74,8 +72,8 @@ const Hero = ({userAddress}) => { - {/* error */} - {/* {error &&

{error}

} */} + + {error &&

{error}

}

Don't have an account? Signup From 7ff0d8a94e3c6db47287bb18e7aeb729f86f88ff Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Fri, 20 Oct 2023 23:23:48 +0530 Subject: [PATCH 8/9] fix: datatype error in login page --- src/component/Login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/Login.js b/src/component/Login.js index ffed57d..198701a 100644 --- a/src/component/Login.js +++ b/src/component/Login.js @@ -19,7 +19,7 @@ const Hero = ({userAddress}) => { axios.get(urlWithParams).then(response =>{ const jsonData = JSON.parse(response.data); console.log(jsonData); - if(jsonData.StatusCode===200){ + if(jsonData.StatusCode==="200"){ Cookies.set('user', JSON.stringify({user_id : jsonData.FullName, total_investment : jsonData.SelfInvestment, AmbassadorID: jsonData.AmbassadorID})) window.location.href= "/" From 59401adfaa50a477f27bf69c03a4f66ef2d3df7b Mon Sep 17 00:00:00 2001 From: Mohit Goyal Date: Sat, 28 Oct 2023 15:18:06 +0530 Subject: [PATCH 9/9] fix: vote function, wallet connectivity, Update: contract --- src/adminSignature.js | 41 +++ src/component/Card.js | 42 +-- src/component/Details.js | 18 +- src/component/Login.js | 2 +- src/connectContract.js | 686 +++++++++++++++++++++++---------------- 5 files changed, 484 insertions(+), 305 deletions(-) create mode 100644 src/adminSignature.js diff --git a/src/adminSignature.js b/src/adminSignature.js new file mode 100644 index 0000000..3d27ebc --- /dev/null +++ b/src/adminSignature.js @@ -0,0 +1,41 @@ +import { ethers } from "ethers"; + + const SIGNING_DOMAIN_NAME = "Abdul-DAO-8955" + const SIGNING_DOMAIN_VERSION = "675" + const chainId = 80001 + const contractAddress = "0xB48dbC24F8D883A5890f97d2054a5b0c4E49C735" // Put the address here from remix + const provider = new ethers.providers.Web3Provider(window.ethereum); + const signer = provider.getSigner(); + const domain = { + name: SIGNING_DOMAIN_NAME, + version: SIGNING_DOMAIN_VERSION, + verifyingContract: contractAddress, + chainId + } + + async function createVoucher(user, proposalId, option, numberOfVotes, time) { + const voucher = { user, proposalId, option, numberOfVotes, time } + const types = { + VoteVoucher2: [ + { name: "user", type: "address" }, + { name: "proposalId", type: "uint256" }, + { name: "option", type: "uint256" }, + { name: "numberOfVotes", type: "uint256" }, + { name: "time", type: "uint256" } + ] + } + console.log("domain, types, voucher : ", domain, types, voucher); + const signature = await signer._signTypedData(domain, types, voucher) + return { + ...voucher, + signature + } + } + + async function main(user, proposalId, option, numberOfVotes) { + const voucher = await createVoucher(user, proposalId, option, numberOfVotes, parseInt(Date.now() / 1000)) // the address is the address which receives the NFT + console.log(`[${voucher.user}, ${voucher.proposalId}, "${voucher.option}", "${voucher.numberOfVotes}","${voucher.time}", "${voucher.signature}"]`) + return voucher; + } + + export default main; \ No newline at end of file diff --git a/src/component/Card.js b/src/component/Card.js index 9083718..2b6d4ba 100644 --- a/src/component/Card.js +++ b/src/component/Card.js @@ -3,18 +3,21 @@ import { NavLink } from "react-router-dom"; import {contract} from "../connectContract" const Card = ({userAddress}) => { - const [proposal ,setproposal] = useState([]); + const [proposal ,setproposal] = useState([]); const [isOwner,setIsOwner] = useState(); const [account, setAccount] = useState(''); const [isActive, setIsActive] = useState(); const [loader, setLoader] = useState(false); //connect to metamask useEffect(() => { - if(window.ethereum){ - window.ethereum.request({ method: 'eth_requestAccounts' }).then((res)=>{ - setAccount(res[0]); - }) - } + window.ethereum.request({ method: 'eth_requestAccounts' }) + .then((res) => { + setAccount(res[0]); + userAddress = res[0]; + }) + .catch((err) => { + console.log(err); + }); }, []); const getAllProposal = async () => { console.log("user is",userAddress) @@ -73,7 +76,7 @@ const Card = ({userAddress}) => { data() },[account]) console.log("proposals is",proposal) - return ( + return ( <>

{ @@ -98,26 +101,7 @@ const Card = ({userAddress}) => { {item[3]}
- {/*

- A) Yes (10%) -

-

- B) No (12.34%) -

-

- C) None (77.66%) -

*/} - {/*
-
- - 77.66% Sold - -
-
-
*/} +
@@ -138,10 +122,10 @@ const Card = ({userAddress}) => { - + {isOwner?