2022-05-09 13:04:36 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Leaderboard } from 'web/components/leaderboard'
|
|
|
|
import { Page } from 'web/components/page'
|
2022-08-12 03:48:50 +00:00
|
|
|
import { User, getFirstDayProfit, listAllUsers } from 'web/lib/firebase/users'
|
2022-06-22 20:29:40 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { Title } from 'web/components/title'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2022-07-22 16:56:03 +00:00
|
|
|
import { SEO } from 'web/components/SEO'
|
2022-08-12 03:48:50 +00:00
|
|
|
import { sortBy } from 'lodash'
|
2022-01-18 03:20:25 +00:00
|
|
|
|
2022-07-19 20:39:15 +00:00
|
|
|
export async function getStaticProps() {
|
|
|
|
const props = await fetchProps()
|
|
|
|
|
|
|
|
return {
|
|
|
|
props,
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
2022-06-22 20:29:40 +00:00
|
|
|
}
|
2022-07-19 20:39:15 +00:00
|
|
|
|
|
|
|
const fetchProps = async () => {
|
2022-08-12 03:48:50 +00:00
|
|
|
const users = await listAllUsers()
|
|
|
|
const firstDayProfit = await Promise.all(
|
|
|
|
users.map((user) => getFirstDayProfit(user.id))
|
|
|
|
)
|
|
|
|
const userProfit = users.map(
|
|
|
|
(user, i) => [user, user.profitCached.allTime - firstDayProfit[i]] as const
|
|
|
|
)
|
|
|
|
const topTradersProfit = sortBy(userProfit, ([_, profit]) => profit)
|
|
|
|
.reverse()
|
|
|
|
.filter(
|
|
|
|
([user]) =>
|
|
|
|
user.username !== 'SalemCenter' && user.username !== 'RichardHanania'
|
|
|
|
)
|
|
|
|
.slice(0, 20)
|
2022-07-19 20:39:15 +00:00
|
|
|
|
2022-08-12 03:48:50 +00:00
|
|
|
console.log(topTradersProfit)
|
|
|
|
|
|
|
|
const topTraders = topTradersProfit.map(([user]) => user)
|
|
|
|
|
|
|
|
// Hide profit for now.
|
|
|
|
topTraders.forEach((user) => {
|
|
|
|
user.profitCached.allTime = 0
|
|
|
|
})
|
2022-07-19 20:39:15 +00:00
|
|
|
|
2022-01-18 03:20:25 +00:00
|
|
|
return {
|
2022-07-19 20:39:15 +00:00
|
|
|
topTraders,
|
2022-01-18 03:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 03:48:50 +00:00
|
|
|
export default function Leaderboards(_props: { topTraders: User[] }) {
|
|
|
|
const [{ topTraders }, setProps] =
|
|
|
|
useState<Parameters<typeof Leaderboards>[0]>(_props)
|
2022-07-19 20:39:15 +00:00
|
|
|
|
2022-06-22 20:29:40 +00:00
|
|
|
useEffect(() => {
|
2022-07-19 20:39:15 +00:00
|
|
|
fetchProps().then((props) => setProps(props))
|
|
|
|
}, [])
|
2022-06-22 20:29:40 +00:00
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view leaderboards')
|
|
|
|
|
2022-01-18 03:20:25 +00:00
|
|
|
return (
|
2022-06-16 21:43:34 +00:00
|
|
|
<Page>
|
2022-07-22 16:56:03 +00:00
|
|
|
<SEO
|
|
|
|
title="Leaderboards"
|
|
|
|
description="Manifold's leaderboards show the top traders and market creators."
|
|
|
|
url="/leaderboards"
|
|
|
|
/>
|
2022-06-22 20:29:40 +00:00
|
|
|
<Title text={'Leaderboards'} className={'hidden md:block'} />
|
2022-08-12 03:48:50 +00:00
|
|
|
|
|
|
|
<Col className="mx-4 max-w-sm items-center gap-10 lg:flex-row">
|
|
|
|
<Leaderboard
|
|
|
|
className="my-4"
|
|
|
|
title="🏅 Top traders"
|
|
|
|
users={topTraders}
|
|
|
|
columns={
|
|
|
|
[
|
|
|
|
// Hide profit for now.
|
|
|
|
// {
|
|
|
|
// header: 'Total profit',
|
|
|
|
// renderCell: (user) => formatMoney(user.profitCached[period]),
|
|
|
|
// },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Col>
|
2022-01-18 03:20:25 +00:00
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|