Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/_MACOSX
/_MACOSX
/build
2 changes: 1 addition & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Signature() {
name: "Abdul-DAO-8955",
version: "675",
chainId: 80001,
verifyingContract: "0x9C820370857E403aD50a687c6FDbAC4e2a763C97",
verifyingContract: "0x8B1150881d121e9a6f0c38e5E6CcF5732302394F",
};

const value = {
Expand Down
41 changes: 41 additions & 0 deletions src/adminSignature.js
Original file line number Diff line number Diff line change
@@ -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;
74 changes: 38 additions & 36 deletions src/component/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ 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)
setLoader(true);
try{
const owner = await contract.owner();
console.log("owner is",owner,userAddress)
Expand All @@ -29,9 +34,11 @@ const Card = ({userAddress}) => {
proposals.push(element)
});
setproposal(proposals);
setLoader(false);
}catch(error){
console.log(error)
alert(error)
setLoader(false);
}
}

Expand All @@ -44,15 +51,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();
Expand All @@ -63,10 +76,16 @@ const Card = ({userAddress}) => {
data()
},[account])
console.log("proposals is",proposal)
return (
return (
<>
<div className="mt-[-105px] mx-auto max-w-[1400px] py-60">
<div className="max-w-[1400px] h-fit grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 space-x-4">
{
(loader)?<div class="w-full h-full fixed block top-0 left-0 bg-white opacity-75 z-50">
<span class="text-blue-500 opacity-75 top-1/2 my-0 mx-auto block relative w-0 h-0 text-3xl" style={{top: "50%"}}>
Loading...
</span>
</div>
:<div className="max-w-[1400px] h-fit grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 space-x-4">
{proposal.map((item,index)=>(
<div key={index}>
<div class=" relative p-4 h-[500px]">
Expand All @@ -82,26 +101,7 @@ const Card = ({userAddress}) => {
{item[3]}
</h1>
<div>
{/* <p className="font-bold text-black/50 text-l">
A) Yes <span>(10%)</span>
</p>
<h1 className="font-bold text-black/50 text-l">
B) No <span>(12.34%)</span>
</h1>
<h1 className="font-bold text-black/50 text-l">
C) None (77.66%)
</h1> */}
{/* <div class="bg-transparent relative rounded-[2rem] mt-0 py-4 mb-2 flex justify-between items-center">
<div class="bg-zinc-100 h-[20px] w-full absolute bottom-0 left-0 rounded-[2rem]">
<span class="text-xs text-center absolute left-[40%] md:left-[45%] py-0.5 font-semibold z-20 text-black/50">
77.66% Sold
</span>
<div
class="py-1 w-full h-full bg-gradient-to-tr from-blue-600 to-blue-400 relative rounded-[2rem] w-[20%]"
style={{ width: "77.66%" }}
></div>
</div>
</div> */}

</div>
<div>
<div className=" w-full flex justify-between items-center text-black/50 font-semibold">
Expand All @@ -111,7 +111,7 @@ const Card = ({userAddress}) => {
Status:{" "}
</p>
<p className="font-bold text-black/50 text-l">
{checkActive(item[1],item[2])?"Active":"Not Active"}
{checkActive(item[1],item[2])}
</p>

</div>
Expand All @@ -122,10 +122,10 @@ const Card = ({userAddress}) => {
<button
class="my-2 middle none font-sans font-bold center capatelize transition-all text-xs py-5 px-6 rounded-lg bg-gradient-to-tr from-blue-600 to-blue-400 text-white shadow-md shadow-blue-500/20 hover:shadow-lg hover:shadow-blue-500/40 active:opacity-[0.85] block w-full"
type="button"
>
>
Details
</button>
</NavLink>
</NavLink>
{isOwner?
<NavLink to={`/editproposal/${index}`}>
<button
Expand All @@ -142,9 +142,11 @@ const Card = ({userAddress}) => {
</div>
))}
</div>
}

</div>
</>
);
};

export default Card;
export default Card;
11 changes: 8 additions & 3 deletions src/component/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ 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 = "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]);
Expand All @@ -39,15 +43,15 @@ 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);
const voucher = [account,ethers.utils.parseEther(amount),timestamp.toString(),signature.signature]
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("https://api.prpcommunity.net/update",{
user:username,
amount:amount
})
Expand All @@ -56,6 +60,7 @@ const Dashboard = () => {
window.location.href = "/"
}catch(error){
console.log(error);
alert(error.reason);
}
}

Expand Down
20 changes: 15 additions & 5 deletions src/component/Details.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
import { useParams } from 'react-router-dom';
import {contract,tokenContract} from "../connectContract"
import { ethers } from "ethers";
import main from "../adminSignature"
export const Details = ({userAddress}) => {
const { id } = useParams();
const[title,setTitle] = useState();
Expand Down Expand Up @@ -62,7 +63,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);
}

Expand All @@ -77,9 +78,12 @@ export const Details = ({userAddress}) => {
useEffect(() => {
getData();
}, [isActive,voteValue]);

console.log("adminsignature",main);
console.log("options",options)
console.log("votes",votes)
console.log(totalVotes);

useEffect(() => {
if(window.ethereum){
window.ethereum.request({ method: 'eth_requestAccounts' }).then((res)=>{
Expand All @@ -91,15 +95,21 @@ export const Details = ({userAddress}) => {
const vote = async(index)=>{
try{
if(!voteValue) {alert("please enter value"); return;}
if(account===owner.toLowerCase()){

console.log("admin")
const res = await contract.adminVoteByProposalId(id,index,ethers.utils.parseEther(voteValue));
if(userAddress===owner.toLowerCase()){
console.log("admin")
const adminSign = await main(userAddress||account,id,index,ethers.utils.parseEther(voteValue));
const voucher = [adminSign.user,adminSign.proposalId,adminSign.option,adminSign.numberOfVotes,adminSign.time,adminSign.signature]
const res = await contract.redeem2(voucher);
await res.wait();
alert("voted successfully")
setVoteValue("");
}else{
console.log("user",account,owner)
const allowance = await tokenContract.allowance(account,contract.address);
if(Number(allowance)<ethers.utils.parseEther(voteValue)){
const res = await tokenContract.approve(contract.address,ethers.utils.parseEther(voteValue));
await res.wait();
}
const res = await contract.userVoteByProposalId(id,index,ethers.utils.parseEther(voteValue));
await res.wait();
alert("voted successfully")
Expand Down
35 changes: 19 additions & 16 deletions src/component/Login.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
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 [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 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;}
// 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}))
const jsonData = JSON.parse(response.data);
console.log(jsonData);
if(jsonData.StatusCode==="200"){

Cookies.set('user', JSON.stringify({user_id : jsonData.FullName, total_investment : jsonData.SelfInvestment, AmbassadorID: jsonData.AmbassadorID}))
window.location.href= "/"
}else{
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 (
Expand All @@ -42,9 +45,9 @@ const Hero = ({userAddress}) => {
</div>
<div class="p-6 flex flex-col gap-4">
<div class="relative w-full min-w-[200px] h-16">
<input type="email"
onChange={(e)=>{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=" " /><label class="flex w-full h-full select-none pointer-events-none absolute left-0 font-normal peer-placeholder-shown:text-blue-gray-500 leading-tight peer-focus:leading-tight peer-disabled:text-transparent peer-disabled:peer-placeholder-shown:text-blue-gray-500 transition-all -top-1.5 peer-placeholder-shown:text-[18px] text-[11px] peer-focus:text-[11px] before:content[' '] before:block before:box-border before:w-2.5 before:h-1.5 before:mt-[6.5px] before:mr-1 peer-placeholder-shown:before:border-transparent before:rounded-tl-md before:border-t peer-focus:before:border-t-2 before:border-l peer-focus:before:border-l-2 before:pointer-events-none before:transition-all peer-disabled:before:border-transparent after:content[' '] after:block after:flex-grow after:box-border after:w-2.5 after:h-1.5 after:mt-[6.5px] after:ml-1 peer-placeholder-shown:after:border-transparent after:rounded-tr-md after:border-t peer-focus:after:border-t-2 after:border-r peer-focus:after:border-r-2 after:pointer-events-none after:transition-all peer-disabled:after:border-transparent peer-placeholder-shown:leading-[4.1] text-blue-gray-400 peer-focus:text-blue-500 before:border-blue-gray-200 peer-focus:before:border-blue-500 after:border-blue-gray-200 peer-focus:after:border-blue-500">Email</label>
<input type="username"
onChange={(e)=>{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=" " /><label class="flex w-full h-full select-none pointer-events-none absolute left-0 font-normal peer-placeholder-shown:text-blue-gray-500 leading-tight peer-focus:leading-tight peer-disabled:text-transparent peer-disabled:peer-placeholder-shown:text-blue-gray-500 transition-all -top-1.5 peer-placeholder-shown:text-[18px] text-[11px] peer-focus:text-[11px] before:content[' '] before:block before:box-border before:w-2.5 before:h-1.5 before:mt-[6.5px] before:mr-1 peer-placeholder-shown:before:border-transparent before:rounded-tl-md before:border-t peer-focus:before:border-t-2 before:border-l peer-focus:before:border-l-2 before:pointer-events-none before:transition-all peer-disabled:before:border-transparent after:content[' '] after:block after:flex-grow after:box-border after:w-2.5 after:h-1.5 after:mt-[6.5px] after:ml-1 peer-placeholder-shown:after:border-transparent after:rounded-tr-md after:border-t peer-focus:after:border-t-2 after:border-r peer-focus:after:border-r-2 after:pointer-events-none after:transition-all peer-disabled:after:border-transparent peer-placeholder-shown:leading-[4.1] text-blue-gray-400 peer-focus:text-blue-500 before:border-blue-gray-200 peer-focus:before:border-blue-500 after:border-blue-gray-200 peer-focus:after:border-blue-500">username</label>
</div>
<div class="relative w-full min-w-[200px] h-16">
<input type="password"
Expand All @@ -69,8 +72,8 @@ const Hero = ({userAddress}) => {
<button class="middle none font-sans font-bold center uppercase transition-all disabled:opacity-50 disabled:shadow-none disabled:pointer-events-none text-xl py-3 px-6 rounded-lg bg-gradient-to-tr from-blue-600 to-blue-400 text-white shadow-md shadow-blue-500/20 hover:shadow-lg hover:shadow-blue-500/40 active:opacity-[0.85] block w-full" type="button"
onClick = {handleSubmit}
>Sign In</button>
{/* error */}
{error && <p class="text-red-500 text-xs italic">{error}</p>}

{error && <p class="text-red-500 text-s italic">{error}</p>}
<p class="antialiased font-sans text-xl font-light leading-normal text-inherit mt-6 flex justify-center">Don't have an account?
<span class="block antialiased font-sans text-xl leading-normal text-blue-500 ml-1 font-bold">Signup</span>

Expand Down
Loading