Fix crash when there aren't any bets
This commit is contained in:
parent
a9cdeb46a2
commit
a3067527ee
|
@ -16,11 +16,13 @@ export const useUsers = () => {
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUserById = (userId: string) => {
|
export const useUserById = (userId?: string) => {
|
||||||
const [user, setUser] = useState<User | undefined>(undefined)
|
const [user, setUser] = useState<User | undefined>(undefined)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
getUser(userId).then(setUser)
|
getUser(userId).then(setUser)
|
||||||
|
}
|
||||||
}, [userId])
|
}, [userId])
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
|
@ -280,7 +280,7 @@ function ContractTopTrades(props: {
|
||||||
|
|
||||||
// Now find the betId with the highest profit
|
// Now find the betId with the highest profit
|
||||||
const topBetId = _.sortBy(bets, (b) => -profitById[b.id])[0]?.id
|
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
|
// And also the commentId of the comment with the highest profit
|
||||||
const topCommentId = _.sortBy(comments, (c) => -profitById[c.betId])[0]?.id
|
const topCommentId = _.sortBy(comments, (c) => -profitById[c.betId])[0]?.id
|
||||||
|
|
Loading…
Reference in New Issue
Block a user