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/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/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 042b3b1..2b6d4ba 100644 --- a/src/component/Card.js +++ b/src/component/Card.js @@ -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) @@ -29,9 +34,11 @@ const Card = ({userAddress}) => { proposals.push(element) }); setproposal(proposals); + setLoader(false); }catch(error){ console.log(error) alert(error) + setLoader(false); } } @@ -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(); @@ -63,10 +76,16 @@ const Card = ({userAddress}) => { data() },[account]) console.log("proposals is",proposal) - return ( + return ( <>
- A) Yes (10%) -
-- {checkActive(item[1],item[2])?"Active":"Not Active"} + {checkActive(item[1],item[2])}
{error}
} + + {error &&{error}
}Don't have an account? Signup diff --git a/src/connectContract.js b/src/connectContract.js index ac735a6..9c67c4b 100644 --- a/src/connectContract.js +++ b/src/connectContract.js @@ -4,421 +4,565 @@ let signer; let tokenContract; const connectContract = () => { try { - const Address = "0x9C820370857E403aD50a687c6FDbAC4e2a763C97"; + const Address = "0xB48dbC24F8D883A5890f97d2054a5b0c4E49C735"; const Abi = [ { - inputs: [ + "inputs": [ { - internalType: "string", - name: "_topic", - type: "string", + "internalType": "string", + "name": "_topic", + "type": "string" }, { - internalType: "uint256", - name: "_startTime", - type: "uint256", + "internalType": "uint256", + "name": "_startTime", + "type": "uint256" }, { - internalType: "uint256", - name: "_endTime", - type: "uint256", + "internalType": "uint256", + "name": "_endTime", + "type": "uint256" }, { - internalType: "string", - name: "_question", - type: "string", + "internalType": "string", + "name": "_question", + "type": "string" }, { - internalType: "string[]", - name: "_options", - type: "string[]", - }, + "internalType": "string[]", + "name": "_options", + "type": "string[]" + } ], - name: "addProposal", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "addProposal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "uint256", - name: "_proposalId", - type: "uint256", + "internalType": "uint256", + "name": "_proposalId", + "type": "uint256" }, { - internalType: "uint256", - name: "_option", - type: "uint256", + "internalType": "uint256", + "name": "_option", + "type": "uint256" }, { - internalType: "uint256", - name: "_numberOfVotes", - type: "uint256", - }, + "internalType": "uint256", + "name": "_numberOfVotes", + "type": "uint256" + } ], - name: "adminVoteByProposalId", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "adminVoteByProposalId", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "uint256", - name: "_proposalId", - type: "uint256", + "internalType": "uint256", + "name": "_proposalId", + "type": "uint256" }, { - internalType: "string", - name: "_topic", - type: "string", + "internalType": "string", + "name": "_topic", + "type": "string" }, { - internalType: "uint256", - name: "_startTime", - type: "uint256", + "internalType": "uint256", + "name": "_startTime", + "type": "uint256" }, { - internalType: "uint256", - name: "_endTime", - type: "uint256", + "internalType": "uint256", + "name": "_endTime", + "type": "uint256" }, { - internalType: "string", - name: "_question", - type: "string", + "internalType": "string", + "name": "_question", + "type": "string" }, { - internalType: "string[]", - name: "_options", - type: "string[]", - }, + "internalType": "string[]", + "name": "_options", + "type": "string[]" + } ], - name: "editProposalById", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "editProposalById", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [], - name: "renounceOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "time", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "internalType": "struct DAO.VoteVoucher", + "name": "voucher", + "type": "tuple" + } + ], + "name": "redeem", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "address", - name: "_tokenContract", - type: "address", - }, + "internalType": "address", + "name": "_tokenContract", + "type": "address" + } ], - stateMutability: "nonpayable", - type: "constructor", + "name": "setTokenContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - anonymous: false, - inputs: [ + "inputs": [ { - indexed: true, - internalType: "address", - name: "previousOwner", - type: "address", - }, + "internalType": "address", + "name": "_tokenContract", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ { - indexed: true, - internalType: "address", - name: "newOwner", - type: "address", + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } ], - name: "OwnershipTransferred", - type: "event", + "name": "OwnershipTransferred", + "type": "event" }, { - inputs: [ + "inputs": [ { - components: [ + "components": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, { - internalType: "address", - name: "user", - type: "address", + "internalType": "uint256", + "name": "proposalId", + "type": "uint256" }, { - internalType: "uint256", - name: "amount", - type: "uint256", + "internalType": "uint256", + "name": "option", + "type": "uint256" }, { - internalType: "uint256", - name: "time", - type: "uint256", + "internalType": "uint256", + "name": "numberOfVotes", + "type": "uint256" }, { - internalType: "bytes", - name: "signature", - type: "bytes", + "internalType": "uint256", + "name": "time", + "type": "uint256" }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } ], - internalType: "struct DAO.VoteVoucher", - name: "voucher", - type: "tuple", - }, + "internalType": "struct DAO.VoteVoucher2", + "name": "voucher", + "type": "tuple" + } ], - name: "redeem", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "redeem2", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [ + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ { - internalType: "address", - name: "newOwner", - type: "address", - }, + "internalType": "address", + "name": "newOwner", + "type": "address" + } ], - name: "transferOwnership", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "uint256", - name: "_proposalId", - type: "uint256", + "internalType": "uint256", + "name": "_proposalId", + "type": "uint256" }, { - internalType: "uint256", - name: "_option", - type: "uint256", + "internalType": "uint256", + "name": "_option", + "type": "uint256" }, { - internalType: "uint256", - name: "_numberOfVotes", - type: "uint256", + "internalType": "uint256", + "name": "_numberOfVotes", + "type": "uint256" + } + ], + "name": "userVoteByProposalId", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } ], - name: "userVoteByProposalId", - outputs: [], - stateMutability: "nonpayable", - type: "function", + "name": "withdrawERC20", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - inputs: [], - name: "getAllProposals", - outputs: [ + "inputs": [ { - components: [ + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "withdrawETH", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + }, + { + "inputs": [], + "name": "getAllProposals", + "outputs": [ + { + "components": [ { - internalType: "string", - name: "topic", - type: "string", + "internalType": "string", + "name": "topic", + "type": "string" }, { - internalType: "uint256", - name: "startTime", - type: "uint256", + "internalType": "uint256", + "name": "startTime", + "type": "uint256" }, { - internalType: "uint256", - name: "endTime", - type: "uint256", + "internalType": "uint256", + "name": "endTime", + "type": "uint256" }, { - internalType: "string", - name: "question", - type: "string", + "internalType": "string", + "name": "question", + "type": "string" }, { - internalType: "string[]", - name: "options", - type: "string[]", + "internalType": "string[]", + "name": "options", + "type": "string[]" }, { - internalType: "uint256[]", - name: "votes", - type: "uint256[]", + "internalType": "uint256[]", + "name": "votes", + "type": "uint256[]" }, { - internalType: "uint256[]", - name: "adminVotes", - type: "uint256[]", - }, + "internalType": "uint256[]", + "name": "adminVotes", + "type": "uint256[]" + } ], - internalType: "struct DAO.Proposal[]", - name: "", - type: "tuple[]", - }, + "internalType": "struct DAO.Proposal[]", + "name": "", + "type": "tuple[]" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "uint256", - name: "_proposalId", - type: "uint256", - }, + "internalType": "uint256", + "name": "_proposalId", + "type": "uint256" + } ], - name: "getProposalById", - outputs: [ + "name": "getProposalById", + "outputs": [ { - internalType: "string", - name: "", - type: "string", + "internalType": "string", + "name": "", + "type": "string" }, { - internalType: "uint256", - name: "", - type: "uint256", + "internalType": "uint256", + "name": "", + "type": "uint256" }, { - internalType: "uint256", - name: "", - type: "uint256", + "internalType": "uint256", + "name": "", + "type": "uint256" }, { - internalType: "string", - name: "", - type: "string", + "internalType": "string", + "name": "", + "type": "string" }, { - internalType: "string[]", - name: "", - type: "string[]", + "internalType": "string[]", + "name": "", + "type": "string[]" }, { - internalType: "uint256[]", - name: "votes", - type: "uint256[]", + "internalType": "uint256[]", + "name": "votes", + "type": "uint256[]" }, { - internalType: "uint256[]", - name: "adminVotes", - type: "uint256[]", - }, + "internalType": "uint256[]", + "name": "adminVotes", + "type": "uint256[]" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [ + "inputs": [ { - internalType: "bytes", - name: "", - type: "bytes", - }, + "internalType": "bytes", + "name": "", + "type": "bytes" + } ], - name: "isSignUsed", - outputs: [ + "name": "isSignUsed", + "outputs": [ { - internalType: "bool", - name: "", - type: "bool", - }, + "internalType": "bool", + "name": "", + "type": "bool" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [], - name: "owner", - outputs: [ + "inputs": [], + "name": "owner", + "outputs": [ { - internalType: "address", - name: "", - type: "address", - }, + "internalType": "address", + "name": "", + "type": "address" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [], - name: "proposalCount", - outputs: [ + "inputs": [], + "name": "proposalCount", + "outputs": [ { - internalType: "uint256", - name: "", - type: "uint256", - }, + "internalType": "uint256", + "name": "", + "type": "uint256" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [ + "inputs": [ { - components: [ + "components": [ { - internalType: "address", - name: "user", - type: "address", + "internalType": "address", + "name": "user", + "type": "address" }, { - internalType: "uint256", - name: "amount", - type: "uint256", + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { - internalType: "uint256", - name: "time", - type: "uint256", + "internalType": "uint256", + "name": "time", + "type": "uint256" }, { - internalType: "bytes", - name: "signature", - type: "bytes", - }, + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } ], - internalType: "struct DAO.VoteVoucher", - name: "voucher", - type: "tuple", - }, + "internalType": "struct DAO.VoteVoucher", + "name": "voucher", + "type": "tuple" + } ], - name: "recover", - outputs: [ + "name": "recover", + "outputs": [ { - internalType: "address", - name: "", - type: "address", - }, + "internalType": "address", + "name": "", + "type": "address" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, { - inputs: [], - name: "remainingTokens", - outputs: [ + "inputs": [ { - internalType: "uint256", - name: "", - type: "uint256", - }, + "components": [ + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "proposalId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "option", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "numberOfVotes", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "time", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "internalType": "struct DAO.VoteVoucher2", + "name": "voucher", + "type": "tuple" + } ], - stateMutability: "view", - type: "function", + "name": "recover2", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" }, { - inputs: [], - name: "tokenContract", - outputs: [ + "inputs": [], + "name": "remainingTokens", + "outputs": [ { - internalType: "address", - name: "", - type: "address", - }, + "internalType": "uint256", + "name": "", + "type": "uint256" + } ], - stateMutability: "view", - type: "function", + "stateMutability": "view", + "type": "function" }, + { + "inputs": [], + "name": "tokenContract", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } ]; const token = "0x4fb73B501f8884721cc91aaFD5E9FA48676fa91f"; const tokenABI = [ @@ -616,7 +760,7 @@ const connectContract = () => { }, ]; const provider = new ethers.providers.Web3Provider(window.ethereum); - signer = provider.getSigner(); + signer = provider.getSigner("0xc6265eBCD55510aAeF33c7fD00e1615AFA12e745"); console.log("signer at contract: ", signer); contract = new ethers.Contract(Address, Abi, signer); tokenContract = new ethers.Contract(token, tokenABI, signer);