From bbbf562d2a2c00dfb801619c313dcd3d4f3f5983 Mon Sep 17 00:00:00 2001 From: corlard3y Date: Wed, 16 Oct 2024 23:23:46 +0100 Subject: [PATCH 1/6] update stake reset --- .../rewards/components/StakePushSection.tsx | 2 +- .../hooks/useStakeRewardsResetTime.tsx | 52 +++++++++++-------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/modules/rewards/components/StakePushSection.tsx b/src/modules/rewards/components/StakePushSection.tsx index f2a6a0e9ea..d7c4692c9b 100644 --- a/src/modules/rewards/components/StakePushSection.tsx +++ b/src/modules/rewards/components/StakePushSection.tsx @@ -36,7 +36,7 @@ const StakePushSection: FC = ({ title, subtitle, timeline, mult caip10WalletAddress: caip10WalletAddress, }); - const activityResetDate = daysToReset + 7; + const activityResetDate = (daysToReset as number) + 7; const isEpochStatusActive = useMemo(() => { return daysToReset != null && !multiplier && daysToReset >= 0 && activityResetDate > 7 && isWalletConnected; diff --git a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx index bef46eda6c..fe3f296006 100644 --- a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx +++ b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx @@ -65,15 +65,9 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { ); }, [rewardActivitiesResponse]); - // const allUniV2Array = useMemo(() => { - // return filterAndSortAllActivities( - // 'multiplier-uni', - // 'point-uni', - // rewardActivitiesResponse?.activities.flatMap((page) => page) || [] - // ); - // }, [rewardActivitiesResponse]); - const daysToReset = useMemo(() => { + if (resetDate == null || resetDate == undefined) return; + const currentTime = Date.now() / 1000; // Current time in seconds const differenceInSeconds = (resetDate as number) - currentTime; return Math.floor(differenceInSeconds / (60 * 60 * 24)); @@ -83,9 +77,9 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { const hasSevenDaysPassed = (storedEpochTime: number) => { const currentTime = Math.floor(Date.now() / 1000); // Current time in epoch seconds const sevenDays = 7; // 7 days - const differenceInSeconds = Math.floor((currentTime - storedEpochTime) / (60 * 60 * 24)); + const differenceInDays = Math.floor((currentTime - storedEpochTime) / (60 * 60 * 24)); - return differenceInSeconds > sevenDays; // Return true if 7 days or more have passed since the stored epoch time + return differenceInDays >= sevenDays; // Return true if 7 days or more have passed since the stored epoch time }; // Function to handle fetch and timestamp/epoch comparison @@ -95,17 +89,6 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { return; } - const latestPushTimestamp = pushStakeData?.toTimestamp; - // const latestUniV2Timestamp = uniV2StakeData.toTimestamp; - const resetStakeEndDate = localStorage.getItem(CommonLocalStorageKeys.resetStakeEndDate); - - // confirm: push timestamp matches yield farming - const laterTimestamp = latestPushTimestamp; - - if (!resetStakeEndDate || hasSevenDaysPassed(Number(laterTimestamp))) { - localStorage.setItem(CommonLocalStorageKeys.resetStakeEndDate, laterTimestamp.toString()); - } - setResetDate(laterTimestamp); // Call the appropriate fetch function based on the later timestamp handleFetchData(allPushArray, 'push'); }; @@ -135,10 +118,31 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { const { latestActivityKey } = getActivityStatus(dataActivity); const mostRecentStakeActivity = dataActivity?.[latestActivityKey]; const stakeData = stakeType === 'push' ? pushStakeData : uniV2StakeData; - const toTimestamp = stakeData?.toTimestamp as number; + const toTimestamp = mostRecentStakeActivity?.data?.toTimestamp as number; + const latestTimestamp = pushStakeData?.toTimestamp as number; const isEpochActive = mostRecentStakeActivity?.data?.currentEpoch === stakeData?.currentEpoch; - const isPastSevenDays = hasSevenDaysPassed(Number(toTimestamp)); + const resetStakeEndDate = localStorage.getItem(CommonLocalStorageKeys.resetStakeEndDate); + + // Check if it's been seven days based on the appropriate timestamp + const isPastSevenDays = + toTimestamp !== undefined + ? hasSevenDaysPassed(Number(toTimestamp)) // If toTimestamp exists, check this + : hasSevenDaysPassed(Number(resetStakeEndDate)); // If toTimestamp is undefined, check resetStakeEndDat + + const updateResetDate = (timestamp: number) => { + localStorage.setItem(CommonLocalStorageKeys.resetStakeEndDate, timestamp.toString()); + setResetDate(timestamp); + }; + + // Determine which timestamp to use for resetting + if (!resetStakeEndDate || toTimestamp === undefined) { + updateResetDate(latestTimestamp); + } else if (!isPastSevenDays) { + updateResetDate(toTimestamp); + } else { + updateResetDate(latestTimestamp); + } if (!isEpochActive && isPastSevenDays) { setResetEpoch(true); @@ -149,6 +153,8 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { } }; + // console.log(daysToReset, 'daysToReset'); + // Effect for handling fetch data for both arrays useEffect(() => { if (isWalletConnected && userDetails?.userId && !isLoadingPushStakeData && !isLoadingPushUniData) { From 60b6f39c70eb56428379dc65b105a3d81d71fa1f Mon Sep 17 00:00:00 2001 From: corlard3y Date: Mon, 21 Oct 2024 10:32:16 +0100 Subject: [PATCH 2/6] update recent activities v2 --- .../components/RewardsActivitiesListItem.tsx | 4 +- src/modules/rewards/hooks/useDailyRewards.tsx | 56 +++++++------- src/modules/rewards/hooks/useLockedStatus.tsx | 74 ++++++++---------- .../hooks/useStakeRewardsResetTime.tsx | 76 ++++++++----------- .../rewards/useGetRewardActivityStatus.ts | 11 +-- .../rewards/getRewardActivityStatus.ts | 13 ++-- 6 files changed, 106 insertions(+), 128 deletions(-) diff --git a/src/modules/rewards/components/RewardsActivitiesListItem.tsx b/src/modules/rewards/components/RewardsActivitiesListItem.tsx index 679ecad9b1..e9ce84ab3a 100644 --- a/src/modules/rewards/components/RewardsActivitiesListItem.tsx +++ b/src/modules/rewards/components/RewardsActivitiesListItem.tsx @@ -55,7 +55,7 @@ const RewardsActivitiesListItem: FC = ({ } = useGetRewardsActivity({ userId, activityId: activity.id }, { enabled: !!userId }); const [errorMessage, setErrorMessage] = useState(''); - const { handleLockStatus } = useLockedStatus(); + const { getLockStatus } = useLockedStatus(); const isRewardsLocked = useMemo(() => { return ( @@ -71,7 +71,7 @@ const RewardsActivitiesListItem: FC = ({ // if activityType is twitter or discord, then re-call check lock status fn useEffect(() => { if (activity.activityType == 'follow_push_on_discord' || activity.activityType == 'follow_push_on_twitter') { - handleLockStatus(); + getLockStatus(); } }, [usersSingleActivity?.status, activity.activityType]); diff --git a/src/modules/rewards/hooks/useDailyRewards.tsx b/src/modules/rewards/hooks/useDailyRewards.tsx index 3c2860f829..80350e3a17 100644 --- a/src/modules/rewards/hooks/useDailyRewards.tsx +++ b/src/modules/rewards/hooks/useDailyRewards.tsx @@ -2,7 +2,13 @@ import { useCallback, useEffect, useState } from 'react'; // hooks -import { useGetRewardActivityStatus, useGetRewardsActivities, useGetUserRewardsDetails } from 'queries'; +import { + RewardActivityStatus, + RewardActivityStatusResponse, + useGetRewardActivityStatus, + useGetRewardsActivities, + useGetUserRewardsDetails, +} from 'queries'; import { useAccount } from 'hooks'; // helpers @@ -43,10 +49,18 @@ const useDailyRewards = () => { return 0; }); - // Mutation for sending recent activities - const { mutate: sendRecentActivities } = useGetRewardActivityStatus({ - userId: userDetails?.userId as string, - }); + const activityTitles = dailyRewardsActivities?.map((activity) => activity.activityType); + + // Check if dailyRewardsActivities is available and all activityTitles are defined + const areActivitiesDefined = dailyRewardsActivities && activityTitles?.every((title) => title !== undefined); + + const { data: sendRecentActivities } = useGetRewardActivityStatus( + { + userId: userDetails?.userId as string, + activities: activityTitles as string[], + }, + !!userDetails?.userId && areActivitiesDefined + ); // Reset state function const resetState = useCallback(() => { @@ -56,29 +70,12 @@ const useDailyRewards = () => { setIsLoadingRewards(false); }, []); - // Handle check-in function + // Handle success response from sending recent activities const handleCheckIn = () => { - if (!userDetails?.userId) return; - - const activityTitles = dailyRewardsActivities?.map((activity) => activity.activityType); - - sendRecentActivities( - { - userId: userDetails?.userId as string, - activities: activityTitles, - }, - { - onSuccess: handleSuccess, - onError: (err) => { - console.error('Error', err); - }, - } - ); - }; + if (!sendRecentActivities || Object.keys(sendRecentActivities).length === 0) return; + setIsLoadingRewards(true); - // Handle success response from sending recent activities - const handleSuccess = (data: any) => { - const { activities: dataActivity } = data; + const dataActivity = sendRecentActivities?.activities as RewardActivityStatusResponse; const { isEmpty, firstEmptyActivity, latestActivityKey } = getActivityStatus(dataActivity); const targetActivity = isEmpty @@ -91,7 +88,9 @@ const useDailyRewards = () => { ); if (latestActivityKey && !isEmpty) { - const number = checkTimeToCurrent(dataActivity?.[latestActivityKey]?.updatedAt); + const latestActivity = dataActivity?.[latestActivityKey] as RewardActivityStatus; + + const number = checkTimeToCurrent(latestActivity.updatedAt); if (number) { setIsActivityDisabled(true); } @@ -106,14 +105,13 @@ const useDailyRewards = () => { useEffect(() => { if (isWalletConnected && userDetails?.userId) { if (isLoadingActivities || dailyRewardsActivities.length <= 0) return; - setIsLoadingRewards(true); handleCheckIn(); } if (!isWalletConnected) { resetState(); } - }, [userDetails?.userId, isWalletConnected, account, isLoadingActivities]); + }, [userDetails?.userId, isWalletConnected, account, isLoadingActivities, dailyRewardsActivities]); return { account, diff --git a/src/modules/rewards/hooks/useLockedStatus.tsx b/src/modules/rewards/hooks/useLockedStatus.tsx index 3a14c748c6..00f3d0abc8 100644 --- a/src/modules/rewards/hooks/useLockedStatus.tsx +++ b/src/modules/rewards/hooks/useLockedStatus.tsx @@ -1,9 +1,14 @@ // React and other libraries -import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; // hooks import { useAccount } from 'hooks'; -import { useGetRewardActivityStatus, useGetUserRewardsDetails } from 'queries'; +import { + RewardActivityStatus, + RewardActivityStatusResponse, + useGetRewardActivityStatus, + useGetUserRewardsDetails, +} from 'queries'; // helpers import { walletToCAIP10 } from 'helpers/w2w'; @@ -15,35 +20,28 @@ import { useRewardsContext } from 'contexts/RewardsContext'; const useLockedStatus = () => { const { account, isWalletConnected } = useAccount(); const { setIsLocked } = useRewardsContext(); - const [hasMounted, setHasMounted] = useState(false); const caip10WalletAddress = walletToCAIP10({ account }); const { data: userDetails, status, error } = useGetUserRewardsDetails({ caip10WalletAddress }); - const { mutate: sendRecentActivities } = useGetRewardActivityStatus({ - userId: userDetails?.userId as string, - }); + const { data: sendRecentActivities } = useGetRewardActivityStatus( + { + userId: userDetails?.userId as string, + activities: ['follow_push_on_discord', 'follow_push_on_twitter'], + }, + !!userDetails?.userId + ); - useEffect(() => { - if (!hasMounted) { - if (isWalletConnected && userDetails?.userId) { - // do componentDidMount logic - setHasMounted(true); - handleLockStatus(); - } - } + const getLockStatus = () => { + if (!sendRecentActivities || Object.keys(sendRecentActivities).length === 0) return; - if (status === 'error' && isWalletConnected) { - if (isUserNotFound(error)) { - setIsLocked(true); - } - } - }, [userDetails?.userId, isWalletConnected, account, status]); + const activities = sendRecentActivities?.activities as RewardActivityStatusResponse; + const discordStatus = activities?.follow_push_on_discord as RewardActivityStatus; + const twitterStatus = activities?.follow_push_on_twitter as RewardActivityStatus; - const getLockStatus = (data: any) => { if ( - data?.follow_push_on_discord?.status === 'COMPLETED' && - (data?.follow_push_on_twitter?.status === 'COMPLETED' || data?.follow_push_on_twitter?.status === 'PENDING') + discordStatus?.status === 'COMPLETED' && + (twitterStatus?.status === 'COMPLETED' || twitterStatus?.status === 'PENDING') ) { setIsLocked(false); } else { @@ -51,30 +49,18 @@ const useLockedStatus = () => { } }; - const handleLockStatus = () => { - if (!userDetails?.userId) { - console.log('No userId, exiting handleLockStatus'); - return; + useEffect(() => { + if (isWalletConnected && userDetails?.userId) { + getLockStatus(); } - - sendRecentActivities( - { - userId: userDetails?.userId, - activities: ['follow_push_on_discord', 'follow_push_on_twitter'], - }, - { - onSuccess: (data) => { - getLockStatus(data?.activities); - }, - - onError: (err) => { - console.error('Error in sendRecentActivities:', err); - }, + if (status === 'error' && isWalletConnected) { + if (isUserNotFound(error)) { + setIsLocked(true); } - ); - }; + } + }, [userDetails?.userId, isWalletConnected, account, status]); - return { handleLockStatus }; + return { getLockStatus }; }; export default useLockedStatus; diff --git a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx index fe3f296006..0beaef3e55 100644 --- a/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx +++ b/src/modules/rewards/hooks/useStakeRewardsResetTime.tsx @@ -2,6 +2,9 @@ import { useEffect, useMemo, useState } from 'react'; import { useAccount } from 'hooks'; import { + RewardActivityStatus, + RewardActivityStatusResponse, + RewardsStakeParams, useGetPushStakeEpoch, useGetRewardActivityStatus, useGetRewardsActivities, @@ -32,11 +35,6 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { const { data: pushStakeData, isLoading: isLoadingPushStakeData } = useGetPushStakeEpoch(); const { data: uniV2StakeData, isLoading: isLoadingPushUniData } = useGetUniV2StakeEpoch(); - // Mutation for sending recent activities - const { mutate: sendRecentActivities } = useGetRewardActivityStatus({ - userId: userDetails?.userId as string, - }); - const isLoading = isLoadingActivities; // Memoized Push and UniV2 stake arrays to avoid unnecessary recomputation @@ -65,6 +63,16 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { ); }, [rewardActivitiesResponse]); + const activityTitles = allPushArray?.map((activity) => activity.activityType); + + const { data: sendRecentActivities } = useGetRewardActivityStatus( + { + userId: userDetails?.userId as string, + activities: activityTitles as string[], + }, + !!userDetails?.userId + ); + const daysToReset = useMemo(() => { if (resetDate == null || resetDate == undefined) return; @@ -82,46 +90,20 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { return differenceInDays >= sevenDays; // Return true if 7 days or more have passed since the stored epoch time }; - // Function to handle fetch and timestamp/epoch comparison - const fetchAndHandleData = () => { - if (!pushStakeData || !uniV2StakeData) { - console.error('Missing stake data'); - return; - } - - // Call the appropriate fetch function based on the later timestamp - handleFetchData(allPushArray, 'push'); - }; - - // Handle get latest data function for both push and uniV2 - const handleFetchData = (activities: any[], stakeType: 'push' | 'uniV2') => { - if (!userDetails?.userId || activities.length <= 0) return; - - const activityTitles = activities.map((activity) => activity.activityType); - sendRecentActivities( - { - userId: userDetails.userId as string, - activities: activityTitles, - }, - { - onSuccess: (data) => handleSuccess(data, stakeType), - onError: (err) => { - console.error('Error', err); - }, - } - ); - }; - // Handle success response and reset epoch if criteria met - const handleSuccess = (data: any, stakeType: 'push' | 'uniV2') => { - const { activities: dataActivity } = data; + const handleFetchData = (stakeType: 'push' | 'uniV2') => { + if (!sendRecentActivities || Object.keys(sendRecentActivities).length === 0) return; + + const dataActivity = sendRecentActivities?.activities as RewardActivityStatusResponse; const { latestActivityKey } = getActivityStatus(dataActivity); - const mostRecentStakeActivity = dataActivity?.[latestActivityKey]; + const mostRecentStakeActivity = dataActivity?.[latestActivityKey] as RewardActivityStatus; + const latestStakeActivity = mostRecentStakeActivity?.data as RewardsStakeParams; + const stakeData = stakeType === 'push' ? pushStakeData : uniV2StakeData; - const toTimestamp = mostRecentStakeActivity?.data?.toTimestamp as number; const latestTimestamp = pushStakeData?.toTimestamp as number; - const isEpochActive = mostRecentStakeActivity?.data?.currentEpoch === stakeData?.currentEpoch; + const toTimestamp = latestStakeActivity?.toTimestamp as number; + const isEpochActive = latestStakeActivity?.currentEpoch === stakeData?.currentEpoch; const resetStakeEndDate = localStorage.getItem(CommonLocalStorageKeys.resetStakeEndDate); // Check if it's been seven days based on the appropriate timestamp @@ -144,6 +126,8 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { updateResetDate(latestTimestamp); } + // console.log(isEpochActive, 'isEpochActive', isPastSevenDays, 'isPastSevenDays'); + if (!isEpochActive && isPastSevenDays) { setResetEpoch(true); console.log(`${stakeType} epoch is reset`); @@ -157,14 +141,20 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => { // Effect for handling fetch data for both arrays useEffect(() => { - if (isWalletConnected && userDetails?.userId && !isLoadingPushStakeData && !isLoadingPushUniData) { - fetchAndHandleData(); + if ( + isWalletConnected && + userDetails?.userId && + !isLoadingPushStakeData && + !isLoadingPushUniData && + sendRecentActivities + ) { + handleFetchData('push'); } if (!isWalletConnected) { setResetEpoch(false); } - }, [userDetails?.userId, isWalletConnected, isLoadingPushStakeData, isLoadingPushUniData]); + }, [userDetails?.userId, isWalletConnected, isLoadingPushStakeData, isLoadingPushUniData, sendRecentActivities]); return { stakePushArray, uniV2PushArray, isLoading, daysToReset }; }; diff --git a/src/queries/hooks/rewards/useGetRewardActivityStatus.ts b/src/queries/hooks/rewards/useGetRewardActivityStatus.ts index 5713bcafdd..3f1b0f3e6a 100644 --- a/src/queries/hooks/rewards/useGetRewardActivityStatus.ts +++ b/src/queries/hooks/rewards/useGetRewardActivityStatus.ts @@ -1,9 +1,10 @@ -import { useMutation } from '@tanstack/react-query'; +import { useQuery } from '@tanstack/react-query'; import { rewardActivityStatus } from 'queries'; import { getRewardActivityStatus } from 'queries/services'; -export const useGetRewardActivityStatus = (payload: { userId: string }) => - useMutation({ - mutationKey: [rewardActivityStatus, payload?.userId], - mutationFn: getRewardActivityStatus, +export const useGetRewardActivityStatus = (payload: { userId: string; activities: string[] }, enabled: boolean) => + useQuery({ + queryKey: [rewardActivityStatus, payload?.userId, payload?.activities], + queryFn: () => getRewardActivityStatus(payload), + enabled, }); diff --git a/src/queries/services/rewards/getRewardActivityStatus.ts b/src/queries/services/rewards/getRewardActivityStatus.ts index 2551984f7e..e0b4946cad 100644 --- a/src/queries/services/rewards/getRewardActivityStatus.ts +++ b/src/queries/services/rewards/getRewardActivityStatus.ts @@ -3,12 +3,15 @@ import { getRewardsBaseURL } from 'queries/baseURL'; import { getRewardActivityStatusModel } from 'queries/models'; import { RewardActivityStatusProps } from 'queries/types'; -export const getRewardActivityStatus = (payload: RewardActivityStatusProps) => - axios({ - method: 'POST', - url: `${getRewardsBaseURL()}/users/${payload.userId}/recent-activities`, - data: payload.activities, +export const getRewardActivityStatus = (payload: RewardActivityStatusProps) => { + // Join the activities array into a string + const activitiesString = payload.activities.join(','); + + return axios({ + method: 'GET', + url: `${getRewardsBaseURL()}/users/${payload.userId}/recent-activities/v2?types=${activitiesString}`, headers: { 'Content-Type': 'application/json', }, }).then((response) => getRewardActivityStatusModel(response.data)); +}; From 3c745dac6109e342e455c9e503f4ba92dec99e0a Mon Sep 17 00:00:00 2001 From: corlard3y Date: Tue, 22 Oct 2024 02:44:16 +0100 Subject: [PATCH 3/6] handle user single activity --- .../components/BonusActivitiesItem.tsx | 15 ++++---- .../components/BonusActivitiesSection.tsx | 27 ++++++++++++++- .../components/DailyRewardsSection.tsx | 17 ++++++---- .../components/RewardsActivitiesList.tsx | 34 ++++++++++++++++++- .../components/RewardsActivitiesListItem.tsx | 17 ++++++---- .../StakePushActivitiesListItem.tsx | 17 ++++++---- .../rewards/components/StakePushSection.tsx | 25 +++++++++++++- src/modules/rewards/hooks/useDailyRewards.tsx | 7 ++-- .../hooks/rewards/useGetRewardsActivity.ts | 14 ++++---- .../rewards/getRewardsActivityModelCreator.ts | 4 +-- .../services/rewards/getRewardsActivity.ts | 10 ++++-- src/queries/types/rewards.ts | 9 +++++ 12 files changed, 152 insertions(+), 44 deletions(-) diff --git a/src/modules/rewards/components/BonusActivitiesItem.tsx b/src/modules/rewards/components/BonusActivitiesItem.tsx index 25c2600999..3c77b88a99 100644 --- a/src/modules/rewards/components/BonusActivitiesItem.tsx +++ b/src/modules/rewards/components/BonusActivitiesItem.tsx @@ -2,7 +2,7 @@ import { FC } from 'react'; // hooks -import { Activity, useGetRewardsActivity } from 'queries'; +import { Activity, StakeActivityResponse, UsersActivity } from 'queries'; import { useAccount } from 'hooks'; // components @@ -17,6 +17,9 @@ export type BonusActivitiesItemProps = { isLoadingItem: boolean; setErrorMessage: (errorMessage: string) => void; isLocked: boolean; + allUsersActivity: StakeActivityResponse; + isAllActivitiesLoading: boolean; + refetchActivity: () => void; }; const BonusActivitiesItem: FC = ({ @@ -25,12 +28,12 @@ const BonusActivitiesItem: FC = ({ isLoadingItem, setErrorMessage, isLocked, + allUsersActivity, + isAllActivitiesLoading, + refetchActivity, }) => { - const { - data: usersSingleActivity, - isLoading, - refetch: refetchActivity, - } = useGetRewardsActivity({ userId, activityId: activity.id }, { enabled: !!userId }); + const usersSingleActivity = allUsersActivity?.[activity?.activityType] as UsersActivity; + const isLoading = isAllActivitiesLoading; const { isWalletConnected } = useAccount(); diff --git a/src/modules/rewards/components/BonusActivitiesSection.tsx b/src/modules/rewards/components/BonusActivitiesSection.tsx index bcd6252117..2f078e50f7 100644 --- a/src/modules/rewards/components/BonusActivitiesSection.tsx +++ b/src/modules/rewards/components/BonusActivitiesSection.tsx @@ -5,7 +5,12 @@ import { FC, useState } from 'react'; import { css } from 'styled-components'; // hooks -import { useGetRewardsActivities, useGetUserRewardsDetails } from 'queries'; +import { + StakeActivityResponse, + useGetRewardsActivities, + useGetRewardsActivity, + useGetUserRewardsDetails, +} from 'queries'; import { useAccount } from 'hooks'; import { useRewardsContext } from 'contexts/RewardsContext'; @@ -41,6 +46,23 @@ const BonusActivities: FC = () => { const { isLocked } = useRewardsContext(); + // Combine all activities into a single array + const allActivities = [...bonusActivities]; + + // Extract the `activityType` from each activity and filter out any undefined values + const activityTypes = allActivities + .map((activity) => activity.activityType) // Extract `activityType` + .filter(Boolean); // Remove undefined/null values + + const { + data: allUsersActivity, + isLoading: isAllActivitiesLoading, + refetch: refetchActivity, + } = useGetRewardsActivity( + { userId: userDetails?.userId as string, activityTypes: activityTypes }, + { enabled: !!userDetails?.userId && activityTypes.length > 0 } + ); + return ( = () => { isLoadingItem={isLoading} setErrorMessage={setErrorMessage} isLocked={isLocked} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} diff --git a/src/modules/rewards/components/DailyRewardsSection.tsx b/src/modules/rewards/components/DailyRewardsSection.tsx index e577aeb1fe..d5c1b8f9b5 100644 --- a/src/modules/rewards/components/DailyRewardsSection.tsx +++ b/src/modules/rewards/components/DailyRewardsSection.tsx @@ -19,14 +19,19 @@ export type DailyRewardsSectionProps = {}; const DailyRewardsSection: FC = () => { const [errorMessage, setErrorMessage] = useState(''); - const { activeItem, activeDay, isActivityDisabled, isLoading, userDetails, dailyRewardsActivities, handleCheckIn } = - useDailyRewards(); + const { + activeItem, + activeDay, + isActivityDisabled, + isLoading, + userDetails, + dailyRewardsActivities, + refetchSendActivities, + } = useDailyRewards(); const { isLocked } = useRewardsContext(); - const isDailyRewardClaimed = useMemo(() => { - return isActivityDisabled && activeDay > 1 && userDetails; - }, [isActivityDisabled, activeDay, userDetails]); + const isDailyRewardClaimed = isActivityDisabled && activeDay > 1 && userDetails; const displayDailyRewards = useMemo(() => { return !isActivityDisabled && activeDay > 0 && activeItem && userDetails; @@ -85,7 +90,7 @@ const DailyRewardsSection: FC = () => { activityType={activeItem?.activityType as ActvityType} userId={userDetails?.userId as string} activityTypeId={activeItem?.id as string} - refetchActivity={() => handleCheckIn()} + refetchActivity={() => refetchSendActivities()} setErrorMessage={setErrorMessage} isLoadingActivity={false} label="Check In" diff --git a/src/modules/rewards/components/RewardsActivitiesList.tsx b/src/modules/rewards/components/RewardsActivitiesList.tsx index 6db3ba3716..eb41493cf3 100644 --- a/src/modules/rewards/components/RewardsActivitiesList.tsx +++ b/src/modules/rewards/components/RewardsActivitiesList.tsx @@ -5,7 +5,13 @@ import { css } from 'styled-components'; import { Box, Lock, Text } from 'blocks'; import { useAccount } from 'hooks'; import { walletToCAIP10 } from 'helpers/w2w'; -import { Activity, useGetRewardsActivities, useGetUserRewardsDetails } from 'queries'; +import { + Activity, + StakeActivityResponse, + useGetRewardsActivities, + useGetRewardsActivity, + useGetUserRewardsDetails, +} from 'queries'; import { useRewardsContext } from 'contexts/RewardsContext'; import { RewardsActivitiesListItem } from './RewardsActivitiesListItem'; @@ -43,6 +49,23 @@ const RewardsActivitiesList: FC = () => { const { isLocked } = useRewardsContext(); + // Combine all activities into a single array + const allActivities = [...socialActivities, ...platformRewardActivities, ...channelSubscriptionActivities]; + + // Extract the `activityType` from each activity and filter out any undefined values + const activityTypes = allActivities + .map((activity) => activity.activityType) // Extract `activityType` + .filter(Boolean); // Remove undefined/null values + + const { + data: allUsersActivity, + isLoading: isAllActivitiesLoading, + refetch: refetchActivity, + } = useGetRewardsActivity( + { userId: userDetails?.userId as string, activityTypes: activityTypes }, + { enabled: !!userDetails?.userId && activityTypes.length > 0 } + ); + return ( = () => { activity={activity} isLoadingItem={isLoading} isLocked={isLocked} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} {(isLocked || !isWalletConnected) && ( @@ -103,6 +129,9 @@ const RewardsActivitiesList: FC = () => { activity={activity} isLoadingItem={isLoading} isLocked={isLocked} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} @@ -114,6 +143,9 @@ const RewardsActivitiesList: FC = () => { activity={activity} isLoadingItem={isLoading} isLocked={isLocked} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} diff --git a/src/modules/rewards/components/RewardsActivitiesListItem.tsx b/src/modules/rewards/components/RewardsActivitiesListItem.tsx index e9ce84ab3a..3dac6e3ac7 100644 --- a/src/modules/rewards/components/RewardsActivitiesListItem.tsx +++ b/src/modules/rewards/components/RewardsActivitiesListItem.tsx @@ -1,6 +1,6 @@ import { FC, useEffect, useMemo, useState } from 'react'; -import { Activity, useGetRewardsActivity } from 'queries'; +import { Activity, StakeActivityResponse, UsersActivity } from 'queries'; import { useAccount } from 'hooks'; import { @@ -27,6 +27,9 @@ export type RewardActivitiesListItemProps = { activity: Activity; isLoadingItem: boolean; isLocked: boolean; + allUsersActivity: StakeActivityResponse; + isAllActivitiesLoading: boolean; + refetchActivity: () => void; }; const getUpdatedExpiryTime = (timestamp: number) => { @@ -46,13 +49,13 @@ const RewardsActivitiesListItem: FC = ({ activity, isLoadingItem, isLocked, + allUsersActivity, + isAllActivitiesLoading, + refetchActivity, }) => { const { isWalletConnected } = useAccount(); - const { - data: usersSingleActivity, - isLoading, - refetch: refetchActivity, - } = useGetRewardsActivity({ userId, activityId: activity.id }, { enabled: !!userId }); + const usersSingleActivity = allUsersActivity?.[activity?.activityType] as UsersActivity; + const isLoading = isAllActivitiesLoading; const [errorMessage, setErrorMessage] = useState(''); const { getLockStatus } = useLockedStatus(); @@ -73,7 +76,7 @@ const RewardsActivitiesListItem: FC = ({ if (activity.activityType == 'follow_push_on_discord' || activity.activityType == 'follow_push_on_twitter') { getLockStatus(); } - }, [usersSingleActivity?.status, activity.activityType]); + }, [usersSingleActivity, activity.activityType]); return ( diff --git a/src/modules/rewards/components/StakePushActivitiesListItem.tsx b/src/modules/rewards/components/StakePushActivitiesListItem.tsx index ad3ccda965..5e5e5d7e2c 100644 --- a/src/modules/rewards/components/StakePushActivitiesListItem.tsx +++ b/src/modules/rewards/components/StakePushActivitiesListItem.tsx @@ -2,7 +2,7 @@ import { FC } from 'react'; // hooks -import { Activity, useGetRewardsActivity } from 'queries'; +import { Activity, StakeActivityResponse, UsersActivity } from 'queries'; import { useAccount } from 'hooks'; // components @@ -17,6 +17,9 @@ export type StakeActivitiesItemProps = { setErrorMessage: (errorMessage: string) => void; isLocked: boolean; hasEpochEnded?: boolean; + allUsersActivity: StakeActivityResponse; + isAllActivitiesLoading: boolean; + refetchActivity: () => void; }; const StakePushActivitiesListItem: FC = ({ userId, @@ -25,15 +28,15 @@ const StakePushActivitiesListItem: FC = ({ setErrorMessage, isLocked, hasEpochEnded, + allUsersActivity, + isAllActivitiesLoading, + refetchActivity, }) => { - const { - data: usersSingleActivity, - isLoading, - refetch: refetchActivity, - } = useGetRewardsActivity({ userId, activityId: activity.id }, { enabled: !!userId }); - const { isWalletConnected } = useAccount(); + const usersSingleActivity = allUsersActivity?.[activity?.activityType] as UsersActivity; + const isLoading = isAllActivitiesLoading; + const hasActivityEndedUnclaimed = usersSingleActivity?.status !== 'COMPLETED' && hasEpochEnded; const isLockedOrNotConnected = isLocked || !isWalletConnected; diff --git a/src/modules/rewards/components/StakePushSection.tsx b/src/modules/rewards/components/StakePushSection.tsx index d7c4692c9b..3647943ae1 100644 --- a/src/modules/rewards/components/StakePushSection.tsx +++ b/src/modules/rewards/components/StakePushSection.tsx @@ -3,7 +3,7 @@ import { FC, useMemo, useState } from 'react'; // hooks import { useAccount } from 'hooks'; -import { useGetUserRewardsDetails } from 'queries'; +import { StakeActivityResponse, useGetRewardsActivity, useGetUserRewardsDetails } from 'queries'; import { useRewardsContext } from 'contexts/RewardsContext'; // helpers @@ -46,6 +46,23 @@ const StakePushSection: FC = ({ title, subtitle, timeline, mult return daysToReset != null && activityResetDate >= 0 && activityResetDate <= 7 && !multiplier && isWalletConnected; }, [daysToReset, activityResetDate, multiplier, isWalletConnected]); + // Combine all activities into a single array + const allActivities = [...uniV2PushArray, ...stakePushArray]; + + // Extract the `activityType` from each activity and filter out any undefined values + const activityTypes = allActivities + .map((activity) => activity.activityType) // Extract `activityType` + .filter(Boolean); // Remove undefined/null values + + const { + data: allUsersActivity, + isLoading: isAllActivitiesLoading, + refetch: refetchActivity, + } = useGetRewardsActivity( + { userId: userDetails?.userId as string, activityTypes: activityTypes }, + { enabled: !!userDetails?.userId && activityTypes.length > 0 } + ); + return ( = ({ title, subtitle, timeline, mult setErrorMessage={setErrorMessage} isLocked={isLocked} hasEpochEnded={hasEpochEnded} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} @@ -184,6 +204,9 @@ const StakePushSection: FC = ({ title, subtitle, timeline, mult setErrorMessage={setErrorMessage} isLocked={isLocked} hasEpochEnded={hasEpochEnded} + allUsersActivity={allUsersActivity as StakeActivityResponse} + isAllActivitiesLoading={isAllActivitiesLoading} + refetchActivity={refetchActivity} /> ))} diff --git a/src/modules/rewards/hooks/useDailyRewards.tsx b/src/modules/rewards/hooks/useDailyRewards.tsx index 80350e3a17..366642bdd1 100644 --- a/src/modules/rewards/hooks/useDailyRewards.tsx +++ b/src/modules/rewards/hooks/useDailyRewards.tsx @@ -54,7 +54,7 @@ const useDailyRewards = () => { // Check if dailyRewardsActivities is available and all activityTitles are defined const areActivitiesDefined = dailyRewardsActivities && activityTitles?.every((title) => title !== undefined); - const { data: sendRecentActivities } = useGetRewardActivityStatus( + const { data: sendRecentActivities, refetch: refetchSendActivities } = useGetRewardActivityStatus( { userId: userDetails?.userId as string, activities: activityTitles as string[], @@ -71,7 +71,7 @@ const useDailyRewards = () => { }, []); // Handle success response from sending recent activities - const handleCheckIn = () => { + const handleCheckIn = useCallback(() => { if (!sendRecentActivities || Object.keys(sendRecentActivities).length === 0) return; setIsLoadingRewards(true); @@ -99,7 +99,7 @@ const useDailyRewards = () => { setActiveDay(newDay); setActiveItem(newDayData); setIsLoadingRewards(false); - }; + }, [sendRecentActivities]); // Effect for handling check-in when user details change or wallet is connected useEffect(() => { @@ -122,6 +122,7 @@ const useDailyRewards = () => { userDetails, dailyRewardsActivities, handleCheckIn, + refetchSendActivities, resetState, }; }; diff --git a/src/queries/hooks/rewards/useGetRewardsActivity.ts b/src/queries/hooks/rewards/useGetRewardsActivity.ts index 29d2800a0c..8a40c5dc92 100644 --- a/src/queries/hooks/rewards/useGetRewardsActivity.ts +++ b/src/queries/hooks/rewards/useGetRewardsActivity.ts @@ -1,14 +1,14 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'; import { rewardsActivity } from '../../queryKeys'; import { getRewardsActivity } from '../../services/rewards'; -import { UsersActivity } from '../../types'; +import { StakeActivityResponse } from '../../types'; export const useGetRewardsActivity = ( - { userId, activityId }: { userId: string; activityId: string }, - config?: Partial> + { userId, activityTypes }: { userId: string; activityTypes: string[] }, + config?: Partial> ) => - useQuery({ - queryKey: [rewardsActivity, userId, activityId], - queryFn: () => getRewardsActivity(userId, activityId), - ...config + useQuery({ + queryKey: [rewardsActivity, userId, activityTypes], + queryFn: () => getRewardsActivity(userId, activityTypes), + ...config, }); diff --git a/src/queries/models/rewards/getRewardsActivityModelCreator.ts b/src/queries/models/rewards/getRewardsActivityModelCreator.ts index 70b7483a6e..8acafe9a1c 100644 --- a/src/queries/models/rewards/getRewardsActivityModelCreator.ts +++ b/src/queries/models/rewards/getRewardsActivityModelCreator.ts @@ -1,3 +1,3 @@ -import { UsersActivity } from 'queries/types'; +import { StakeActivityResponse } from 'queries/types'; -export const getRewardsActivityModelCreator = (response: UsersActivity): UsersActivity => response; +export const getRewardsActivityModelCreator = (response: StakeActivityResponse): StakeActivityResponse => response; diff --git a/src/queries/services/rewards/getRewardsActivity.ts b/src/queries/services/rewards/getRewardsActivity.ts index 62e3f8834a..8662432918 100644 --- a/src/queries/services/rewards/getRewardsActivity.ts +++ b/src/queries/services/rewards/getRewardsActivity.ts @@ -2,9 +2,13 @@ import axios from 'axios'; import { getRewardsBaseURL } from 'queries/baseURL'; import { getRewardsActivityModelCreator } from 'queries/models'; -export const getRewardsActivity = (userId: string, activityId: string) => - axios({ +export const getRewardsActivity = (userId: string, activityTypes: string[]) => { + // Join the activities array into a string + const activitiesString = activityTypes.join(','); + + return axios({ method: 'GET', - url: `${getRewardsBaseURL()}/users/${userId}/activity/${activityId}`, + url: `${getRewardsBaseURL()}/users/${userId}/activities/bytype?types=${activitiesString}`, }).then((response) => getRewardsActivityModelCreator(response.data)); +}; diff --git a/src/queries/types/rewards.ts b/src/queries/types/rewards.ts index bb9ec7b4c4..085ced02f2 100644 --- a/src/queries/types/rewards.ts +++ b/src/queries/types/rewards.ts @@ -97,6 +97,15 @@ export type UsersActivity = { updatedAt: string; // ISO 8601 date string }; +export type UsersActivityError = { + error: string; +}; + +// The key can be any string, and the value can be either StakeActivitySuccess or StakeActivityError +export type StakeActivityResponse = { + [key: string]: UsersActivity | UsersActivityError; +}; + type Prop = { [key: string]: string; }; From 8a880397bdc5b387e96b563343276fee15a5f33b Mon Sep 17 00:00:00 2001 From: corlard3y Date: Tue, 22 Oct 2024 09:15:10 +0100 Subject: [PATCH 4/6] add revoke activities --- src/common/Common.baseLogos.ts | 3 +++ .../rewards/components/RewardsActivityIcon.tsx | 13 ++++++++++++- .../rewards/hooks/useStakeRewardsResetTime.tsx | 2 -- src/modules/rewards/utils/activityTypeArray.ts | 1 + src/queries/types/rewards.ts | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/common/Common.baseLogos.ts b/src/common/Common.baseLogos.ts index 82e97f3813..0cc673e50d 100644 --- a/src/common/Common.baseLogos.ts +++ b/src/common/Common.baseLogos.ts @@ -9,3 +9,6 @@ export const walletTrackerLogo = export const shapeShiftLogo = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z3BhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABYWVogAAAAAAAA9tYAAQAAAADTLW1sdWMAAAAAAAAAAQAAAAxlblVTAAAAIAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAwAD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0yqavGiRlwccHPpD3IzOFF5WdkZWboTMvT08uZo6CunMpGWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/9k='; diff --git a/src/modules/rewards/components/RewardsActivityIcon.tsx b/src/modules/rewards/components/RewardsActivityIcon.tsx index f4fb06dcf9..4f2104f72c 100644 --- a/src/modules/rewards/components/RewardsActivityIcon.tsx +++ b/src/modules/rewards/components/RewardsActivityIcon.tsx @@ -30,7 +30,7 @@ import { PushAlpha, CyberLogoRewards, } from 'blocks'; -import { quickSwapLogo, priceTrackerLogo, walletTrackerLogo, shapeShiftLogo } from 'common'; +import { quickSwapLogo, priceTrackerLogo, walletTrackerLogo, shapeShiftLogo, revokeLogo } from 'common'; import { ActvityType } from 'queries'; type RewardsActivityIconProp = { @@ -217,6 +217,17 @@ const RewardsActivityIcon: FC = ({ type }) => { ); } + if (type === 'channel_specific_subscriptions:REVOKE_NOTIFICATIONS') { + return ( + + ); + } + if (type === 'stake_1_uni_v2_lp_epoch' || type === 'stake_1k_push_epoch') { return ( { updateResetDate(latestTimestamp); } - // console.log(isEpochActive, 'isEpochActive', isPastSevenDays, 'isPastSevenDays'); - if (!isEpochActive && isPastSevenDays) { setResetEpoch(true); console.log(`${stakeType} epoch is reset`); diff --git a/src/modules/rewards/utils/activityTypeArray.ts b/src/modules/rewards/utils/activityTypeArray.ts index 1aed2807f5..5afbb9dbac 100644 --- a/src/modules/rewards/utils/activityTypeArray.ts +++ b/src/modules/rewards/utils/activityTypeArray.ts @@ -16,6 +16,7 @@ export const channelSubscriptionActivities: ActvityType[] = [ 'channel_specific_subscriptions:WALLETTRACKER_CHANNEL', 'channel_specific_subscriptions:SHAPESHIFT_CHANNEL', 'channel_specific_subscriptions:CYBER_CHANNEL', + 'channel_specific_subscriptions:REVOKE_NOTIFICATIONS', ]; export const bonusRewardActivities: ActvityType[] = [ diff --git a/src/queries/types/rewards.ts b/src/queries/types/rewards.ts index 085ced02f2..b3115eaff9 100644 --- a/src/queries/types/rewards.ts +++ b/src/queries/types/rewards.ts @@ -36,6 +36,7 @@ export type ActvityType = | 'channel_specific_subscriptions:PRICETRACKER_CHANNEL' | 'channel_specific_subscriptions:SHAPESHIFT_CHANNEL' | 'channel_specific_subscriptions:CYBER_CHANNEL' + | 'channel_specific_subscriptions:REVOKE_NOTIFICATIONS' | 'stake_1k_push_epoch' | 'stake_5k_push_epoch' | 'stake_10k_push_epoch' From e6165c7d062dd63db6d5d513f0f5510d5e57ceda Mon Sep 17 00:00:00 2001 From: corlard3y Date: Tue, 22 Oct 2024 10:55:22 +0100 Subject: [PATCH 5/6] update revoke notifications channel --- src/modules/rewards/components/RewardsActivityIcon.tsx | 2 +- src/modules/rewards/utils/activityTypeArray.ts | 2 +- src/queries/types/rewards.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/rewards/components/RewardsActivityIcon.tsx b/src/modules/rewards/components/RewardsActivityIcon.tsx index 4f2104f72c..846d3be50a 100644 --- a/src/modules/rewards/components/RewardsActivityIcon.tsx +++ b/src/modules/rewards/components/RewardsActivityIcon.tsx @@ -217,7 +217,7 @@ const RewardsActivityIcon: FC = ({ type }) => { ); } - if (type === 'channel_specific_subscriptions:REVOKE_NOTIFICATIONS') { + if (type === 'channel_specific_subscriptions:REVOKE_NOTIFICATIONS_CHANNEL') { return ( Date: Tue, 22 Oct 2024 12:47:28 +0100 Subject: [PATCH 6/6] update locked status --- .../rewards/components/RewardsActivitiesListItem.tsx | 11 ++++++++--- src/modules/rewards/hooks/useLockedStatus.tsx | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/rewards/components/RewardsActivitiesListItem.tsx b/src/modules/rewards/components/RewardsActivitiesListItem.tsx index 3dac6e3ac7..0179a19ed7 100644 --- a/src/modules/rewards/components/RewardsActivitiesListItem.tsx +++ b/src/modules/rewards/components/RewardsActivitiesListItem.tsx @@ -58,7 +58,7 @@ const RewardsActivitiesListItem: FC = ({ const isLoading = isAllActivitiesLoading; const [errorMessage, setErrorMessage] = useState(''); - const { getLockStatus } = useLockedStatus(); + const { refetchRecentActivities, getLockStatus, statusRecentActivities } = useLockedStatus(); const isRewardsLocked = useMemo(() => { return ( @@ -71,12 +71,17 @@ const RewardsActivitiesListItem: FC = ({ const isNotDiscordOrTwitter = activity.activityType !== 'follow_push_on_discord' && activity.activityType !== 'follow_push_on_twitter'; + const updateActivities = () => { + refetchActivity(); + refetchRecentActivities(); + }; + // if activityType is twitter or discord, then re-call check lock status fn useEffect(() => { if (activity.activityType == 'follow_push_on_discord' || activity.activityType == 'follow_push_on_twitter') { getLockStatus(); } - }, [usersSingleActivity, activity.activityType]); + }, [usersSingleActivity?.status, activity.activityType, statusRecentActivities]); return ( @@ -250,7 +255,7 @@ const RewardsActivitiesListItem: FC = ({ userId={userId} activityTypeId={activity.id} activityType={activity.activityType} - refetchActivity={refetchActivity} + refetchActivity={() => updateActivities()} setErrorMessage={setErrorMessage} usersSingleActivity={usersSingleActivity} isLoadingActivity={isLoading} diff --git a/src/modules/rewards/hooks/useLockedStatus.tsx b/src/modules/rewards/hooks/useLockedStatus.tsx index 00f3d0abc8..75a2acce54 100644 --- a/src/modules/rewards/hooks/useLockedStatus.tsx +++ b/src/modules/rewards/hooks/useLockedStatus.tsx @@ -24,7 +24,11 @@ const useLockedStatus = () => { const caip10WalletAddress = walletToCAIP10({ account }); const { data: userDetails, status, error } = useGetUserRewardsDetails({ caip10WalletAddress }); - const { data: sendRecentActivities } = useGetRewardActivityStatus( + const { + data: sendRecentActivities, + refetch: refetchRecentActivities, + status: statusRecentActivities, + } = useGetRewardActivityStatus( { userId: userDetails?.userId as string, activities: ['follow_push_on_discord', 'follow_push_on_twitter'], @@ -60,7 +64,7 @@ const useLockedStatus = () => { } }, [userDetails?.userId, isWalletConnected, account, status]); - return { getLockStatus }; + return { getLockStatus, refetchRecentActivities, statusRecentActivities }; }; export default useLockedStatus;