diff --git a/apis/rewards.ts b/apis/rewards.ts index 3ebbd5c2..084995f2 100644 --- a/apis/rewards.ts +++ b/apis/rewards.ts @@ -34,22 +34,6 @@ type LeaderboardItem = { tier: string } -export const fetchRewardsPoints = async ( - mangoAccountPk: string, - seasonId: number, -) => { - try { - const data = await fetch( - `${MANGO_DATA_API_URL}/seasons/season-total-points-account?mango-account=${mangoAccountPk}&seasons-id=${seasonId}`, - ) - const res = await data.json() - return res?.total_points || 0 - } catch (e) { - console.log('Failed to fetch points', e) - return 0 - } -} - export const fetchDistribution = async (provider: Provider, season: number) => { try { const client = new MangoMintsRedemptionClient(provider as AnchorProvider) diff --git a/components/TopBar.tsx b/components/TopBar.tsx index 0abccf44..244517b9 100644 --- a/components/TopBar.tsx +++ b/components/TopBar.tsx @@ -30,13 +30,14 @@ import { IS_ONBOARDED_KEY } from 'utils/constants' import useLocalStorageState from 'hooks/useLocalStorageState' import SettingsModal from './modals/SettingsModal' import DepositWithdrawIcon from './icons/DepositWithdrawIcon' -import { useCurrentSeason, useWalletPoints } from 'hooks/useRewards' +import { useAccountPointsAndRank, useCurrentSeason } from 'hooks/useRewards' import SheenLoader from './shared/SheenLoader' import Link from 'next/link' import { useIsWhiteListed } from 'hooks/useIsWhiteListed' import FormatNumericValue from './shared/FormatNumericValue' import { useRouter } from 'next/router' import TopBarStore from '@store/topBarStore' +import MedalIcon from './icons/MedalIcon' export const TOPBAR_ICON_BUTTON_CLASSES = 'relative flex h-16 w-10 sm:w-16 items-center justify-center sm:border-l sm:border-th-bkg-3 focus-visible:bg-th-bkg-3 md:hover:bg-th-bkg-2' @@ -49,10 +50,10 @@ const TopBar = () => { const { connected, wallet } = useWallet() const { data: seasonData } = useCurrentSeason() const { - data: walletPoints, - isLoading: loadingWalletRewardsData, - refetch: refetchWalletPoints, - } = useWalletPoints(mangoAccountAddress, seasonData?.season_id, wallet) + data: accountPointsAndRank, + isInitialLoading: loadingAccountPointsAndRank, + refetch: refetchPoints, + } = useAccountPointsAndRank(mangoAccountAddress, seasonData?.season_id) const { data: isWhiteListed } = useIsWhiteListed() const router = useRouter() const themeData = mangoStore((s) => s.themeData) @@ -102,7 +103,7 @@ const TopBar = () => { useEffect(() => { if (router.pathname === '/rewards') { - refetchWalletPoints() + refetchPoints() } }, [router]) @@ -184,15 +185,45 @@ const TopBar = () => { ) ) : isWhiteListed ? ( -
+ {accountPointsAndRank.rank} +
+ {accountPointsAndRank.rank < 4 ? ( +
- {walletPoints ? (
-