Fix crash when there aren't any bets

This commit is contained in:
Austin Chen 2022-03-21 15:19:42 -07:00
parent a9cdeb46a2
commit a3067527ee
2 changed files with 5 additions and 3 deletions

View File

@ -16,11 +16,13 @@ export const useUsers = () => {
return users
}
export const useUserById = (userId: string) => {
export const useUserById = (userId?: string) => {
const [user, setUser] = useState<User | undefined>(undefined)
useEffect(() => {
getUser(userId).then(setUser)
if (userId) {
getUser(userId).then(setUser)
}
}, [userId])
return user

View File

@ -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