Skip to content

Commit

Permalink
handle coingecko request failing
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Nov 3, 2023
1 parent f97a75f commit fdb6f10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions apps/potlock/widget/Project/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ const donationsForProject = Near.view(donationContractId, "get_donations_for_rec
});

const [totalAmount, totalDonors] = useMemo(() => {
if (!donationsForProject || !props.nearToUsd) {
return ["-", "-"];
}
if (!donationsForProject) return [null, null];
const donors = [];
let totalDonationAmount = new Big(0);
for (const donation of donationsForProject) {
Expand All @@ -112,7 +110,10 @@ const [totalAmount, totalDonors] = useMemo(() => {
}
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
}
return [(props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2), donors.length];
return [
props.nearToUsd ? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2) : "-",
donors.length,
];
}, [donationsForProject]);

return (
Expand Down Expand Up @@ -160,11 +161,11 @@ return (
</Info>
<DonationsInfoContainer>
<DonationsInfoItem>
<Title>{totalDonors}</Title>
<Title>{totalDonors || totalDonors === 0 ? totalDonors : "-"}</Title>
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount}</Title>
<Title>${totalAmount || "-"}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
Expand Down
13 changes: 7 additions & 6 deletions build/potlock/src/Project/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ const donationsForProject = Near.view(donationContractId, "get_donations_for_rec
});

const [totalAmount, totalDonors] = useMemo(() => {
if (!donationsForProject || !props.nearToUsd) {
return ["-", "-"];
}
if (!donationsForProject) return [null, null];
const donors = [];
let totalDonationAmount = new Big(0);
for (const donation of donationsForProject) {
Expand All @@ -112,7 +110,10 @@ const [totalAmount, totalDonors] = useMemo(() => {
}
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
}
return [(props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2), donors.length];
return [
props.nearToUsd ? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2) : "-",
donors.length,
];
}, [donationsForProject]);

return (
Expand Down Expand Up @@ -160,11 +161,11 @@ return (
</Info>
<DonationsInfoContainer>
<DonationsInfoItem>
<Title>{totalDonors}</Title>
<Title>{totalDonors || totalDonors === 0 ? totalDonors : "-"}</Title>
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount}</Title>
<Title>${totalAmount || "-"}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
Expand Down

0 comments on commit fdb6f10

Please sign in to comment.