From fd041e02282cbd2d8616d30e77e535a7cb8ba034 Mon Sep 17 00:00:00 2001 From: nicolasito1411 <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Sun, 15 Oct 2023 13:14:01 +0200 Subject: [PATCH 1/4] feat: number of steps and participants --- components/quests/questDetails.tsx | 56 ++++++++++++++++++++++++++++++ styles/quests.module.css | 22 ++++++++++++ 2 files changed, 78 insertions(+) diff --git a/components/quests/questDetails.tsx b/components/quests/questDetails.tsx index 7761f436..09863dc6 100644 --- a/components/quests/questDetails.tsx +++ b/components/quests/questDetails.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState, FunctionComponent, + useContext, } from "react"; import styles from "../../styles/quests.module.css"; import Task from "./task"; @@ -23,6 +24,7 @@ import { generateCodeChallenge } from "../../utils/codeChallenge"; import Timer from "./timer"; import NftImage from "./nftImage"; import { splitByNftContract } from "../../utils/rewards"; +import { StarknetIdJsContext } from "../../context/StarknetIdJsProvider"; type QuestDetailsProps = { quest: QuestDocument; @@ -45,6 +47,7 @@ const QuestDetails: FunctionComponent = ({ const { provider } = useProvider(); const [tasks, setTasks] = useState([]); const [rewardsEnabled, setRewardsEnabled] = useState(false); + const { starknetIdNavigator } = useContext(StarknetIdJsContext); const [eligibleRewards, setEligibleRewards] = useState< Record >({}); @@ -54,7 +57,44 @@ const QuestDetails: FunctionComponent = ({ const [mintCalldata, setMintCalldata] = useState(); const [taskError, setTaskError] = useState(); const [showQuiz, setShowQuiz] = useState(); + const questId = quest.id.toString(); + const [participants, setParticipants] = useState({ + count: 0, + firstParticipants: [] as string[], + }); + + // This fetches the number of participants in the quest and up to 3 of their starknet ids + useEffect(() => { + if (questId && starknetIdNavigator) { + fetch( + `http://127.0.0.1:8080/get_quest_participants?quest_id=${questId}`, + { + method: "GET", + } + ) + .then((response) => response.json()) + .then(async (data) => { + setParticipants(data); + const addrs = data.firstParticipants; + const identities = addrs.map(async (addr: string) => { + const domain = await starknetIdNavigator + ?.getStarkName(addr) + .catch((err) => {}); + return domain + ? await starknetIdNavigator + ?.getStarknetId(domain) + .catch((err) => {}) + : 0; + }); + const identitiesResolved = await Promise.all(identities); + setParticipants({ + count: data.count, + firstParticipants: identitiesResolved, + }); + }); + } + }, [questId, starknetIdNavigator]); // this fetches all tasks of this quest from db useEffect(() => { @@ -272,6 +312,22 @@ const QuestDetails: FunctionComponent = ({ ) : ( <> +
+

{tasks.length} steps

+
+
+ {participants.firstParticipants.map((participant, index) => ( + user icons + ))} +
+

{participants.count || 0} participants

+
+
{tasks.map((task) => { return ( Date: Sun, 15 Oct 2023 13:17:07 +0200 Subject: [PATCH 2/4] fixing build errors --- components/quests/questDetails.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/quests/questDetails.tsx b/components/quests/questDetails.tsx index 09863dc6..0edf097a 100644 --- a/components/quests/questDetails.tsx +++ b/components/quests/questDetails.tsx @@ -80,11 +80,11 @@ const QuestDetails: FunctionComponent = ({ const identities = addrs.map(async (addr: string) => { const domain = await starknetIdNavigator ?.getStarkName(addr) - .catch((err) => {}); + .catch(console.error); return domain ? await starknetIdNavigator ?.getStarknetId(domain) - .catch((err) => {}) + .catch(console.error) : 0; }); const identitiesResolved = await Promise.all(identities); From cc1f26e3943b61e0e469d4ad6c4bd37c4dfd39fd Mon Sep 17 00:00:00 2001 From: nicolasito1411 <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:57:02 +0200 Subject: [PATCH 3/4] using env var for the api request --- components/quests/questDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/quests/questDetails.tsx b/components/quests/questDetails.tsx index 0edf097a..9b5ffe70 100644 --- a/components/quests/questDetails.tsx +++ b/components/quests/questDetails.tsx @@ -68,7 +68,7 @@ const QuestDetails: FunctionComponent = ({ useEffect(() => { if (questId && starknetIdNavigator) { fetch( - `http://127.0.0.1:8080/get_quest_participants?quest_id=${questId}`, + `${process.env.NEXT_PUBLIC_API_LINK}/get_quest_participants?quest_id=${questId}`, { method: "GET", } From d7e389155e823aef9a5a15d2fcd7d3cbc520cd17 Mon Sep 17 00:00:00 2001 From: nicolasito1411 <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:43:57 +0200 Subject: [PATCH 4/4] using an env var for identicons --- components/quests/questDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/quests/questDetails.tsx b/components/quests/questDetails.tsx index 9b5ffe70..01935212 100644 --- a/components/quests/questDetails.tsx +++ b/components/quests/questDetails.tsx @@ -318,7 +318,7 @@ const QuestDetails: FunctionComponent = ({
{participants.firstParticipants.map((participant, index) => (