From 167cf20bfcad7f38fcbf117203c4abcae1faa1f8 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 10 May 2022 13:58:38 -0700 Subject: [PATCH] Upgrade eslint, fix eslint warnings (#149) * Add a couple missing dependencies for hooks * Upgrade eslint This newer eslint and typescript-eslint fixes some spurious warnings that were bugs and supports our version of Typescript. * Use Next Script component the way it wants us to * Rephrase ContractLeaderboard component to avoid useEffect woes * Use perhaps more idiomatic type for ContractLeaderboard props * Make Folds data fetching more correct and more clear --- web/package.json | 4 +- web/pages/[username]/[contractSlug].tsx | 34 +- web/pages/_app.tsx | 10 + web/pages/_document.tsx | 16 - web/pages/charity/index.tsx | 2 +- web/pages/folds.tsx | 13 +- yarn.lock | 445 ++++++++++-------------- 7 files changed, 230 insertions(+), 294 deletions(-) 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..6a1a726c 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -131,6 +131,12 @@ export function ContractPageContent(props: FirstArgument) { ) : null + // 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) + ) + return ( {showConfetti && ( @@ -181,7 +187,7 @@ export function ContractPageContent(props: FirstArgument) { {isResolved && ( <>
- + ) { ) } -function ContractLeaderboard(props: { contract: Contract; bets: Bet[] }) { - const { contract, bets } = props +function ContractLeaderboard(props: { userProfits: { [id: string]: number } }) { + const { userProfits } = 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) - useEffect(() => { + // 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) + if (top5Ids.length > 0) { listUsers(top5Ids).then((users) => { const sortedUsers = _.sortBy(users, (user) => -userProfits[user.id]) setUsers(sortedUsers) }) } - }, []) + }, [userProfits]) 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" /> - - -