Skip to content

Commit

Permalink
change total amount to after fees & add referral fees
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Nov 9, 2023
1 parent 96d2c57 commit df4c3c5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
2 changes: 0 additions & 2 deletions apps/potlock/widget/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ if (state.registryAdmins === null) {
State.update({ registryAdmins });
}

console.log("state: ", state);

const tabContentWidget = {
[CREATE_PROJECT_TAB]: "Project.Create",
[EDIT_PROJECT_TAB]: "Project.Create",
Expand Down
32 changes: 28 additions & 4 deletions apps/potlock/widget/Project/DonationsInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,54 @@ const donationsForProject = Near.view(donationContractId, "get_donations_for_rec
recipient_id: props.projectId,
});

const [totalDonations, totalDonors] = useMemo(() => {
const [totalDonations, totalDonors, totalReferralFees] = useMemo(() => {
if (!donationsForProject) {
return ["", ""];
}
const donors = [];
let totalDonationAmount = new Big(0);
let totalReferralFees = new Big(0);
for (const donation of donationsForProject) {
if (!donors.includes(donation.donor_id)) {
donors.push(donation.donor_id);
}
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
const totalAmount = new Big(donation.total_amount);
const referralAmount = new Big(donation.referrer_fee || "0");
const protocolAmount = new Big(donation.protocol_fee || "0");
totalDonationAmount = totalDonationAmount.plus(
totalAmount.minus(referralAmount).minus(protocolAmount)
);
totalReferralFees = totalReferralFees.plus(referralAmount);
}
return [totalDonationAmount.div(1e24).toNumber().toFixed(2), donors.length];
return [
totalDonationAmount.div(1e24).toNumber().toFixed(2),
donors.length,
totalReferralFees.div(1e24).toNumber().toFixed(2),
];
}, [donationsForProject]);

return (
<Container>
<InfoCard>
<InfoTextPrimary>${totalDonations}</InfoTextPrimary>
<InfoTextPrimary>
{props.nearToUsd
? `$${(totalDonations * props.nearToUsd).toFixed(2)}`
: `${totalDonations} N`}
</InfoTextPrimary>
<InfoTextSecondary>Contributed</InfoTextSecondary>
</InfoCard>
<InfoCard>
<InfoTextPrimary>{totalDonors}</InfoTextPrimary>
<InfoTextSecondary>{totalDonors === 1 ? "Donor" : "Donors"}</InfoTextSecondary>
</InfoCard>
<InfoCard>
<InfoTextPrimary>
{" "}
{props.nearToUsd
? `$${(totalReferralFees * props.nearToUsd).toFixed(2)}`
: `${totalReferralFees} N`}
</InfoTextPrimary>
<InfoTextSecondary>Referral Fees</InfoTextSecondary>
</InfoCard>
</Container>
);
2 changes: 0 additions & 2 deletions build/potlock/src/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ if (state.registryAdmins === null) {
State.update({ registryAdmins });
}

console.log("state: ", state);

const tabContentWidget = {
[CREATE_PROJECT_TAB]: "Project.Create",
[EDIT_PROJECT_TAB]: "Project.Create",
Expand Down
32 changes: 28 additions & 4 deletions build/potlock/src/Project/DonationsInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,54 @@ const donationsForProject = Near.view(donationContractId, "get_donations_for_rec
recipient_id: props.projectId,
});

const [totalDonations, totalDonors] = useMemo(() => {
const [totalDonations, totalDonors, totalReferralFees] = useMemo(() => {
if (!donationsForProject) {
return ["", ""];
}
const donors = [];
let totalDonationAmount = new Big(0);
let totalReferralFees = new Big(0);
for (const donation of donationsForProject) {
if (!donors.includes(donation.donor_id)) {
donors.push(donation.donor_id);
}
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
const totalAmount = new Big(donation.total_amount);
const referralAmount = new Big(donation.referrer_fee || "0");
const protocolAmount = new Big(donation.protocol_fee || "0");
totalDonationAmount = totalDonationAmount.plus(
totalAmount.minus(referralAmount).minus(protocolAmount)
);
totalReferralFees = totalReferralFees.plus(referralAmount);
}
return [totalDonationAmount.div(1e24).toNumber().toFixed(2), donors.length];
return [
totalDonationAmount.div(1e24).toNumber().toFixed(2),
donors.length,
totalReferralFees.div(1e24).toNumber().toFixed(2),
];
}, [donationsForProject]);

return (
<Container>
<InfoCard>
<InfoTextPrimary>${totalDonations}</InfoTextPrimary>
<InfoTextPrimary>
{props.nearToUsd
? `$${(totalDonations * props.nearToUsd).toFixed(2)}`
: `${totalDonations} N`}
</InfoTextPrimary>
<InfoTextSecondary>Contributed</InfoTextSecondary>
</InfoCard>
<InfoCard>
<InfoTextPrimary>{totalDonors}</InfoTextPrimary>
<InfoTextSecondary>{totalDonors === 1 ? "Donor" : "Donors"}</InfoTextSecondary>
</InfoCard>
<InfoCard>
<InfoTextPrimary>
{" "}
{props.nearToUsd
? `$${(totalReferralFees * props.nearToUsd).toFixed(2)}`
: `${totalReferralFees} N`}
</InfoTextPrimary>
<InfoTextSecondary>Referral Fees</InfoTextSecondary>
</InfoCard>
</Container>
);

0 comments on commit df4c3c5

Please sign in to comment.