diff --git a/components/TopBar.tsx b/components/TopBar.tsx index 3b6de14b..fa0822c1 100644 --- a/components/TopBar.tsx +++ b/components/TopBar.tsx @@ -193,7 +193,7 @@ const TopBar = () => { ) - ) : isWhiteListed ? ( + ) : isWhiteListed && mangoAccountAddress ? (
{accountPointsAndRank?.rank ? ( diff --git a/components/rewards/PromoBanner.tsx b/components/rewards/PromoBanner.tsx index ea21ca9d..f8537d7d 100644 --- a/components/rewards/PromoBanner.tsx +++ b/components/rewards/PromoBanner.tsx @@ -13,6 +13,7 @@ import { MANGO_MINTS_BANNER_KEY } from 'utils/constants' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import { useWallet } from '@solana/wallet-adapter-react' +import useMangoAccount from 'hooks/useMangoAccount' dayjs.extend(relativeTime) const BANNER_WRAPPER_CLASSES = @@ -29,12 +30,16 @@ const PromoBanner = () => { {}, ) const { publicKey } = useWallet() + const { mangoAccountAddress } = useMangoAccount() const { data: isWhiteListed } = useIsWhiteListed() const { data: seasonData } = useCurrentSeason() const currentSeasonId = seasonData ? seasonData.season_id : undefined const prevSeasonId = currentSeasonId ? currentSeasonId - 1 : undefined const { data: distributionDataAndClient } = useDistribution(prevSeasonId) - const { showClaim } = useIsAllClaimed(prevSeasonId, publicKey) + const { showClaim, loading: loadingClaimed } = useIsAllClaimed( + prevSeasonId, + publicKey, + ) const hasClosedBanner = useMemo(() => { if (!seasonData?.season_id) return false @@ -54,7 +59,10 @@ const PromoBanner = () => { ) }, [distributionDataAndClient]) - return currentSeasonId && isWhiteListed ? ( + return currentSeasonId && + isWhiteListed && + !loadingClaimed && + mangoAccountAddress ? ( showClaim ? ( { return useQuery( - ['account-rank', mangoAccount], + ['account-rank', mangoAccount, seasonId], () => fetchAccountPointsAndRank(mangoAccount, seasonId!), { cacheTime: 1000 * 60 * 10, @@ -82,19 +82,25 @@ export const useIsAllClaimed = ( walletPk: PublicKey | null, ) => { const [isAllClaimed, setIsAllCliamed] = useState(true) - const [showClaim, setShowClaim] = useState(false) + const [showClaim, setShowClaim] = useState(true) + const [loading, setLoading] = useState(true) const { data: distributionDataAndClient } = useDistribution(prevSeason) const distributionData = distributionDataAndClient?.distribution useEffect(() => { const handleGetIsAllClaimed = async () => { if (walletPk) { - const toClaim = distributionData?.getClaims(walletPk).length - const claimed = (await distributionData?.getClaimed(walletPk))?.filter( - (x) => !x.equals(PublicKey.default), - )?.length - - setIsAllCliamed(!toClaim || toClaim === claimed) + try { + const toClaim = distributionData?.getClaims(walletPk).length + const claimed = ( + await distributionData?.getClaimed(walletPk) + )?.filter((x) => !x.equals(PublicKey.default))?.length + setLoading(false) + setIsAllCliamed(!toClaim || toClaim === claimed) + } catch (e) { + console.log('failed to check claimed rewards', e) + setLoading(false) + } } else { setIsAllCliamed(false) } @@ -112,9 +118,7 @@ export const useIsAllClaimed = ( !isAllClaimed setShowClaim(isClaimActive) - } else { - setShowClaim(false) } }, [distributionData, walletPk, isAllClaimed]) - return { isAllClaimed, showClaim } + return { isAllClaimed, showClaim, loading } }