diff --git a/src/modules/rewards/components/ActivityButton.tsx b/src/modules/rewards/components/ActivityButton.tsx index 684fa37e3d..482b392b1f 100644 --- a/src/modules/rewards/components/ActivityButton.tsx +++ b/src/modules/rewards/components/ActivityButton.tsx @@ -2,7 +2,7 @@ import { FC } from 'react'; //Queries -import { ActvityType, UsersActivity } from 'queries'; +import { ActvityType, useGetPushStakeEpoch, useGetUniV2StakeEpoch, UsersActivity } from 'queries'; import { Button } from 'blocks'; import { ActivityVerificationButton } from './ActivityVerificationButton'; import { useRewardsContext } from 'contexts/RewardsContext'; @@ -31,14 +31,39 @@ const ActivityButton: FC = ({ usersSingleActivity, isLoadingActivity, label, - isStakeSection, - lifeTime, }) => { const { resetEpoch } = useRewardsContext(); + const { data: pushStakeData } = useGetPushStakeEpoch(); + const { data: uniV2StakeData } = useGetUniV2StakeEpoch(); + const isPushEpochRelated = + typeof usersSingleActivity?.activityTypeId === 'string' && + usersSingleActivity.activityTypeId.endsWith('push_epoch'); - if (usersSingleActivity?.status === 'COMPLETED' && isStakeSection && resetEpoch && !lifeTime) { + const isUniV2EpochRelated = + typeof usersSingleActivity?.activityTypeId === 'string' && usersSingleActivity.activityTypeId.endsWith('v2_epoch'); + + const isEpochRelated = + usersSingleActivity?.data?.currentEpoch == pushStakeData?.currentEpoch || + usersSingleActivity?.data?.currentEpoch == uniV2StakeData?.currentEpoch; + + // claimed status for the same epoch + if (usersSingleActivity?.status === 'COMPLETED' && (isPushEpochRelated || isUniV2EpochRelated) && isEpochRelated) { + console.log('claimed in this epoch button'); + return ( + + ); + } + + // default verify button for stake epoch section + if (usersSingleActivity?.status === 'COMPLETED' && resetEpoch && (isPushEpochRelated || isUniV2EpochRelated)) { + console.log('reset button'); return ( - // default verify button = ({ const usersSingleActivity = allUsersActivity?.[activity?.activityType] as UsersActivity; const isLoading = isAllActivitiesLoading; - const hasActivityEndedUnclaimed = usersSingleActivity?.status !== 'COMPLETED' && hasEpochEnded; + const hasActivityEndedUnclaimed = hasEpochEnded; const isLockedOrNotConnected = isLocked || !isWalletConnected; diff --git a/src/modules/rewards/components/StakePushSection.tsx b/src/modules/rewards/components/StakePushSection.tsx index 10cae3ed15..f3e6062b4e 100644 --- a/src/modules/rewards/components/StakePushSection.tsx +++ b/src/modules/rewards/components/StakePushSection.tsx @@ -25,7 +25,7 @@ export type StakePushPoints = { const StakePushSection: FC = ({ title, subtitle, timeline, lifeTime }) => { const { account, isWalletConnected } = useAccount(); const { isLocked } = useRewardsContext(); - const { stakePushArray, uniV2PushArray, isLoading, daysToReset } = useStakeRewardsResetTime({ + const { stakePushArray, uniV2PushArray, isLoading, daysToReset, refetchSendActivities } = useStakeRewardsResetTime({ lifeTime, }); const [errorMessage, setErrorMessage] = useState(''); @@ -184,7 +184,10 @@ const StakePushSection: FC = ({ title, subtitle, timeline, life hasEpochEnded={hasEpochEnded} allUsersActivity={allUsersActivity as StakeActivityResponse} isAllActivitiesLoading={isAllActivitiesLoading} - refetchActivity={refetchActivity} + refetchActivity={() => { + refetchActivity(); + refetchSendActivities(); + }} lifeTime={lifeTime} /> ))} diff --git a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx index 74cc6d5750..6e789562b2 100644 --- a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx +++ b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx @@ -65,7 +65,7 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => { const activityTitles = allPushArray?.map((activity) => activity.activityType); - const { data: sendRecentActivities } = useGetRewardActivityStatus( + const { data: sendRecentActivities, refetch: refetchSendActivities } = useGetRewardActivityStatus( { userId: userDetails?.userId as string, activities: activityTitles as string[], @@ -80,6 +80,7 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => { const differenceInSeconds = (resetDate as number) - currentTime; return Math.floor(differenceInSeconds / (60 * 60 * 24)); }, [resetDate]); + // const daysToReset = -2; // Helper function to check if 7 days have passed since the stored epoch time (in seconds) const hasSevenDaysPassed = (storedEpochTime: number) => { @@ -126,7 +127,8 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => { updateResetDate(latestTimestamp); } - if (!isEpochActive && isPastSevenDays) { + if (!isEpochActive) { + // if (!isEpochActive && isPastSevenDays) { setResetEpoch(true); console.log(`${stakeType} epoch is reset`); } else { @@ -135,8 +137,6 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => { } }; - // console.log(daysToReset, 'daysToReset'); - // Effect for handling fetch data for both arrays useEffect(() => { if ( @@ -154,7 +154,7 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => { } }, [userDetails?.userId, isWalletConnected, isLoadingPushStakeData, isLoadingPushUniData, sendRecentActivities]); - return { stakePushArray, uniV2PushArray, isLoading, daysToReset }; + return { stakePushArray, uniV2PushArray, isLoading, daysToReset, refetchSendActivities }; }; export { useStakeRewardsResetTime }; diff --git a/src/queries/hooks/rewards/index.ts b/src/queries/hooks/rewards/index.ts index ee6ba806a3..7609e40628 100644 --- a/src/queries/hooks/rewards/index.ts +++ b/src/queries/hooks/rewards/index.ts @@ -7,4 +7,5 @@ export * from './useCreateRewardsUser'; export * from './useGetRewardsLedearboard'; export * from './useGetRewardActivityStatus'; export * from './useGetPushStakeEpoch'; +export * from './useGetPreviousPushStakeEpoch'; export * from './useGetUniV2StakeEpoch'; diff --git a/src/queries/hooks/rewards/useGetPreviousPushStakeEpoch.ts b/src/queries/hooks/rewards/useGetPreviousPushStakeEpoch.ts new file mode 100644 index 0000000000..0b1114130e --- /dev/null +++ b/src/queries/hooks/rewards/useGetPreviousPushStakeEpoch.ts @@ -0,0 +1,9 @@ +import { useQuery } from '@tanstack/react-query'; +import { getPreviousPushStakeEpoch } from 'queries'; +import { pushPreviousStakeEpoch } from 'queries/queryKeys'; + +export const useGetPreviousPushStakeEpoch = () => + useQuery({ + queryKey: [pushPreviousStakeEpoch], + queryFn: getPreviousPushStakeEpoch, + }); diff --git a/src/queries/models/rewards/getPreviousPushStakeEpochModel.ts b/src/queries/models/rewards/getPreviousPushStakeEpochModel.ts new file mode 100644 index 0000000000..0184e1d452 --- /dev/null +++ b/src/queries/models/rewards/getPreviousPushStakeEpochModel.ts @@ -0,0 +1,3 @@ +import { RewardsStakeParams } from 'queries/types'; + +export const getPreviousPushStakeEpochModel = (response: RewardsStakeParams): RewardsStakeParams => response; diff --git a/src/queries/models/rewards/index.ts b/src/queries/models/rewards/index.ts index cb8c48e292..f6d00ceca4 100644 --- a/src/queries/models/rewards/index.ts +++ b/src/queries/models/rewards/index.ts @@ -7,4 +7,5 @@ export * from './createUserRewardsDetailsModel'; export * from './getRewardsLeaderboardModalCreator'; export * from './getRewardActivityStatusModel'; export * from './getPushStakeEpochModel'; +export * from './getPreviousPushStakeEpochModel'; export * from './getUniV2StakeEpochModel'; diff --git a/src/queries/queryKeys.ts b/src/queries/queryKeys.ts index c9b8fab717..b105f97615 100644 --- a/src/queries/queryKeys.ts +++ b/src/queries/queryKeys.ts @@ -25,6 +25,7 @@ export const pointsVaultPendingUsers = 'pointsVaultPendingUsers'; export const pointsVaultRejectedUsers = 'pointsVaultRejectedUsers'; export const pointsVaultSearch = 'pointsVaultSearch'; export const pointsVaultUserLoginKey = 'pointsVaultUserLogin'; +export const pushPreviousStakeEpoch = 'pushPreviousStakeEpoch'; export const pushStakeEpoch = 'pushStakeEpoch'; export const reactivatingChannel = 'reactivatingChannel'; export const rejectVaultUser = 'rejectVaultUser'; diff --git a/src/queries/services/rewards/getPreviousPushStakeEpoch.ts b/src/queries/services/rewards/getPreviousPushStakeEpoch.ts new file mode 100644 index 0000000000..45d6f69045 --- /dev/null +++ b/src/queries/services/rewards/getPreviousPushStakeEpoch.ts @@ -0,0 +1,10 @@ +import axios from 'axios'; + +import { getRewardsBaseURL } from '../../baseURL'; +import { getPreviousPushStakeEpochModel } from 'queries/models'; + +export const getPreviousPushStakeEpoch = () => + axios({ + method: 'GET', + url: `${getRewardsBaseURL()}/staking/push/previous-epoch-blocks`, + }).then((response) => getPreviousPushStakeEpochModel(response.data)); diff --git a/src/queries/services/rewards/index.ts b/src/queries/services/rewards/index.ts index 85434d4bd6..61f7d46820 100644 --- a/src/queries/services/rewards/index.ts +++ b/src/queries/services/rewards/index.ts @@ -7,4 +7,5 @@ export * from './createUserRewardsDetail.ts'; export * from './getRewardsLeaderboard'; export * from './getRewardActivityStatus.ts'; export * from './getPushStakeEpoch.ts'; +export * from './getPreviousPushStakeEpoch.ts'; export * from './getUniV2StakeEpoch.ts'; diff --git a/src/queries/types/rewards.ts b/src/queries/types/rewards.ts index f1b057203b..a6934334ab 100644 --- a/src/queries/types/rewards.ts +++ b/src/queries/types/rewards.ts @@ -93,7 +93,10 @@ export type UsersActivity = { activityId: string; userId: string; activityTypeId: string; - data: { twitter?: string; discord?: string }; + data: + | { twitter?: string; discord?: string } + | { currentEpoch?: number; fromBlock?: number; toBlock?: number; fromTimestamp?: number; toTimestamp?: number } + | any; status: 'COMPLETED' | 'PENDING' | 'REJECTED'; points: number; multiplier: number;