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" />
|
<ArrowRightIcon className="sideways-bounce ml-2 h-5 w-5 text-th-fgd-1" />
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
) : isWhiteListed ? (
|
) : isWhiteListed && mangoAccountAddress ? (
|
||||||
<Link href="/rewards" shallow={true}>
|
<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">
|
<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 ? (
|
{accountPointsAndRank?.rank ? (
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { MANGO_MINTS_BANNER_KEY } from 'utils/constants'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||||
import { useWallet } from '@solana/wallet-adapter-react'
|
import { useWallet } from '@solana/wallet-adapter-react'
|
||||||
|
import useMangoAccount from 'hooks/useMangoAccount'
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime)
|
||||||
|
|
||||||
const BANNER_WRAPPER_CLASSES =
|
const BANNER_WRAPPER_CLASSES =
|
||||||
|
@ -29,12 +30,16 @@ const PromoBanner = () => {
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
const { publicKey } = useWallet()
|
const { publicKey } = useWallet()
|
||||||
|
const { mangoAccountAddress } = useMangoAccount()
|
||||||
const { data: isWhiteListed } = useIsWhiteListed()
|
const { data: isWhiteListed } = useIsWhiteListed()
|
||||||
const { data: seasonData } = useCurrentSeason()
|
const { data: seasonData } = useCurrentSeason()
|
||||||
const currentSeasonId = seasonData ? seasonData.season_id : undefined
|
const currentSeasonId = seasonData ? seasonData.season_id : undefined
|
||||||
const prevSeasonId = currentSeasonId ? currentSeasonId - 1 : undefined
|
const prevSeasonId = currentSeasonId ? currentSeasonId - 1 : undefined
|
||||||
const { data: distributionDataAndClient } = useDistribution(prevSeasonId)
|
const { data: distributionDataAndClient } = useDistribution(prevSeasonId)
|
||||||
const { showClaim } = useIsAllClaimed(prevSeasonId, publicKey)
|
const { showClaim, loading: loadingClaimed } = useIsAllClaimed(
|
||||||
|
prevSeasonId,
|
||||||
|
publicKey,
|
||||||
|
)
|
||||||
|
|
||||||
const hasClosedBanner = useMemo(() => {
|
const hasClosedBanner = useMemo(() => {
|
||||||
if (!seasonData?.season_id) return false
|
if (!seasonData?.season_id) return false
|
||||||
|
@ -54,7 +59,10 @@ const PromoBanner = () => {
|
||||||
)
|
)
|
||||||
}, [distributionDataAndClient])
|
}, [distributionDataAndClient])
|
||||||
|
|
||||||
return currentSeasonId && isWhiteListed ? (
|
return currentSeasonId &&
|
||||||
|
isWhiteListed &&
|
||||||
|
!loadingClaimed &&
|
||||||
|
mangoAccountAddress ? (
|
||||||
showClaim ? (
|
showClaim ? (
|
||||||
<BannerContent
|
<BannerContent
|
||||||
text={`Claiming season ${prevSeasonId} rewards ends ${
|
text={`Claiming season ${prevSeasonId} rewards ends ${
|
||||||
|
|
|
@ -38,7 +38,7 @@ export const useAccountPointsAndRank = (
|
||||||
seasonId: number | undefined,
|
seasonId: number | undefined,
|
||||||
) => {
|
) => {
|
||||||
return useQuery(
|
return useQuery(
|
||||||
['account-rank', mangoAccount],
|
['account-rank', mangoAccount, seasonId],
|
||||||
() => fetchAccountPointsAndRank(mangoAccount, seasonId!),
|
() => fetchAccountPointsAndRank(mangoAccount, seasonId!),
|
||||||
{
|
{
|
||||||
cacheTime: 1000 * 60 * 10,
|
cacheTime: 1000 * 60 * 10,
|
||||||
|
@ -82,19 +82,25 @@ export const useIsAllClaimed = (
|
||||||
walletPk: PublicKey | null,
|
walletPk: PublicKey | null,
|
||||||
) => {
|
) => {
|
||||||
const [isAllClaimed, setIsAllCliamed] = useState(true)
|
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 { data: distributionDataAndClient } = useDistribution(prevSeason)
|
||||||
const distributionData = distributionDataAndClient?.distribution
|
const distributionData = distributionDataAndClient?.distribution
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleGetIsAllClaimed = async () => {
|
const handleGetIsAllClaimed = async () => {
|
||||||
if (walletPk) {
|
if (walletPk) {
|
||||||
const toClaim = distributionData?.getClaims(walletPk).length
|
try {
|
||||||
const claimed = (await distributionData?.getClaimed(walletPk))?.filter(
|
const toClaim = distributionData?.getClaims(walletPk).length
|
||||||
(x) => !x.equals(PublicKey.default),
|
const claimed = (
|
||||||
)?.length
|
await distributionData?.getClaimed(walletPk)
|
||||||
|
)?.filter((x) => !x.equals(PublicKey.default))?.length
|
||||||
setIsAllCliamed(!toClaim || toClaim === claimed)
|
setLoading(false)
|
||||||
|
setIsAllCliamed(!toClaim || toClaim === claimed)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('failed to check claimed rewards', e)
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setIsAllCliamed(false)
|
setIsAllCliamed(false)
|
||||||
}
|
}
|
||||||
|
@ -112,9 +118,7 @@ export const useIsAllClaimed = (
|
||||||
!isAllClaimed
|
!isAllClaimed
|
||||||
|
|
||||||
setShowClaim(isClaimActive)
|
setShowClaim(isClaimActive)
|
||||||
} else {
|
|
||||||
setShowClaim(false)
|
|
||||||
}
|
}
|
||||||
}, [distributionData, walletPk, isAllClaimed])
|
}, [distributionData, walletPk, isAllClaimed])
|
||||||
return { isAllClaimed, showClaim }
|
return { isAllClaimed, showClaim, loading }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue