diff --git a/web/components/leaderboard.tsx b/web/components/leaderboard.tsx
index eb0fdcfc..54e105b5 100644
--- a/web/components/leaderboard.tsx
+++ b/web/components/leaderboard.tsx
@@ -16,7 +16,7 @@ export function Leaderboard(props: {
const { title, users, columns, className } = props
return (
-
+
{users.length === 0 ? (
None yet
) : (
diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx
index 8346f245..9fde1c18 100644
--- a/web/pages/fold/[...slugs]/index.tsx
+++ b/web/pages/fold/[...slugs]/index.tsx
@@ -74,10 +74,10 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) {
)
const creatorScores = scoreCreators(contracts, bets)
- const [topCreators, topCreatorScores] = await toUserScores(creatorScores)
+ const topCreators = await toTopUsers(creatorScores)
const traderScores = scoreTraders(contracts, bets)
- const [topTraders, topTraderScores] = await toUserScores(traderScores)
+ const topTraders = await toTopUsers(traderScores)
return {
props: {
@@ -87,17 +87,17 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) {
activeContracts,
activeContractBets,
activeContractComments,
+ traderScores,
topTraders,
- topTraderScores,
+ creatorScores,
topCreators,
- topCreatorScores,
},
revalidate: 60, // regenerate after a minute
}
}
-async function toUserScores(userScores: { [userId: string]: number }) {
+async function toTopUsers(userScores: { [userId: string]: number }) {
const topUserPairs = _.take(
_.sortBy(Object.entries(userScores), ([_, score]) => -1 * score),
10
@@ -106,14 +106,7 @@ async function toUserScores(userScores: { [userId: string]: number }) {
const topUsers = await Promise.all(
topUserPairs.map(([userId]) => getUser(userId))
)
- const existingPairs = topUserPairs.filter(([id, _]) =>
- topUsers.find((user) => user?.id === id)
- )
- const topExistingUsers = existingPairs.map(
- ([id]) => topUsers.find((user) => user?.id === id) as User
- )
- const topUserScores = existingPairs.map(([_, score]) => score)
- return [topExistingUsers, topUserScores] as const
+ return topUsers.filter((user) => user)
}
export async function getStaticPaths() {
@@ -128,19 +121,19 @@ export default function FoldPage(props: {
activeContracts: Contract[]
activeContractBets: Bet[][]
activeContractComments: Comment[][]
+ traderScores: { [userId: string]: number }
topTraders: User[]
- topTraderScores: number[]
+ creatorScores: { [userId: string]: number }
topCreators: User[]
- topCreatorScores: number[]
}) {
const {
curator,
activeContractBets,
activeContractComments,
+ traderScores,
topTraders,
- topTraderScores,
+ creatorScores,
topCreators,
- topCreatorScores,
} = props
const router = useRouter()
@@ -272,25 +265,28 @@ export default function FoldPage(props: {
/>
)}
-
+
)}
{page === 'leaderboards' && (
-
+
)}
@@ -337,14 +333,54 @@ function FoldOverview(props: { fold: Fold; curator: User }) {
}
function FoldLeaderboards(props: {
+ traderScores: { [userId: string]: number }
+ creatorScores: { [userId: string]: number }
topTraders: User[]
- topTraderScores: number[]
topCreators: User[]
- topCreatorScores: number[]
+ user: User | null | undefined
+ yourPerformanceClassName?: string
}) {
- const { topTraders, topTraderScores, topCreators, topCreatorScores } = props
+ const {
+ traderScores,
+ creatorScores,
+ topTraders,
+ topCreators,
+ user,
+ yourPerformanceClassName,
+ } = props
+
+ const yourTraderScore = user ? traderScores[user.id] : undefined
+ const yourCreatorScore = user ? creatorScores[user.id] : undefined
+
+ const topTraderScores = topTraders.map((user) => traderScores[user.id])
+ const topCreatorScores = topCreators.map((user) => creatorScores[user.id])
+
return (
<>
+ {user && (
+
+
+ Your performance
+
+
+
+
+
+ Trading profit |
+ {formatMoney(yourTraderScore ?? 0)} |
+
+ {yourCreatorScore && (
+
+ Created market vol |
+ {formatMoney(yourCreatorScore)} |
+
+ )}
+
+
+
+
+ )}
+
+
formatMoney(topCreatorScores[topCreators.indexOf(user)]),
},