diff --git a/web/hooks/use-users.ts b/web/hooks/use-users.ts index 35244d73..5d2649b6 100644 --- a/web/hooks/use-users.ts +++ b/web/hooks/use-users.ts @@ -16,11 +16,13 @@ export const useUsers = () => { return users } -export const useUserById = (userId: string) => { +export const useUserById = (userId?: string) => { const [user, setUser] = useState(undefined) useEffect(() => { - getUser(userId).then(setUser) + if (userId) { + getUser(userId).then(setUser) + } }, [userId]) return user diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 487942d5..7e7e6562 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -280,7 +280,7 @@ function ContractTopTrades(props: { // Now find the betId with the highest profit const topBetId = _.sortBy(bets, (b) => -profitById[b.id])[0]?.id - const topBettor = useUserById(betsById[topBetId].userId) + const topBettor = useUserById(betsById[topBetId]?.userId) // And also the commentId of the comment with the highest profit const topCommentId = _.sortBy(comments, (c) => -profitById[c.betId])[0]?.id