mango-v4-ui/components/leaderboard/LeaderboardTable.tsx

108 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-03-06 00:59:14 -08:00
import MedalIcon from '@components/icons/MedalIcon'
import ProfileImage from '@components/profile/ProfileImage'
2023-03-14 03:50:42 -07:00
import SheenLoader from '@components/shared/SheenLoader'
2023-03-06 00:59:14 -08:00
import { ChevronRightIcon } from '@heroicons/react/20/solid'
import { useViewport } from 'hooks/useViewport'
import { formatCurrencyValue } from 'utils/numbers'
import { breakpoints } from 'utils/theme'
2023-03-14 03:50:42 -07:00
import { LeaderboardItem } from './LeaderboardPage'
2023-03-06 00:59:14 -08:00
2023-03-14 03:50:42 -07:00
const LeaderboardTable = ({
data,
loading,
}: {
data: LeaderboardItem[]
loading: boolean
}) => {
2023-03-06 00:59:14 -08:00
return (
<>
2023-03-14 03:50:42 -07:00
{/* <div className="grid grid-cols-12 px-4 pb-2">
2023-03-06 00:59:14 -08:00
<div className="col-span-2 md:col-span-1">
<p className="text-xs text-th-fgd-4">{t('rank')}</p>
</div>
<div className="col-span-4 md:col-span-5">
<p className="text-xs text-th-fgd-4">{t('trader')}</p>
</div>
<div className="col-span-5 flex justify-end">
<p className="text-xs text-th-fgd-4">{t('pnl')}</p>
</div>
2023-03-14 03:50:42 -07:00
</div> */}
2023-03-06 00:59:14 -08:00
<div className="space-y-2">
2023-03-14 03:50:42 -07:00
{data.map((d, i) => (
<LeaderboardRow
item={d}
rank={i + 1}
2023-03-19 20:19:53 -07:00
key={d.mango_account + d.pnl}
2023-03-14 03:50:42 -07:00
loading={loading}
/>
2023-03-06 00:59:14 -08:00
))}
</div>
</>
)
}
export default LeaderboardTable
2023-03-14 03:50:42 -07:00
const LeaderboardRow = ({
item,
loading,
rank,
}: {
item: LeaderboardItem
loading: boolean
2023-03-06 00:59:14 -08:00
rank: number
2023-03-14 03:50:42 -07:00
}) => {
2023-03-15 01:35:29 -07:00
const { profile_name, profile_image_url, mango_account, pnl, wallet_pk } =
item
2023-03-06 00:59:14 -08:00
const { width } = useViewport()
const isMobile = width ? width < breakpoints.md : false
2023-03-14 03:50:42 -07:00
return !loading ? (
<a
className="default-transition flex w-full items-center justify-between rounded-md border border-th-bkg-3 px-3 py-3 md:px-4 md:hover:bg-th-bkg-2"
href={`/?address=${mango_account}`}
rel="noopener noreferrer"
target="_blank"
2023-03-06 00:59:14 -08:00
>
2023-03-14 03:50:42 -07:00
<div className="flex items-center space-x-3">
2023-03-15 01:35:29 -07:00
<div className="relative flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full bg-th-bkg-3 md:mr-2">
2023-03-06 00:59:14 -08:00
<p
className={`relative z-10 font-bold ${
rank < 4 ? 'text-th-bkg-1' : 'text-th-fgd-3'
}`}
>
{rank}
</p>
{rank < 4 ? (
<MedalIcon className="absolute shadow-md" rank={rank} />
) : null}
</div>
2023-03-14 03:50:42 -07:00
<ProfileImage
imageSize={isMobile ? '32' : '40'}
imageUrl={profile_image_url}
placeholderSize={isMobile ? '20' : '24'}
/>
<div className="text-left">
<p className="capitalize text-th-fgd-2 md:text-base">
2023-03-19 20:19:53 -07:00
{profile_name ||
wallet_pk.slice(0, 4) + '...' + wallet_pk.slice(-4)}
2023-03-14 03:50:42 -07:00
</p>
<p className="text-xs text-th-fgd-4">
2023-03-15 01:35:29 -07:00
Acc: {mango_account.slice(0, 4) + '...' + mango_account.slice(-4)}
2023-03-14 03:50:42 -07:00
</p>
2023-03-06 00:59:14 -08:00
</div>
</div>
2023-03-14 03:50:42 -07:00
<div className="flex items-center">
<span className="mr-3 text-right font-mono md:text-base">
{formatCurrencyValue(pnl, 2)}
2023-03-06 00:59:14 -08:00
</span>
2023-03-14 03:50:42 -07:00
<ChevronRightIcon className="h-5 w-5 text-th-fgd-3" />
2023-03-06 00:59:14 -08:00
</div>
2023-03-14 03:50:42 -07:00
</a>
) : (
<SheenLoader className="flex flex-1">
<div className="h-16 w-full rounded-md bg-th-bkg-2" />
</SheenLoader>
2023-03-06 00:59:14 -08:00
)
}