Skip to content

Commit

Permalink
updated ui/ux
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayushshah196 committed Jul 7, 2022
1 parent 95cc5ce commit 5da8112
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 205 deletions.
5 changes: 2 additions & 3 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Routes, Route } from 'react-router-dom';

import Admin from './screens/Admin';
import Vote from './screens/Vote';
import Home from './screens/Home';
import Navbar from './components/Navbar';
import Login from './screens/Login';

Expand All @@ -18,8 +18,7 @@ function App() {
<div>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/vote" element={<Vote />} />
<Route path="/home" element={<Admin />} />
<Route path="/home" element={<Home />} />
</Routes>
</div>

Expand Down
316 changes: 158 additions & 158 deletions client/src/contracts/Election.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions client/src/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@
"sourceMap": "66:352:0:-:0;;;113:10;90:33;;;;;;;;;;;;;;;;;;;;66:352;;;;;;;;;;;;;;;;",
"deployedSourceMap": "66:352:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;127:36;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;90:33;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;313:103;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;127:36;;;;:::o;90:33::-;;;;;;;;;;;;:::o;313:103::-;225:5;;;;;;;;;;211:19;;:10;:19;;;196:101;;;;;;;;;;;;:::i;:::-;;;;;;;;;402:9:::1;375:24;:36;;;;313:103:::0;:::o;7:77:2:-;44:7;73:5;62:16;;7:77;;;:::o;90:118::-;177:24;195:5;177:24;:::i;:::-;172:3;165:37;90:118;;:::o;214:222::-;307:4;345:2;334:9;330:18;322:26;;358:71;426:1;415:9;411:17;402:6;358:71;:::i;:::-;214:222;;;;:::o;442:126::-;479:7;519:42;512:5;508:54;497:65;;442:126;;;:::o;574:96::-;611:7;640:24;658:5;640:24;:::i;:::-;629:35;;574:96;;;:::o;676:118::-;763:24;781:5;763:24;:::i;:::-;758:3;751:37;676:118;;:::o;800:222::-;893:4;931:2;920:9;916:18;908:26;;944:71;1012:1;1001:9;997:17;988:6;944:71;:::i;:::-;800:222;;;;:::o;1109:117::-;1218:1;1215;1208:12;1355:122;1428:24;1446:5;1428:24;:::i;:::-;1421:5;1418:35;1408:63;;1467:1;1464;1457:12;1408:63;1355:122;:::o;1483:139::-;1529:5;1567:6;1554:20;1545:29;;1583:33;1610:5;1583:33;:::i;:::-;1483:139;;;;:::o;1628:329::-;1687:6;1736:2;1724:9;1715:7;1711:23;1707:32;1704:119;;;1742:79;;:::i;:::-;1704:119;1862:1;1887:53;1932:7;1923:6;1912:9;1908:22;1887:53;:::i;:::-;1877:63;;1833:117;1628:329;;;;:::o;1963:169::-;2047:11;2081:6;2076:3;2069:19;2121:4;2116:3;2112:14;2097:29;;1963:169;;;;:::o;2138:238::-;2278:34;2274:1;2266:6;2262:14;2255:58;2347:21;2342:2;2334:6;2330:15;2323:46;2138:238;:::o;2382:366::-;2524:3;2545:67;2609:2;2604:3;2545:67;:::i;:::-;2538:74;;2621:93;2710:3;2621:93;:::i;:::-;2739:2;2734:3;2730:12;2723:19;;2382:366;;;:::o;2754:419::-;2920:4;2958:2;2947:9;2943:18;2935:26;;3007:9;3001:4;2997:20;2993:1;2982:9;2978:17;2971:47;3035:131;3161:4;3035:131;:::i;:::-;3027:139;;2754:419;;;:::o",
"source": "// SPDX-License-Identifier: MIT\npragma solidity >=0.4.22 <0.9.0;\n\ncontract Migrations {\n address public owner = msg.sender;\n uint public last_completed_migration;\n\n modifier restricted() {\n require(\n msg.sender == owner,\n \"This function is restricted to the contract's owner\"\n );\n _;\n }\n\n function setCompleted(uint completed) public restricted {\n last_completed_migration = completed;\n }\n}\n",
"sourcePath": "C:\\dev\\voting-dapp\\contracts\\Migrations.sol",
"sourcePath": "/media/aayush/5CBEC50ABEC4DE20/voting-dapp/contracts/Migrations.sol",
"ast": {
"absolutePath": "project:/contracts/Migrations.sol",
"exportedSymbols": {
Expand Down Expand Up @@ -1914,12 +1914,12 @@
"5777": {
"events": {},
"links": {},
"address": "0xd1B6C08Cc15A8b56B1894dFD3BBD1ef48884C780",
"transactionHash": "0x010c6b72f67f6af1e19ca96a32c3b11e760ca627c39366067533331e2db4a3d0"
"address": "0xd7fCfF35f7DB8a4b43701bb76F8e6a06002B2fCB",
"transactionHash": "0xaea0f632af9d58d32617918b64ff126d6541f98be3e6dfc668a24581fc67d03c"
}
},
"schemaVersion": "3.4.7",
"updatedAt": "2022-07-01T17:29:48.665Z",
"schemaVersion": "3.4.8",
"updatedAt": "2022-07-07T07:24:07.914Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",
Expand Down
4 changes: 3 additions & 1 deletion client/src/screens/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default function Admin({role, contract, web3, currentAccount}) {
}
setCandidates(temp);
setLoading(false);
console.log(temp)
}
};

Expand Down Expand Up @@ -104,9 +105,10 @@ export default function Admin({role, contract, web3, currentAccount}) {
</Grid>

<Grid item xs={12}>
{candidates.map((candidate, index) => (
{candidates && candidates.map((candidate, index) => (
<Candidate id={index} name={candidate.name} voteCount={candidate.votes} />
))}

</Grid>

</Grid>
Expand Down
9 changes: 5 additions & 4 deletions client/src/screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getWeb3 from "../utils/getWeb3";


export default function Home() {
const [role, setRole] = useState(1);
const [role, setRole] = useState(2);
const [web3, setWeb3] = useState(null);
const [currentAccount, setCurrentAccount] = useState(null);
const [contract, setContract] = useState(null);
Expand All @@ -34,7 +34,8 @@ export default function Home() {

const getRole = async () => {
if (contract) {
const role = await contract.methods.getRole().call();
// const role = await contract.methods.getRole().call();
const role = 2;
setRole(role);
setLoading(false);
}
Expand All @@ -54,13 +55,13 @@ export default function Home() {
<h1>Loading the page !!!</h1>
) : (
<Box>
{ role && role===1 && <Vote role={role}
{ role===1 && <Vote role={role}
contract={contract}
web3={web3}
currentAccount={currentAccount}/>
}

{ role && role===2 && <Admin role={role}
{ role===2 && <Admin role={role}
contract={contract}
web3={web3}
currentAccount={currentAccount}/>
Expand Down
38 changes: 4 additions & 34 deletions client/src/screens/Vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,17 @@ export default function Vote({role, contract, web3, currentAccount}) {
setVote(event.target.value);
};

const handleEnd = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

const handleAgree = () => {
console.log("Voting Done!!!");
const handleVote = () => {
voteCandidate(vote);
}
};

return (
<Box>
{ loading ? (
<h1>Loading the page !!!</h1>
) : (
<Box>
<form onSubmit={handleEnd}>
<form onSubmit={handleVote}>
<Grid container>

<Grid item xs={12}>
Expand All @@ -133,6 +124,7 @@ export default function Vote({role, contract, web3, currentAccount}) {
<div style={{display:"flex"}}>
{candidates.map((candidate, index) => (
<FormControlLabel
key={index}
labelPlacement="top"
control={<Radio />}
value={index}
Expand All @@ -159,28 +151,6 @@ export default function Vote({role, contract, web3, currentAccount}) {
</Grid>

</form>

<Dialog
open={open}
onClose={handleClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">
{"Use Google's location service?"}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
Do you want to submit your vote?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Disagree</Button>
<Button onClick={handleAgree} autoFocus>
Agree
</Button>
</DialogActions>
</Dialog>
</Box>
)}

Expand Down
17 changes: 17 additions & 0 deletions contracts/Voting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ contract Election {
uint256 voteCount;
}

address private owner;

struct Voter {
uint256 id;
string name;
}

mapping(uint256 => Candidate) candidates;
mapping(address => bool) voted;

mapping(address => bool) isVoter;

uint256 public candidatesCount = 0;

uint256 public votersCount = 0;

constructor() {
addCandidate("Candidate 1");
addCandidate("Candidate 2");
Expand All @@ -25,7 +36,13 @@ contract Election {
candidatesCount++;
}

function addVoter(address _voter) public {
require(owner==msg.sender, "Only owner can add voter");
isVoter[_voter] = true;
}

function vote(uint256 _candidateId) public {
require(isVoter[msg.sender], "Non authorised user cannot vote");
require(!voted[msg.sender], "You have already voted");
require(
_candidateId >= 0 && _candidateId < candidatesCount,
Expand Down

0 comments on commit 5da8112

Please sign in to comment.