diff --git a/apis/whitelist.ts b/apis/whitelist.ts new file mode 100644 index 00000000..36ee2e1f --- /dev/null +++ b/apis/whitelist.ts @@ -0,0 +1,14 @@ +import { WHITE_LIST_API } from 'utils/constants' + +export type WhiteListedResp = { + found: boolean +} + +export const fetchIsWhiteListed = async (wallet: string) => { + const data = await fetch(`${WHITE_LIST_API}isWhiteListed?wallet=${wallet}`) + const body = await data.json() + if (body.error) { + throw { error: body.error, status: data.status } + } + return body.found +} diff --git a/components/rewards/RewardsPage.tsx b/components/rewards/RewardsPage.tsx index 9e7040a2..17168b38 100644 --- a/components/rewards/RewardsPage.tsx +++ b/components/rewards/RewardsPage.tsx @@ -7,6 +7,7 @@ import Button, { LinkButton } from '@components/shared/Button' import Modal from '@components/shared/Modal' import { Disclosure } from '@headlessui/react' import { + CheckIcon, ChevronDownIcon, ChevronRightIcon, ClockIcon, @@ -25,6 +26,8 @@ import SheenLoader from '@components/shared/SheenLoader' import { abbreviateAddress } from 'utils/formatting' import { PublicKey } from '@solana/web3.js' import { useTranslation } from 'next-i18next' +import { useIsWhiteListed } from 'hooks/useIsWhiteListed' +import { XMarkIcon } from '@heroicons/react/24/outline' export type RewardsLeaderboardItem = { points: number @@ -147,7 +150,7 @@ const Season = ({ const { t } = useTranslation(['common', 'rewards']) const { wallet } = useWallet() const [topAccountsTier, setTopAccountsTier] = useState('seed') - + const { data: isWhiteListed } = useIsWhiteListed() const { data: walletRewardsData, isFetching: fetchingWalletRewardsData, @@ -197,7 +200,15 @@ const Season = ({

Season 1 starts in:{' '} - 4 days + 4 days +

+ User whitelisted -{' '} + {isWhiteListed ? ( + + ) : ( + + )} +

diff --git a/hooks/useIsWhiteListed.ts b/hooks/useIsWhiteListed.ts new file mode 100644 index 00000000..ba22a057 --- /dev/null +++ b/hooks/useIsWhiteListed.ts @@ -0,0 +1,22 @@ +import { useQuery } from '@tanstack/react-query' +import { useWallet } from '@solana/wallet-adapter-react' +import { fetchIsWhiteListed } from 'apis/whitelist' + +const refetchMs = 24 * 60 * 60 * 1000 + +export function useIsWhiteListed() { + const { publicKey } = useWallet() + const walletPubKey = publicKey?.toBase58() + const criteria = walletPubKey + + return useQuery( + ['isWhiteListed', criteria], + () => fetchIsWhiteListed(walletPubKey!), + { + enabled: !!walletPubKey, + staleTime: refetchMs, + retry: 1, + refetchInterval: refetchMs, + } + ) +} diff --git a/utils/constants.ts b/utils/constants.ts index 36fb3960..334fc3ff 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -97,6 +97,7 @@ export const JUPITER_API_DEVNET = 'https://api.jup.ag/api/tokens/devnet' export const JUPITER_PRICE_API_MAINNET = 'https://price.jup.ag/v4/' export const NOTIFICATION_API = 'https://notifications-api.herokuapp.com/' + export const NOTIFICATION_API_WEBSOCKET = 'wss://notifications-api.herokuapp.com/ws' @@ -122,3 +123,5 @@ export const CUSTOM_TOKEN_ICONS: { [key: string]: boolean } = { usdt: true, 'wbtc (portal)': true, } + +export const WHITE_LIST_API = 'https://api.mngo.cloud/whitelist/v1/'