Skip to content

Commit

Permalink
fix: issue where leaderboard not rendering for user without creator a…
Browse files Browse the repository at this point in the history
…ctivity
  • Loading branch information
teodorus-nathaniel committed Jan 31, 2024
1 parent 885fb68 commit 581f846
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/components/leaderboard/common/LeaderboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import styles from './LeaderboardTable.module.sass'
export type LeaderboardTableProps = ComponentProps<'div'> & {
role: LeaderboardRole
currentUserRank?: {
rank: number
rank?: number
reward: string
address: string
}
Expand All @@ -55,7 +55,7 @@ export default function LeaderboardTable({
addresses: string[]
slicedData: typeof data
}>(() => {
if (!currentUserRank || currentUserRank.rank < TABLE_LIMIT) {
if (!currentUserRank || (currentUserRank?.rank ?? 0) < TABLE_LIMIT) {
return {
addresses: data.slice(0, TABLE_LIMIT).map(row => row.address),
slicedData: data.slice(0, TABLE_LIMIT),
Expand Down Expand Up @@ -161,7 +161,7 @@ function UserRow({
'!ColorNormal',
)}
>
<MutedSpan>{data.rank + 1}</MutedSpan>
<MutedSpan>{data?.rank !== undefined && data.rank + 1}</MutedSpan>
<div className='d-flex align-items-center' style={{ minWidth: 0, height: '41px' }}>
{isLoading ? (
<>
Expand Down
8 changes: 4 additions & 4 deletions src/components/utils/datahub/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export async function getUserStatistics({ address }: { address: string }): Promi
staker: {
reward: string
rankIndex: number
}
} | null
creator: {
reward: string
rankIndex: number
}
} | null
activeStakingAccountActivityMetricsForFixedPeriod: {
staker: {
likedCreators: number
Expand All @@ -146,11 +146,11 @@ export async function getUserStatistics({ address }: { address: string }): Promi
address,
creator: {
...res.data.activeStakingAccountActivityMetricsForFixedPeriod.creator,
rank: res.data.creator.rankIndex,
rank: res.data.creator?.rankIndex,
},
staker: {
...res.data.activeStakingAccountActivityMetricsForFixedPeriod.staker,
rank: res.data.staker.rankIndex,
rank: res.data.staker?.rankIndex,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtk/features/leaderboard/leaderboardSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createSimpleFetchWrapper } from 'src/rtk/app/wrappers'
export type LeaderboardData = {
total: number
page: number
data: { reward: string; rank: number; address: string }[]
data: { reward: string; rank?: number; address: string }[]
hasMore: boolean
role: LeaderboardRole
}
Expand Down
4 changes: 2 additions & 2 deletions src/rtk/features/leaderboard/userStatisticsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export type UserStatistics = {
likedPosts: number
earnedByPeriod: string
earnedTotal: string
rank: number
rank: number | undefined
}
creator: {
likesCountByPeriod: number
stakersWhoLiked: number
earnedByPeriod: string
earnedTotal: string
rank: number
rank: number | undefined
}
}

Expand Down

0 comments on commit 581f846

Please sign in to comment.