Skip to content

Commit

Permalink
Merge pull request #179 from PotLock/donations-api
Browse files Browse the repository at this point in the history
Donations Value
  • Loading branch information
Ebube111 authored Sep 18, 2024
2 parents b692848 + 8ad03ac commit 94d0b58
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/pages/Projects/components/DonationStats/DonationStats.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "alem";
import { asyncFetch, useEffect, useState } from "alem";
import DonateSDK from "@app/SDK/donate";
import yoctosToUsdWithFallback from "@app/utils/yoctosToUsdWithFallback";
import { Stats, StatsSubTitle, StatsTitle } from "./styles";
Expand All @@ -10,6 +10,33 @@ const DonationStats = () => {
const [donations, setDonations] = useState<string | null>(null);

const data = DonateSDK.getConfig();

const getDonations = () => {
asyncFetch("https://dev.potlock.io/api/v1/stats", {
method: "GET",
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
"Allow-Origin": "*",
},
})
.then((statesResponse) => {
console.log("States response:", statesResponse);
if (statesResponse.ok) {
return statesResponse.json().then((states) => {
const lastDonationAmount = states.total_payouts_usd;

setDonations(states?.total_donors_count);
setDonated(yoctosToUsdWithFallback(lastDonationAmount, true));
});
}
// throw new Error("Failed to fetch states");
})
.catch((error) => {
console.error("Error fetching states:", error);
});
};

useEffect(() => {
if (!donated) {
const lastDonationAmount = data.net_donations_amount
Expand All @@ -20,6 +47,7 @@ const DonationStats = () => {
setDonated(lastDonationAmount);
setDonations(totalDonations);
}
getDonations();
}, [data, donated]);

// const { donated, donations } = useDonationsInfo();
Expand Down

0 comments on commit 94d0b58

Please sign in to comment.