Only show profitable traders

This commit is contained in:
Austin Chen 2022-03-18 21:05:32 -07:00
parent b8e391f0f0
commit e14acd28c0

View File

@ -214,18 +214,23 @@ function ContractLeaderboard(props: { contract: Contract; bets: Bet[] }) {
_.sumBy(bets, (bet) => resolvedPayout(contract, bet) - bet.amount) _.sumBy(bets, (bet) => resolvedPayout(contract, bet) - bet.amount)
) )
// Find the 5 users with the most profit // Find the 5 users with the most profits
const topUsers = _.entries(userProfits).sort(([i1, p1], [i2, p2]) => p2 - p1) const top5Ids = _.entries(userProfits)
const top5Ids = topUsers.slice(0, 5).map(([userId]) => userId) .sort(([i1, p1], [i2, p2]) => p2 - p1)
.filter(([, p]) => p > 0)
.slice(0, 5)
.map(([id]) => id)
useEffect(() => { useEffect(() => {
listUsers(top5Ids).then((users) => { if (top5Ids.length > 0) {
const sortedUsers = _.sortBy(users, (user) => -userProfits[user.id]) listUsers(top5Ids).then((users) => {
setUsers(sortedUsers) const sortedUsers = _.sortBy(users, (user) => -userProfits[user.id])
}) setUsers(sortedUsers)
})
}
}, []) }, [])
return ( return users && users.length > 0 ? (
<Leaderboard <Leaderboard
title="Top Traders" title="Top Traders"
users={users || []} users={users || []}
@ -237,7 +242,7 @@ function ContractLeaderboard(props: { contract: Contract; bets: Bet[] }) {
]} ]}
className="mt-12 max-w-sm" className="mt-12 max-w-sm"
/> />
) ) : null
} }
const getOpenGraphProps = (contract: Contract) => { const getOpenGraphProps = (contract: Contract) => {