Skip to content

Commit ecc9d4d

Browse files
authoredAug 18, 2023
Merge pull request #19 from FLock-io/fix/display-task-participants
Fix/display task participants
2 parents 5818e89 + e18d5c4 commit ecc9d4d

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed
 

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/renderer/components/Task.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function Task({ task, goBack }: TaskProps) {
8484
finalDataForReport,
8585
dataCurrentAccuracy,
8686
accuracies,
87+
numberOfParticipants,
8788
} = useTaskData({
8889
task,
8990
participantAddress: address,
@@ -478,11 +479,11 @@ function Task({ task, goBack }: TaskProps) {
478479
<Box direction="row" justify="between" align="center">
479480
<Box direction="row" align="center" gap="xsmall">
480481
<Text color="brand" size="2xl" weight="bold">
481-
{Number(task.numberOfParticipants)}
482+
{Number(numberOfParticipants)}
482483
</Text>
483484
<Text weight="bold">
484485
participant
485-
{Number(task.numberOfParticipants) !== 1 && 's'} have
486+
{Number(numberOfParticipants) !== 1 && 's'} have
486487
joined the task
487488
</Text>
488489
</Box>
@@ -491,7 +492,7 @@ function Task({ task, goBack }: TaskProps) {
491492
{Array.from(
492493
{
493494
length: Math.min(
494-
Number(task.numberOfParticipants),
495+
Number(numberOfParticipants),
495496
7
496497
),
497498
},
@@ -503,7 +504,7 @@ function Task({ task, goBack }: TaskProps) {
503504
{Array.from(
504505
{
505506
length:
506-
Number(task.numberOfParticipants) - (i + 1),
507+
Number(numberOfParticipants) - (i + 1),
507508
},
508509
(_, j) => (
509510
<Box key={j} pad="xsmall" />
@@ -513,8 +514,8 @@ function Task({ task, goBack }: TaskProps) {
513514
)
514515
)}
515516
</Stack>
516-
{Number(task.numberOfParticipants) > 7 && (
517-
<Text>+{Number(task.numberOfParticipants) - 7}</Text>
517+
{Number(numberOfParticipants) > 7 && (
518+
<Text>+{Number(numberOfParticipants) - 7}</Text>
518519
)}
519520
</Box>
520521
</Box>
@@ -539,7 +540,7 @@ function Task({ task, goBack }: TaskProps) {
539540
<Meter
540541
values={[
541542
{
542-
value: Number(task.numberOfParticipants),
543+
value: Number(numberOfParticipants),
543544
color: 'brand',
544545
onClick: () => {},
545546
label: `Min: ${task.minParticipants}`,

‎src/renderer/hooks/useTaskData.ts

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const useTaskData = ({
2828
{ round: number; accuracy: number }[]
2929
>([]);
3030

31+
const [numberOfParticipants, setNumberOfParticipants] = useState<bigint>();
32+
3133
const { data: dataCurrentRound } = useContractRead({
3234
address: task.address as `0x${string}`,
3335
abi: FLOCK_TASK_ABI,
@@ -126,11 +128,21 @@ export const useTaskData = ({
126128
setAccuracies(result);
127129
};
128130

131+
const loadRoundParticipants = async () => {
132+
const participantsData = readContract({
133+
address: task.address as `0x${string}`,
134+
abi: FLOCK_TASK_ABI,
135+
functionName: 'getNumberOfParticipants',
136+
}) as Promise<bigint>;
137+
setNumberOfParticipants(await participantsData);
138+
};
139+
129140
useEffect(() => {
130141
loadRoundParticipantRewardedAmount();
131142
loadRoundParticipantBalance();
132143
loadRoundParticipantRole();
133144
loadAccuracies();
145+
loadRoundParticipants();
134146
}, [dataCurrentRound]);
135147

136148
const finalDataForReport = [];
@@ -172,6 +184,7 @@ export const useTaskData = ({
172184
finalDataForReport,
173185
dataCurrentAccuracy,
174186
accuracies,
187+
numberOfParticipants,
175188
};
176189
};
177190

0 commit comments

Comments
 (0)