From 20b528e8577798df3c3c33bec8f27a43f6e7595a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez?= Date: Thu, 14 Mar 2024 17:22:10 +0000 Subject: [PATCH 1/2] Dynamically compute Jessys grant amount --- .../nextjs/app/_components/EcosystemGrants.tsx | 7 ++++--- packages/nextjs/app/_components/GrantsStats.tsx | 4 ++-- .../services/database/ecosystemGrants.json | 2 +- packages/nextjs/services/database/grants.ts | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/nextjs/app/_components/EcosystemGrants.tsx b/packages/nextjs/app/_components/EcosystemGrants.tsx index 0a1d741..412757e 100644 --- a/packages/nextjs/app/_components/EcosystemGrants.tsx +++ b/packages/nextjs/app/_components/EcosystemGrants.tsx @@ -1,5 +1,5 @@ import Image from "next/image"; -import ecosystemGrants from "~~/services/database/ecosystemGrants.json"; +import { getAllEcosystemGrants } from "~~/services/database/grants"; const EcosystemGrantsCard = ({ title, @@ -28,7 +28,7 @@ const EcosystemGrantsCard = ({
Amount: - {amountGranted} ETH + {Number(amountGranted).toFixed(2)} ETH
Twitter @@ -39,7 +39,8 @@ const EcosystemGrantsCard = ({ ); }; -export const EcosystemGrants = () => { +export const EcosystemGrants = async () => { + const ecosystemGrants = await getAllEcosystemGrants(); return (
diff --git a/packages/nextjs/app/_components/GrantsStats.tsx b/packages/nextjs/app/_components/GrantsStats.tsx index 86eb251..1d10971 100644 --- a/packages/nextjs/app/_components/GrantsStats.tsx +++ b/packages/nextjs/app/_components/GrantsStats.tsx @@ -1,6 +1,5 @@ import Image from "next/image"; -import ecosystemGrants from "~~/services/database/ecosystemGrants.json"; -import { getGrantsStats } from "~~/services/database/grants"; +import { getAllEcosystemGrants, getGrantsStats } from "~~/services/database/grants"; const Stat = ({ label, imgLink, value }: { label: string; imgLink: string; value: string | number }) => { return ( @@ -16,6 +15,7 @@ const Stat = ({ label, imgLink, value }: { label: string; imgLink: string; value export const GrantsStats = async () => { const stats = await getGrantsStats(); + const ecosystemGrants = await getAllEcosystemGrants(); const sum = ecosystemGrants.grants.reduce( (acc, grant) => acc + parseFloat(grant.amountGranted), diff --git a/packages/nextjs/services/database/ecosystemGrants.json b/packages/nextjs/services/database/ecosystemGrants.json index 55879ed..877ac80 100644 --- a/packages/nextjs/services/database/ecosystemGrants.json +++ b/packages/nextjs/services/database/ecosystemGrants.json @@ -3,7 +3,7 @@ { "name": "Jessy's Hacker House", "description": "Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.Lorem ipsum dolor sit amet, qui minim labore adipisicing.", - "amountGranted": "14", + "amountGranted": "tbc", "twitterLink": "https://twitter.com/wehack247", "imgLink": "/assets/jessy-hacker-house.png" }, diff --git a/packages/nextjs/services/database/grants.ts b/packages/nextjs/services/database/grants.ts index 4610efb..c21d619 100644 --- a/packages/nextjs/services/database/grants.ts +++ b/packages/nextjs/services/database/grants.ts @@ -1,5 +1,6 @@ import { getFirestoreConnector } from "./firestoreDB"; import { BuilderData, GrantData, GrantDataWithBuilder } from "./schema"; +import ecosystemGrants from "~~/services/database/ecosystemGrants.json"; import { findUserByAddress } from "~~/services/database/users"; import { PROPOSAL_STATUS, ProposalStatusType } from "~~/utils/grants"; @@ -109,6 +110,21 @@ export const getAllActiveGrants = async () => { } }; +// Get all the data from ecosystemGrants.json and update the amountGranted for Jessy's grant +export const getAllEcosystemGrants = async () => { + const withdrawEventsSnapshot = await firestoreDB.collection("events").where("type", "==", "cohort.withdraw").get(); + const totalEthWithdrawnForJessy = withdrawEventsSnapshot.docs.reduce((acc, event) => { + const payload = event.data().payload; + if (payload.cohortName.includes("Jessy")) { + return acc + Number(payload.amount); + } + return acc; + }, 0); + + ecosystemGrants.grants[0].amountGranted = totalEthWithdrawnForJessy.toString(); + return ecosystemGrants; +}; + type ReviewGrantParams = { grantId: string; action: ProposalStatusType; From 3e08443a02b3beb01e75e5fe0053f2756e258d72 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 14 Mar 2024 17:26:11 +0000 Subject: [PATCH 2/2] change default amountGranted for jessy => 0 --- packages/nextjs/services/database/ecosystemGrants.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/services/database/ecosystemGrants.json b/packages/nextjs/services/database/ecosystemGrants.json index 877ac80..6d4ffa0 100644 --- a/packages/nextjs/services/database/ecosystemGrants.json +++ b/packages/nextjs/services/database/ecosystemGrants.json @@ -3,7 +3,7 @@ { "name": "Jessy's Hacker House", "description": "Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.Lorem ipsum dolor sit amet, qui minim labore adipisicing.", - "amountGranted": "tbc", + "amountGranted": "0", "twitterLink": "https://twitter.com/wehack247", "imgLink": "/assets/jessy-hacker-house.png" },