From 5ca8c9a7053f9f680d26f0cb8155cebc9b851e5e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 25 Apr 2022 23:00:18 -0400 Subject: [PATCH] Read txns for charity card and charity page. --- common/charity.ts | 3 +-- web/components/charity/charity-card.tsx | 7 ++++++- web/pages/charity/[charitySlug].tsx | 17 ++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/common/charity.ts b/common/charity.ts index 5b5a1e64..92f87178 100644 --- a/common/charity.ts +++ b/common/charity.ts @@ -1,12 +1,11 @@ export interface Charity { id: string - slug: string // Note, slugs double as charity IDs + slug: string name: string website: string ein: string photo: string blurb: string - raised?: number } export const charities: Charity[] = [ diff --git a/web/components/charity/charity-card.tsx b/web/components/charity/charity-card.tsx index 3ecd3ce8..e0ba6466 100644 --- a/web/components/charity/charity-card.tsx +++ b/web/components/charity/charity-card.tsx @@ -1,9 +1,14 @@ +import _ from 'lodash' import Link from 'next/link' import { Charity } from '../../../common/charity' +import { useCharityTxns } from '../../hooks/use-charity-txns' import { Row } from '../layout/row' export function CharityCard(props: { charity: Charity }) { - const { name, slug, photo, raised, blurb } = props.charity + const { name, slug, photo, blurb, id } = props.charity + + const txns = useCharityTxns(id) + const raised = _.sumBy(txns, (txn) => txn.amount) return ( diff --git a/web/pages/charity/[charitySlug].tsx b/web/pages/charity/[charitySlug].tsx index c6997b9e..5e00eaf2 100644 --- a/web/pages/charity/[charitySlug].tsx +++ b/web/pages/charity/[charitySlug].tsx @@ -40,6 +40,11 @@ function CharityPage(props: { charity: Charity }) { const txns = useCharityTxns(charity.id) const totalRaised = _.sumBy(txns, (txn) => txn.amount) + const fromYou = _.sumBy( + txns.filter((txn) => txn.fromId === user?.id), + (txn) => txn.amount + ) + const numSupporters = _.uniqBy(txns, (txn) => txn.fromId).length return ( }> @@ -51,9 +56,9 @@ function CharityPage(props: { charity: Charity }) { {photo && }

About

@@ -99,9 +104,9 @@ function Blurb({ text }: { text: string }) { function Details(props: { charity: Charity - userDonated?: number - numSupporters: number totalRaised: number + userDonated: number + numSupporters: number }) { const { charity, userDonated, numSupporters, totalRaised } = props const { website } = charity @@ -110,7 +115,7 @@ function Details(props: {
{manaToUSD(totalRaised ?? 0)} raised
- {userDonated && ( + {userDonated > 0 && (
{manaToUSD(userDonated)} from you!
@@ -139,8 +144,6 @@ function DonationBox(props: { user?: User | null; charity: Charity }) { setError(undefined) await transact({ amount, - // TODO hardcode in Manifold Markets official account. - // Or should we just have it go into a void? fromId: user.id, fromType: 'user', toId: charity.id,