2022-06-14 03:53:29 +00:00
|
|
|
import {
|
|
|
|
mapValues,
|
|
|
|
groupBy,
|
|
|
|
sumBy,
|
|
|
|
sum,
|
|
|
|
sortBy,
|
|
|
|
debounce,
|
|
|
|
uniqBy,
|
|
|
|
} from 'lodash'
|
2022-04-29 23:35:56 +00:00
|
|
|
import { useState, useMemo } from 'react'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { charities, Charity as CharityType } from 'common/charity'
|
|
|
|
import { CharityCard } from 'web/components/charity/charity-card'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Spacer } from 'web/components/layout/spacer'
|
|
|
|
import { Page } from 'web/components/page'
|
|
|
|
import { SiteLink } from 'web/components/site-link'
|
|
|
|
import { Title } from 'web/components/title'
|
|
|
|
import { getAllCharityTxns } from 'web/lib/firebase/txns'
|
2022-06-14 04:27:20 +00:00
|
|
|
import { manaToUSD } from 'common/util/format'
|
2022-06-14 03:53:29 +00:00
|
|
|
import { quadraticMatches } from 'common/quadratic-funding'
|
|
|
|
import { Txn } from 'common/txn'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2022-04-29 23:35:56 +00:00
|
|
|
|
2022-05-03 17:25:14 +00:00
|
|
|
export async function getStaticProps() {
|
|
|
|
const txns = await getAllCharityTxns()
|
2022-05-22 08:36:05 +00:00
|
|
|
const totals = mapValues(groupBy(txns, 'toId'), (txns) =>
|
|
|
|
sumBy(txns, (txn) => txn.amount)
|
2022-05-02 17:55:40 +00:00
|
|
|
)
|
2022-05-22 08:36:05 +00:00
|
|
|
const totalRaised = sum(Object.values(totals))
|
|
|
|
const sortedCharities = sortBy(charities, [
|
2022-05-02 17:55:40 +00:00
|
|
|
(charity) => (charity.tags?.includes('Featured') ? 0 : 1),
|
|
|
|
(charity) => -totals[charity.id],
|
|
|
|
])
|
2022-06-14 03:53:29 +00:00
|
|
|
const matches = quadraticMatches(txns, totalRaised)
|
|
|
|
const numDonors = uniqBy(txns, (txn) => txn.fromId).length
|
2022-05-02 17:55:40 +00:00
|
|
|
|
2022-05-03 17:25:14 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
totalRaised,
|
|
|
|
charities: sortedCharities,
|
2022-06-14 03:53:29 +00:00
|
|
|
matches,
|
|
|
|
txns,
|
|
|
|
numDonors,
|
2022-05-03 17:25:14 +00:00
|
|
|
},
|
|
|
|
revalidate: 60,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 03:53:29 +00:00
|
|
|
type Stat = {
|
|
|
|
name: string
|
|
|
|
stat: string
|
|
|
|
}
|
|
|
|
|
|
|
|
function DonatedStats(props: { stats: Stat[] }) {
|
|
|
|
const { stats } = props
|
|
|
|
return (
|
|
|
|
<dl className="mt-3 grid grid-cols-1 gap-5 rounded-lg bg-gradient-to-r from-pink-300 via-purple-300 to-indigo-400 p-4 sm:grid-cols-3">
|
|
|
|
{stats.map((item) => (
|
|
|
|
<div
|
|
|
|
key={item.name}
|
|
|
|
className="overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:p-6"
|
|
|
|
>
|
|
|
|
<dt className="truncate text-sm font-medium text-gray-500">
|
|
|
|
{item.name}
|
|
|
|
</dt>
|
|
|
|
<dd className="mt-1 text-3xl font-semibold text-gray-900">
|
|
|
|
{item.stat}
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</dl>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-03 17:25:14 +00:00
|
|
|
export default function Charity(props: {
|
|
|
|
totalRaised: number
|
|
|
|
charities: CharityType[]
|
2022-06-14 03:53:29 +00:00
|
|
|
matches: { [charityId: string]: number }
|
|
|
|
txns: Txn[]
|
|
|
|
numDonors: number
|
2022-05-03 17:25:14 +00:00
|
|
|
}) {
|
2022-06-14 03:53:29 +00:00
|
|
|
const { totalRaised, charities, matches, numDonors } = props
|
2022-05-03 17:25:14 +00:00
|
|
|
|
2022-04-29 23:35:56 +00:00
|
|
|
const [query, setQuery] = useState('')
|
2022-05-22 08:36:05 +00:00
|
|
|
const debouncedQuery = debounce(setQuery, 50)
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
const filterCharities = useMemo(
|
2022-04-30 12:42:25 +00:00
|
|
|
() =>
|
2022-05-05 14:12:16 +00:00
|
|
|
charities.filter(
|
|
|
|
(charity) =>
|
|
|
|
charity.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
|
|
charity.preview.toLowerCase().includes(query.toLowerCase()) ||
|
|
|
|
charity.description.toLowerCase().includes(query.toLowerCase()) ||
|
|
|
|
(charity.tags as string[])?.includes(query.toLowerCase())
|
2022-04-30 12:42:25 +00:00
|
|
|
),
|
2022-05-10 21:49:24 +00:00
|
|
|
[charities, query]
|
2022-04-29 23:35:56 +00:00
|
|
|
)
|
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view charity')
|
|
|
|
|
2022-04-29 23:35:56 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-05-03 15:26:02 +00:00
|
|
|
<Col className="w-full rounded px-4 py-6 sm:px-8 xl:w-[125%]">
|
2022-06-14 03:53:29 +00:00
|
|
|
<Col className="">
|
2022-06-11 16:15:59 +00:00
|
|
|
<Title className="!mt-0" text="Manifold for Charity" />
|
2022-06-14 03:53:29 +00:00
|
|
|
<span className="text-gray-600">
|
2022-06-14 04:27:20 +00:00
|
|
|
Through July 15, up to $25k of donations will be matched via{' '}
|
|
|
|
<SiteLink href="https://wtfisqf.com/" className="font-bold">
|
|
|
|
quadratic funding
|
|
|
|
</SiteLink>
|
|
|
|
, courtesy of{' '}
|
|
|
|
<SiteLink href="https://ftxfuturefund.org/" className="font-bold">
|
|
|
|
the FTX Future Fund
|
|
|
|
</SiteLink>
|
|
|
|
!
|
2022-06-14 03:53:29 +00:00
|
|
|
</span>
|
|
|
|
<DonatedStats
|
|
|
|
stats={[
|
|
|
|
{
|
|
|
|
name: 'Raised by Manifold users',
|
|
|
|
stat: manaToUSD(totalRaised),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Number of donors',
|
|
|
|
stat: `${numDonors}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Matched via quadratic funding',
|
|
|
|
stat: manaToUSD(sum(Object.values(matches))),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Spacer h={10} />
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
onChange={(e) => debouncedQuery(e.target.value)}
|
2022-06-14 03:53:29 +00:00
|
|
|
placeholder="Find a charity"
|
2022-04-29 23:35:56 +00:00
|
|
|
className="input input-bordered mb-6 w-full"
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
<div className="grid max-w-xl grid-flow-row grid-cols-1 gap-4 lg:max-w-full lg:grid-cols-2 xl:grid-cols-3">
|
|
|
|
{filterCharities.map((charity) => (
|
2022-06-14 03:53:29 +00:00
|
|
|
<CharityCard
|
|
|
|
charity={charity}
|
|
|
|
key={charity.name}
|
|
|
|
match={matches[charity.id]}
|
|
|
|
/>
|
2022-04-29 23:35:56 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{filterCharities.length === 0 && (
|
|
|
|
<div className="text-center text-gray-500">
|
2022-04-30 12:42:25 +00:00
|
|
|
😢 We couldn't find that charity...
|
2022-04-29 23:35:56 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-06-14 04:27:20 +00:00
|
|
|
<div className="mt-10 w-full rounded-xl bg-gradient-to-r from-pink-300 via-purple-300 to-indigo-400 p-5">
|
|
|
|
<iframe
|
|
|
|
height="405"
|
|
|
|
src="https://manifold.markets/ManifoldMarkets/how-much-will-be-donated-through-ma"
|
|
|
|
title="Total donations for Manifold for Charity this May (in USD)"
|
|
|
|
frameBorder="0"
|
|
|
|
className="w-full rounded-xl bg-white p-10"
|
|
|
|
></iframe>
|
|
|
|
</div>
|
2022-04-30 20:27:19 +00:00
|
|
|
|
2022-04-30 12:42:25 +00:00
|
|
|
<div className="mt-10 text-gray-500">
|
2022-06-14 04:27:20 +00:00
|
|
|
<span className="font-semibold">Notes</span>
|
|
|
|
<br />
|
|
|
|
- Don't see your favorite charity? Recommend it by emailing
|
2022-06-14 03:53:29 +00:00
|
|
|
charity@manifold.markets!
|
2022-04-29 23:35:56 +00:00
|
|
|
<br />
|
2022-06-14 04:27:20 +00:00
|
|
|
- Manifold is not affiliated with non-Featured charities; we're just
|
|
|
|
fans of their work.
|
2022-04-30 12:42:25 +00:00
|
|
|
<br />
|
2022-06-14 04:27:20 +00:00
|
|
|
- As Manifold itself is a for-profit entity, your contributions will
|
|
|
|
not be tax deductible.
|
|
|
|
<br />- Donations + matches are wired once each quarter.
|
2022-04-29 23:35:56 +00:00
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|