diff --git a/web/package.json b/web/package.json index 6e9d6f7d..2707476e 100644 --- a/web/package.json +++ b/web/package.json @@ -47,8 +47,8 @@ "autoprefixer": "10.2.6", "concurrently": "6.5.1", "critters": "0.0.16", - "eslint": "7.32.0", - "eslint-config-next": "12.0.4", + "eslint": "8.15.0", + "eslint-config-next": "12.1.6", "husky": "7.0.4", "lint-staged": "12.1.3", "next-sitemap": "^2.5.14", diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 96b5feee..e5a8ee43 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react' +import React, { useEffect, useMemo, useState } from 'react' import { ArrowLeftIcon } from '@heroicons/react/outline' import { useContractWithPreload } from 'web/hooks/use-contract' @@ -207,27 +207,30 @@ function ContractLeaderboard(props: { contract: Contract; bets: Bet[] }) { const { contract, bets } = props const [users, setUsers] = useState() - // Create a map of userIds to total profits (including sales) - const betsByUser = _.groupBy(bets, 'userId') - const userProfits = _.mapValues(betsByUser, (bets) => - _.sumBy(bets, (bet) => resolvedPayout(contract, bet) - bet.amount) - ) - - // Find the 5 users with the most profits - const top5Ids = _.entries(userProfits) - .sort(([i1, p1], [i2, p2]) => p2 - p1) - .filter(([, p]) => p > 0) - .slice(0, 5) - .map(([id]) => id) + const { userProfits, top5Ids } = useMemo(() => { + // Create a map of userIds to total profits (including sales) + const betsByUser = _.groupBy(bets, 'userId') + const userProfits = _.mapValues(betsByUser, (bets) => + _.sumBy(bets, (bet) => resolvedPayout(contract, bet) - bet.amount) + ) + // Find the 5 users with the most profits + const top5Ids = _.entries(userProfits) + .sort(([i1, p1], [i2, p2]) => p2 - p1) + .filter(([, p]) => p > 0) + .slice(0, 5) + .map(([id]) => id) + return { userProfits, top5Ids } + }, [contract, bets]) useEffect(() => { + console.log('foo') if (top5Ids.length > 0) { listUsers(top5Ids).then((users) => { const sortedUsers = _.sortBy(users, (user) => -userProfits[user.id]) setUsers(sortedUsers) }) } - }, []) + }, [userProfits, top5Ids]) return users && users.length > 0 ? ( + Manifold Markets — A market for every question diff --git a/web/pages/_document.tsx b/web/pages/_document.tsx index 93d5d774..f1a7ccab 100644 --- a/web/pages/_document.tsx +++ b/web/pages/_document.tsx @@ -17,28 +17,12 @@ export default function Document() { href="https://fonts.googleapis.com/css2?family=Major+Mono+Display&family=Readex+Pro:wght@400;600;700&display=swap" rel="stylesheet" /> - - -