-
-
Notifications
You must be signed in to change notification settings - Fork 185
fix: add loading spinner and disable create process button during tra… #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
4da995e
2b5be5d
5b636f2
770b100
6cc6394
a380055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,13 @@ 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'; | ||
| import { ethers } from 'ethers'; | ||
|
|
||
| //web3 imports | ||
| import { deployVotingProcess, deployTestContract, getTestContract } from '../web3/contracts' | ||
| import { useState, useEffect, useRef } from 'react'; | ||
| // web3 imports | ||
| import { deployVotingProcess } from '../web3/contracts'; | ||
| import { useState } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
|
|
||
|
|
||
|
|
||
| const CreateProcess = () => { | ||
| const navigate = useNavigate(); | ||
|
|
||
|
|
@@ -20,105 +18,133 @@ const CreateProcess = () => { | |
| 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()){ | ||
|
|
||
| if (!isFormValid()) { | ||
| window.alert("Form is not valid"); | ||
| 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 = 1000000; | ||
| const endDate = 1000000; | ||
|
|
||
| useEffect(() => { | ||
| // setPending(!pending); | ||
| }, [pending]) | ||
| const result = await deployVotingProcess( | ||
| name, | ||
| description, | ||
| startDate, | ||
| endDate | ||
| ); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <div > | ||
| setTransactionResult(result); | ||
| setShow(true); | ||
|
|
||
| } catch (err) { | ||
| console.error(err); | ||
| window.alert("Transaction failed"); | ||
| } finally { | ||
| setPending(false); | ||
| } | ||
| }; | ||
|
Comment on lines
42
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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"
fiRepository: AOSSIE-Org/Agora-Blockchain Length of output: 5494 Update The function signature on line 12 of 🤖 Prompt for AI Agents |
||
|
|
||
| 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)} | ||
|
|
@@ -127,25 +153,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; | ||
Uh oh!
There was an error while loading. Please reload this page.