From 6f4a44cc1752d16ed7ccb3b25e9b43fd24bd77c0 Mon Sep 17 00:00:00 2001 From: corlard3y Date: Fri, 22 Nov 2024 22:14:28 +0100 Subject: [PATCH] update reset fn --- .../rewards/components/ActivityButton.tsx | 35 ++++++++++++++++--- .../StakePushActivitiesListItem.tsx | 2 +- .../hooks/useStakeRewardsResetTime.tsx | 6 ++-- src/queries/hooks/rewards/index.ts | 1 + .../rewards/useGetPreviousPushStakeEpoch.ts | 9 +++++ .../rewards/getPreviousPushStakeEpochModel.ts | 3 ++ src/queries/models/rewards/index.ts | 1 + src/queries/queryKeys.ts | 1 + .../rewards/getPreviousPushStakeEpoch.ts | 10 ++++++ src/queries/services/rewards/index.ts | 1 + src/queries/types/rewards.ts | 5 ++- 11 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 src/queries/hooks/rewards/useGetPreviousPushStakeEpoch.ts create mode 100644 src/queries/models/rewards/getPreviousPushStakeEpochModel.ts create mode 100644 src/queries/services/rewards/getPreviousPushStakeEpoch.ts 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/hooks/useStakeRewardsResetTime.tsx b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx index 74cc6d5750..c61813fdfd 100644 --- a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx +++ b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx @@ -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 ( 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 338dcfb708..79924d6067 100644 --- a/src/queries/types/rewards.ts +++ b/src/queries/types/rewards.ts @@ -92,7 +92,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;