fix rewards banner display and show prev season points before claim
This commit is contained in:
parent
4cc2ab5df8
commit
3b3344039e
|
@ -193,7 +193,7 @@ const TopBar = () => {
|
|||
<ArrowRightIcon className="sideways-bounce ml-2 h-5 w-5 text-th-fgd-1" />
|
||||
</span>
|
||||
)
|
||||
) : isWhiteListed ? (
|
||||
) : isWhiteListed && mangoAccountAddress ? (
|
||||
<Link href="/rewards" shallow={true}>
|
||||
<div className="flex h-[63px] items-center justify-between border-x border-th-bkg-3 bg-th-bkg-1 px-4 md:border-l-0">
|
||||
{accountPointsAndRank?.rank ? (
|
||||
|
|
|
@ -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 ? (
|
||||
<BannerContent
|
||||
text={`Claiming season ${prevSeasonId} rewards ends ${
|
||||
|
|
|
@ -38,7 +38,7 @@ export const useAccountPointsAndRank = (
|
|||
seasonId: number | undefined,
|
||||
) => {
|
||||
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) {
|
||||
try {
|
||||
const toClaim = distributionData?.getClaims(walletPk).length
|
||||
const claimed = (await distributionData?.getClaimed(walletPk))?.filter(
|
||||
(x) => !x.equals(PublicKey.default),
|
||||
)?.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 }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue