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

118 lines
3.4 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'
2023-11-09 18:54:04 -08:00
import {
EquityLeaderboardRes,
PnlLeaderboardRes,
isEquityLeaderboard,
isPnlLeaderboard,
} from './LeaderboardPage'
2023-11-13 20:41:16 -08:00
import ToggleFollowButton from '@components/shared/ToggleFollowButton'
2023-03-06 00:59:14 -08:00
2023-03-14 03:50:42 -07:00
const LeaderboardTable = ({
data,
loading,
2023-11-09 18:54:04 -08:00
type,
2023-03-14 03:50:42 -07:00
}: {
2023-11-09 18:54:04 -08:00
data: PnlLeaderboardRes[] | EquityLeaderboardRes[]
2023-03-14 03:50:42 -07:00
loading: boolean
2023-11-09 18:54:04 -08:00
type: string
2023-03-14 03:50:42 -07:00
}) => {
2023-03-06 00:59:14 -08:00
return (
<>
<div className="space-y-2">
2023-03-14 03:50:42 -07:00
{data.map((d, i) => (
<LeaderboardRow
item={d}
loading={loading}
2023-03-26 05:18:40 -07:00
rank={i + 1}
2023-11-09 18:54:04 -08:00
key={d.mango_account + i}
type={type}
2023-03-14 03:50:42 -07:00
/>
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,
2023-11-09 18:54:04 -08:00
type,
2023-03-14 03:50:42 -07:00
}: {
2023-11-09 18:54:04 -08:00
item: PnlLeaderboardRes | EquityLeaderboardRes
2023-03-26 05:18:40 -07:00
loading?: boolean
2023-03-06 00:59:14 -08:00
rank: number
2023-11-09 18:54:04 -08:00
type: string
2023-03-14 03:50:42 -07:00
}) => {
2023-11-09 18:54:04 -08:00
const { profile_name, profile_image_url, mango_account, wallet_pk } = item
const value =
type === 'pnl' && isPnlLeaderboard(item)
? item.pnl
: isEquityLeaderboard(item)
? item.account_equity
: 0
2023-08-31 20:22:50 -07:00
const { isTablet } = useViewport()
2023-03-06 00:59:14 -08:00
2023-03-14 03:50:42 -07:00
return !loading ? (
2023-11-13 20:41:16 -08:00
<div className="flex">
<div className="flex flex-1 items-center rounded-l-md bg-th-bkg-2 px-3">
2023-11-14 02:39:37 -08:00
<ToggleFollowButton accountPk={mango_account} />
2023-11-13 20:41:16 -08:00
</div>
<a
className="flex w-full items-center justify-between rounded-md rounded-l-none border border-l-0 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"
>
<div className="flex items-center space-x-3">
<div
className={`relative flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full ${
rank < 4 ? '' : 'bg-th-bkg-3'
} md:mr-2`}
2023-03-06 00:59:14 -08:00
>
2023-11-13 20:41:16 -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" rank={rank} /> : null}
</div>
<ProfileImage
imageSize={isTablet ? '32' : '40'}
imageUrl={profile_image_url}
placeholderSize={isTablet ? '20' : '24'}
/>
<div className="text-left">
<p className="capitalize text-th-fgd-2 md:text-base">
{profile_name ||
wallet_pk.slice(0, 4) + '...' + wallet_pk.slice(-4)}
</p>
<p className="text-xs text-th-fgd-4">
Acc: {mango_account.slice(0, 4) + '...' + mango_account.slice(-4)}
</p>
</div>
2023-03-06 00:59:14 -08:00
</div>
2023-11-13 20:41:16 -08:00
<div className="flex items-center">
<span className="mr-3 text-right font-mono md:text-base">
{formatCurrencyValue(value, 2)}
</span>
<ChevronRightIcon className="h-5 w-5 text-th-fgd-3" />
2023-03-06 00:59:14 -08:00
</div>
2023-11-13 20:41:16 -08:00
</a>
</div>
2023-03-14 03:50:42 -07:00
) : (
<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
)
}