Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,146 @@ import Modal from 'react-bootstrap/Modal';
import Collapse from 'react-bootstrap/Collapse';
import Spinner from 'react-bootstrap/Spinner';
import styles from './CreateProcessPage.module.css';
import {ethers} from 'ethers';

//web3 imports
import { deployVotingProcess, deployTestContract, getTestContract } from '../web3/contracts'
import { useState, useEffect, useRef } from 'react';
import { ethers } from 'ethers';
import { deployVotingProcess } from '../web3/contracts';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';



const CreateProcess = () => {
const navigate = useNavigate();

const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [proposals, setProposals] = useState('');
const [pending, setPending] = useState(false);

const [show, setShow] = useState(false);
const [open, setOpen] = useState(false);
const [transactionResult, setTransactionResult] = useState(null);

const handleClose = () => {
setShow(false);
navigate('/');
}
const [open, setOpen] = useState(false);
const [transactionResult, setTransactionResult] = useState(null);
};

const isFormValid = () => {
const validProposals = proposals
.split(',')
.map(p => p.trim())
.filter(p => p.length > 0);
return validProposals.length >= 2;
};

const formatProposals = (input) => {
return input
.split(',')
.map(p => p.trim())
.filter(p => p.length > 0)
.map(p => ethers.utils.toUtf8Bytes(p));
};

const refValue = useRef(false);

const createProcess = async (e) => {
e.preventDefault();
console.log("name: ", name);
//format proposals
let proposalArray = formatProposals(proposals);
//check form inputs
if(!isFormValid()){
window.alert("Form is not valid");

if (!isFormValid()) {
window.alert("Form is not valid. Enter at least 2 proposals.");
return;
}
setPending(true);
refValue.current = true;
//deploy new process contract
const result = await deployVotingProcess(name, description, proposalArray,1000000,1000000);
setTransactionResult(result);

refValue.current = false;
setPending(false);

setShow(true);
}

const isFormValid = () => {
if(proposals < 2)
return false;
return true;
}
try {
setPending(true);

const formatProposals = (input) => {
let proposals = input.split(',');
let array = []
for(let i=0; i < proposals.length; i ++){
array.push(ethers.utils.toUtf8Bytes(proposals[i].trim()));
}
return array;
}
const _formattedProposals = formatProposals(proposals);

const startDate = Math.floor(Date.now() / 1000); // current time
const endDate = startDate + 24 * 60 * 60; // 1 day later

// Deploy with proposals
const result = await deployVotingProcess(
name,
description,
startDate,
endDate,
_formattedProposals // <-- send proposals to contract
);

useEffect(() => {
// setPending(!pending);
}, [pending])
setTransactionResult(result);
setShow(true);

return (
<div >
} catch (err) {
console.error(err);
window.alert("Transaction failed: " + (err.message || err));
} finally {
setPending(false);
}
};
Comment on lines 42 to +76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, find the contracts.js file
echo "=== Finding contracts.js file ==="
find . -name "contracts.js" -type f

echo -e "\n=== Content of contracts.js ==="
# Get the contracts file path
CONTRACT_FILE=$(find . -name "contracts.js" -type f | head -1)
if [ -n "$CONTRACT_FILE" ]; then
  wc -l "$CONTRACT_FILE"
  cat -n "$CONTRACT_FILE"
fi

Repository: AOSSIE-Org/Agora-Blockchain

Length of output: 5494


Update deployVotingProcess to accept and use proposals parameter.

The function signature on line 12 of contracts.js accepts only 4 parameters (name, description, startDate, endDate), but CreateProcessPage.js calls it with 5 arguments, passing _formattedProposals as the 5th parameter. This parameter is currently ignored. The function must be updated to accept proposals and pass them to the contract's createVotingProcess method.

🤖 Prompt for AI Agents
In anonymousVoting/clientAnonymousVoting/src/components/CreateProcessPage.js
around lines 42 to 76, CreateProcessPage passes a fifth parameter
(_formattedProposals) to deployVotingProcess but the function in contracts.js
only accepts four params and ignores proposals; update the deployVotingProcess
signature to accept a proposals parameter, include that parameter in the call to
the smart-contract method (e.g., pass proposals to contract.createVotingProcess
as the proposals argument), ensure proposals are validated/serialized in the
same format expected by the contract, propagate errors as before, and update any
other callers/tests to pass the proposals argument if necessary.


return (
<div>
<div className={styles.createProcess}>
<h1>Create new voting process</h1>
</div>

<form onSubmit={createProcess} className={styles.create}>
<div>
<label>Process name:</label>
<input
<input
type="text"
required
value = {name}
value={name}
onChange={(e) => setName(e.target.value)}
/>
</div>

<div>
<label>Process description:</label>
<input
<input
type="text"
required
value = {description}
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
</div>

<div>
<label>Proposals (separated with ","):</label>
<input
<input
type="text"
required
value = {proposals}
value={proposals}
onChange={(e) => setProposals(e.target.value)}
/>
</div>

<div>
<button className="baseButton">Create new process</button>
<button
className="baseButton"
type="submit"
disabled={pending}
>
{pending ? (
<>
<Spinner
animation="border"
size="sm"
style={{ marginRight: "8px" }}
/>
Creating...
</>
) : (
"Create new process"
)}
</button>
</div>
{refValue.current == true && <div style={{marginTop: "2em"}}>
<Spinner animation="border" />
</div>}
</form>

<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>Transaction result</Modal.Title>
</Modal.Header>

<Modal.Body>
<p>
Transaction was executed.
</p>
<p>Transaction was executed.</p>

<button
className="baseButton"
onClick={() => setOpen(!open)}
Expand All @@ -127,25 +150,34 @@ const CreateProcess = () => {
>
Transaction details
</button>
{ transactionResult && <Collapse in={open}>
<div id="example-collapse-text" className={styles.collapse}>
<div>
<h4>transaction hash: </h4>
<p>{transactionResult.hash}</p>
</div>
<div>
<h4>nonce: </h4>
<p>{transactionResult.nonce}</p>

{transactionResult && (
<Collapse in={open}>
<div
id="example-collapse-text"
className={styles.collapse}
>
<div>
<h4>Transaction hash:</h4>
<p>{transactionResult.hash}</p>
</div>
<div>
<h4>Nonce:</h4>
<p>{transactionResult.nonce}</p>
</div>
</div>
</div>
</Collapse>}
</Collapse>
)}
</Modal.Body>

<Modal.Footer>
<button className="baseButton" onClick={handleClose}>Close</button>
<button className="baseButton" onClick={handleClose}>
Close
</button>
</Modal.Footer>
</Modal>
</div>
);
}
export default CreateProcess;
};

export default CreateProcess;