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..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": "14", + "amountGranted": "0", "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;