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 ? ( + + ) : loadingAccountPointsAndRank ? ( + +
+ + ) : null}
Points - {!loadingWalletRewardsData ? ( + {!loadingAccountPointsAndRank ? (

- {walletPoints ? ( - + {accountPointsAndRank?.total_points ? ( + ) : wallet?.adapter.publicKey ? ( 0 ) : ( diff --git a/hooks/notifications/useNotificationSocket.ts b/hooks/notifications/useNotificationSocket.ts index 0bd38816..44ee7bc2 100644 --- a/hooks/notifications/useNotificationSocket.ts +++ b/hooks/notifications/useNotificationSocket.ts @@ -8,18 +8,16 @@ import { Notification } from 'apis/notifications/notifications' import { tryParse } from 'utils/formatting' import { NotificationsWebSocket } from 'apis/notifications/websocket' import useMangoAccount from 'hooks/useMangoAccount' -import { useCurrentSeason, useWalletPoints } from 'hooks/useRewards' +import { useAccountPointsAndRank, useCurrentSeason } from 'hooks/useRewards' export function useNotificationSocket() { const isAuth = useIsAuthorized() const { publicKey } = useWallet() const { mangoAccountAddress } = useMangoAccount() - const { wallet } = useWallet() const { data: seasonData } = useCurrentSeason() - const { refetch } = useWalletPoints( + const { refetch } = useAccountPointsAndRank( mangoAccountAddress, seasonData?.season_id, - wallet, ) const token = NotificationCookieStore((s) => s.currentToken) diff --git a/hooks/useRewards.ts b/hooks/useRewards.ts index bce4ca8e..8a862a3d 100644 --- a/hooks/useRewards.ts +++ b/hooks/useRewards.ts @@ -1,4 +1,3 @@ -import { Wallet } from '@solana/wallet-adapter-react' import { PublicKey } from '@solana/web3.js' import mangoStore from '@store/mangoStore' import { useQuery } from '@tanstack/react-query' @@ -8,7 +7,6 @@ import { fetchCurrentSeason, fetchDistribution, fetchLeaderboard, - fetchRewardsPoints, } from 'apis/rewards' import { useEffect, useState } from 'react' @@ -65,24 +63,6 @@ export const useDistribution = (seasonId: number | undefined) => { ) } -export const useWalletPoints = ( - mangoAccountAddress: string, - season_id: number | undefined, - wallet: Wallet | null, -) => { - return useQuery( - ['rewards-points', mangoAccountAddress, season_id], - () => fetchRewardsPoints(mangoAccountAddress, season_id!), - { - cacheTime: 1000 * 60 * 10, - staleTime: 1000 * 60, - retry: 3, - refetchOnWindowFocus: false, - enabled: !!(wallet?.adapter && mangoAccountAddress), - }, - ) -} - export const useTopAccountsLeaderBoard = (season_id: number | undefined) => { return useQuery( ['top-accounts-leaderboard-data'],