From b437459a20c8479ab65dd449a2296814797d1583 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Wed, 13 Mar 2024 17:56:29 -0500 Subject: [PATCH] UI for work requests --- client/src/App.jsx | 125 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 98 insertions(+), 27 deletions(-) diff --git a/client/src/App.jsx b/client/src/App.jsx index 0a47676..044edc7 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -34,6 +34,7 @@ function App() { const [validationPools, setValidationPools] = useState([]); const stakedPools = useRef([]); const [availabilityStakes, setAvailabilityStakes] = useState([]); + const [workRequests, setWorkRequests] = useState([]); // const watchReputationToken = useCallback(async () => { // await provider.request({ @@ -47,7 +48,7 @@ function App() { // }); // }, [provider]); - const getStatus = (pool) => { + const getPoolStatus = (pool) => { if (pool.resolved) { return pool.outcome ? 'Accepted' : 'Rejected'; } @@ -55,6 +56,21 @@ function App() { return new Date() < endDate ? 'In Progress' : 'Ready to Evaluate'; }; + const getRequestStatus = (request) => { + switch (Number(request.status)) { + case 0: + return 'Requested'; + case 1: + return 'Evidence Submitted'; + case 2: + return 'Approval Submitted'; + case 3: + return 'Complete'; + default: + return 'Unknown'; + } + }; + // In this effect, we initialize everything and add contract event listeners. // TODO: Refactor -- make separate, functional components? useEffect(() => { @@ -66,7 +82,6 @@ function App() { const fetchPrice = async () => { const fetchedPrice = await work1Contract.methods.price().call(); - console.log('fetchedPrice', fetchedPrice); setWork1Price(web3.utils.fromWei(fetchedPrice, 'ether')); }; @@ -111,7 +126,7 @@ function App() { } const pools = (await Promise.all(promises)).map((p) => { const pool = p; - pool.status = getStatus(pool); + pool.status = getPoolStatus(pool); const timeRemaining = new Date(Number(pool.endTime) * 1000) - new Date(); if (timeRemaining > 0 && !pool.resolved && reputation.current && !stakedPools.current.includes(pool.id)) { @@ -155,11 +170,29 @@ function App() { setAvailabilityStakes(fetchedStakes); }; + const fetchWorkRequests = async () => { + const count = await work1Contract.methods.requestCount().call(); + const promises = []; + for (let i = 0; i < count; i += 1) { + promises.push(work1Contract.methods.requests(i).call()); + } + const fetchedRequests = (await Promise.all(promises)).map((x, index) => { + Object.assign(x, { + id: index, + statusString: getRequestStatus(x), + feeEther: web3.utils.fromWei(x.fee, 'ether'), + }); + return x; + }); + setWorkRequests(fetchedRequests); + }; + fetchPrice(); fetchReputation(); fetchPosts(); fetchValidationPools(); fetchAvailabilityStakes(); + fetchWorkRequests(); setWork1(work1Contract); setDAO(DAOContract); @@ -375,34 +408,72 @@ function App() { {' '} {availabilityStakes.length} - - - - - - - - - - - - - {availabilityStakes.map((stake) => ( - - - - - - - +
+
IDWorkerAmountEnd TimeAssignedReclaimed
{stake.id.toString()}{stake.worker.toString()}{stake.amount.toString()}{new Date(Number(stake.endTime) * 1000).toLocaleString()}{stake.assigned.toString()}{stake.reclaimed.toString()}
+ + + + + + + + - ))} - -
IDWorkerAmountEnd TimeAssignedReclaimed
- + + + {availabilityStakes.map((stake) => ( + + {stake.id.toString()} + {stake.worker.toString()} + {stake.amount.toString()} + {new Date(Number(stake.endTime) * 1000).toLocaleString()} + {stake.assigned.toString()} + {stake.reclaimed.toString()} + + ))} + + +
+
+ Work Request Count: + {' '} + {workRequests.length} +
+
+ + + + + + + + + + + + + + {workRequests.map((request) => ( + + + + + + + + + + ))} + +
IDCustomerFeeStatusStake IDApprovalPool ID
{request.id.toString()}{request.customer.toString()} + {request.feeEther} + {' '} + ETH + {request.statusString}{request.stakeIndex.toString()}{request.approval.toString()}{request.poolIndex.toString()}
+
)}