Skip to content

Commit

Permalink
Dynamically compute Jessys grant amount (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex authored Mar 14, 2024
1 parent ceb3fe7 commit d6c5b97
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/nextjs/app/_components/EcosystemGrants.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -28,7 +28,7 @@ const EcosystemGrantsCard = ({
<div className="flex justify-between items-baseline w-full">
<div className="bg-primary rounded-lg py-1 px-2 text-xs font-bold">
Amount:
<span className="text-sm"> {amountGranted} ETH</span>
<span className="text-sm"> {Number(amountGranted).toFixed(2)} ETH</span>
</div>
<a href={twitterLink} target="_blank" className="text-sm underline underline-offset-1">
Twitter
Expand All @@ -39,7 +39,8 @@ const EcosystemGrantsCard = ({
);
};

export const EcosystemGrants = () => {
export const EcosystemGrants = async () => {
const ecosystemGrants = await getAllEcosystemGrants();
return (
<div>
<div className="container flex flex-col justify-center max-w-[90%] lg:max-w-7xl mx-auto py-12 lg:pt-20 lg:pb-28 lg:px-4 gap-6">
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/app/_components/GrantsStats.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/services/database/ecosystemGrants.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
16 changes: 16 additions & 0 deletions packages/nextjs/services/database/grants.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d6c5b97

Please sign in to comment.