align to new api response
This commit is contained in:
parent
d4344b7241
commit
91e9a3df2e
|
@ -3,56 +3,49 @@ import { LinkButton } from '@components/shared/Button'
|
||||||
import SheenLoader from '@components/shared/SheenLoader'
|
import SheenLoader from '@components/shared/SheenLoader'
|
||||||
import { NoSymbolIcon } from '@heroicons/react/20/solid'
|
import { NoSymbolIcon } from '@heroicons/react/20/solid'
|
||||||
import { useInfiniteQuery } from '@tanstack/react-query'
|
import { useInfiniteQuery } from '@tanstack/react-query'
|
||||||
import { isArray } from 'lodash'
|
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
import { useMemo, useState } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import { EmptyObject, ProfileDetails } from 'types'
|
import { EmptyObject } from 'types'
|
||||||
import { MANGO_DATA_API_URL } from 'utils/constants'
|
import { MANGO_DATA_API_URL } from 'utils/constants'
|
||||||
import LeaderboardTable from './LeaderboardTable'
|
import LeaderboardTable from './LeaderboardTable'
|
||||||
|
|
||||||
interface LeaderboardRes {
|
export interface LeaderboardRes {
|
||||||
date_hour: string
|
date_hour: string
|
||||||
mango_account: string
|
mango_account: string
|
||||||
pnl: number
|
pnl: number
|
||||||
|
profile_image_url: string | null
|
||||||
|
profile_name: string
|
||||||
start_date_hour: string
|
start_date_hour: string
|
||||||
|
trader_category: string
|
||||||
wallet_pk: string
|
wallet_pk: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LeaderboardItem = LeaderboardRes & ProfileDetails
|
|
||||||
|
|
||||||
type DaysToShow = '1DAY' | '1WEEK' | 'ALLTIME'
|
type DaysToShow = '1DAY' | '1WEEK' | 'ALLTIME'
|
||||||
|
|
||||||
|
const isLeaderboard = (
|
||||||
|
response: null | EmptyObject | LeaderboardRes[]
|
||||||
|
): response is LeaderboardRes[] => {
|
||||||
|
if (response && Array.isArray(response)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const fetchLeaderboard = async (
|
const fetchLeaderboard = async (
|
||||||
daysToShow: DaysToShow,
|
daysToShow: DaysToShow,
|
||||||
offset = 0
|
offset = 0
|
||||||
): Promise<Array<LeaderboardItem>> => {
|
): Promise<Array<LeaderboardRes>> => {
|
||||||
const data = await fetch(
|
const data = await fetch(
|
||||||
`${MANGO_DATA_API_URL}/leaderboard-pnl?over_period=${daysToShow}&offset=${offset}`
|
`${MANGO_DATA_API_URL}/leaderboard-pnl?over_period=${daysToShow}&offset=${offset}`
|
||||||
)
|
)
|
||||||
const leaderboardRes: null | EmptyObject | LeaderboardRes[] =
|
const parsedData: null | EmptyObject | LeaderboardRes[] = await data.json()
|
||||||
await data.json()
|
|
||||||
if (leaderboardRes && isArray(leaderboardRes)) {
|
let leaderboardData
|
||||||
const profileData = await Promise.all(
|
if (isLeaderboard(parsedData)) {
|
||||||
leaderboardRes.map((r: LeaderboardRes) =>
|
leaderboardData = parsedData
|
||||||
fetch(
|
|
||||||
`${MANGO_DATA_API_URL}/user-data/profile-details?wallet-pk=${r.wallet_pk}`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
const profileRes: null | EmptyObject | ProfileDetails[] = await Promise.all(
|
|
||||||
profileData.map((d) => d.json())
|
|
||||||
)
|
|
||||||
if (profileRes && isArray(profileRes)) {
|
|
||||||
const combinedRes = leaderboardRes.map(
|
|
||||||
(r: LeaderboardRes, i: number) => ({
|
|
||||||
...r,
|
|
||||||
...profileRes[i],
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return combinedRes
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return []
|
return leaderboardData ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
const LeaderboardPage = () => {
|
const LeaderboardPage = () => {
|
||||||
|
@ -101,7 +94,7 @@ const LeaderboardPage = () => {
|
||||||
activeValue={daysToShow}
|
activeValue={daysToShow}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
onChange={(v) => handleDaysToShow(v)}
|
onChange={(v) => handleDaysToShow(v)}
|
||||||
names={['24h', '7d', t('all')]}
|
names={['24h', '7d', '30d', t('all')]}
|
||||||
values={['1DAY', '1WEEK', 'ALLTIME']}
|
values={['1DAY', '1WEEK', 'ALLTIME']}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,13 +5,13 @@ import { ChevronRightIcon } from '@heroicons/react/20/solid'
|
||||||
import { useViewport } from 'hooks/useViewport'
|
import { useViewport } from 'hooks/useViewport'
|
||||||
import { formatCurrencyValue } from 'utils/numbers'
|
import { formatCurrencyValue } from 'utils/numbers'
|
||||||
import { breakpoints } from 'utils/theme'
|
import { breakpoints } from 'utils/theme'
|
||||||
import { LeaderboardItem } from './LeaderboardPage'
|
import { LeaderboardRes } from './LeaderboardPage'
|
||||||
|
|
||||||
const LeaderboardTable = ({
|
const LeaderboardTable = ({
|
||||||
data,
|
data,
|
||||||
loading,
|
loading,
|
||||||
}: {
|
}: {
|
||||||
data: LeaderboardItem[]
|
data: LeaderboardRes[]
|
||||||
loading: boolean
|
loading: boolean
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
|
@ -48,7 +48,7 @@ const LeaderboardRow = ({
|
||||||
loading,
|
loading,
|
||||||
rank,
|
rank,
|
||||||
}: {
|
}: {
|
||||||
item: LeaderboardItem
|
item: LeaderboardRes
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
rank: number
|
rank: number
|
||||||
}) => {
|
}) => {
|
||||||
|
|
|
@ -9,7 +9,7 @@ const ProfileImage = ({
|
||||||
}: {
|
}: {
|
||||||
imageSize: string
|
imageSize: string
|
||||||
placeholderSize: string
|
placeholderSize: string
|
||||||
imageUrl?: string
|
imageUrl?: string | null
|
||||||
isOwnerProfile?: boolean
|
isOwnerProfile?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const profile = mangoStore((s) => s.profile.details)
|
const profile = mangoStore((s) => s.profile.details)
|
||||||
|
|
Loading…
Reference in New Issue