Skip to content

Commit

Permalink
fix: direct allocation stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Sep 17, 2024
1 parent 446d95e commit 3e239a3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/builder/src/components/grants/stats/StatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function StatCard({
>
<Box mb={2}>
<div className="table-row">
<div className="text-[14px] text-gitcoin-grey-500 font-semibold table-cell">
<div className="text-[12px] text-gitcoin-grey-500 font-semibold table-cell">
{heading}{" "}
</div>

Expand Down
10 changes: 6 additions & 4 deletions packages/builder/src/components/grants/stats/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Spinner } from "@chakra-ui/react";
import { BaseDonorValues, useDataLayer } from "data-layer";
import { DirectDonationValues, useDataLayer } from "data-layer";
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -60,15 +60,17 @@ export default function RoundStats() {
let totalDirectDonationCount = 0;

try {
const directDonations: BaseDonorValues[] =
const directDonations: DirectDonationValues[] =
await dataLayer.getDirectDonationsByProjectId({
projectId: props.projectID,
chainIds: allChains.map((chain) => chain.id),
});

console.log("directDonations", directDonations);
totalDirectDonationCount = directDonations.length;

directDonations.forEach((donation) => {
totalDirectDonations += donation.totalAmountDonatedInUsd;
totalDirectDonationCount += donation.totalDonationsCount;
totalDirectDonations += donation.amountInUsd;
});
} catch (e) {
console.error("Error fetching direct donations", e);
Expand Down
15 changes: 10 additions & 5 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
RoundApplicationPayout,
ProjectApplicationWithRoundAndProgram,
BaseDonorValues,
DirectDonationValues,
} from "./data.types";
import {
ApplicationSummary,
Expand Down Expand Up @@ -976,12 +977,16 @@ export class DataLayer {
}: {
projectId: string;
chainIds: number[];
}): Promise<BaseDonorValues[]> {
const response: { rounds: BaseDonorValues[] } = await request(
}): Promise<DirectDonationValues[]> {
const response: { rounds: { donations: DirectDonationValues[] }[] } = await request(
this.gsIndexerEndpoint,
getDirectDonationsByProjectId,
{ projectId, chainIds },
{ projectId, chainIds }
);
return response.rounds;
}

// Flatten the donations from all rounds into a single array
const allDonations = response.rounds.flatMap(round => round.donations);

return allDonations;
}
}
6 changes: 6 additions & 0 deletions packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ export type BaseDonorValues = {
uniqueDonorsCount: number;
};

export type DirectDonationValues = {
amount: number;
donorAddress: string;
amountInUsd: number;
};

/**
* The project application type for v2
*
Expand Down
7 changes: 3 additions & 4 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,10 @@ export const getDirectDonationsByProjectId = gql`
) {
donations(filter: { projectId: { equalTo: $projectId } }) {
id
amount
donorAddress
amountInUsd
}
id
uniqueDonorsCount
totalAmountDonatedInUsd
totalDonationsCount
}
}
`;

0 comments on commit 3e239a3

Please sign in to comment.