Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stake section #1978

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/modules/rewards/components/ActivityButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -31,14 +31,39 @@ const ActivityButton: FC<ActivityButtonProps> = ({
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 (
<Button
variant="tertiary"
size="small"
disabled
>
Claimed
</Button>
);
}

// default verify button for stake epoch section
if (usersSingleActivity?.status === 'COMPLETED' && resetEpoch && (isPushEpochRelated || isUniV2EpochRelated)) {
console.log('reset button');
return (
// default verify button
<ActivityVerificationButton
activityType={activityType}
userId={userId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
const usersSingleActivity = allUsersActivity?.[activity?.activityType] as UsersActivity;
const isLoading = isAllActivitiesLoading;

const hasActivityEndedUnclaimed = usersSingleActivity?.status !== 'COMPLETED' && hasEpochEnded;
const hasActivityEndedUnclaimed = hasEpochEnded;

const isLockedOrNotConnected = isLocked || !isWalletConnected;

Expand Down
7 changes: 5 additions & 2 deletions src/modules/rewards/components/StakePushSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type StakePushPoints = {
const StakePushSection: FC<StakePushPoints> = ({ 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<string>('');
Expand Down Expand Up @@ -184,7 +184,10 @@ const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, life
hasEpochEnded={hasEpochEnded}
allUsersActivity={allUsersActivity as StakeActivityResponse}
isAllActivitiesLoading={isAllActivitiesLoading}
refetchActivity={refetchActivity}
refetchActivity={() => {
refetchActivity();
refetchSendActivities();
}}
lifeTime={lifeTime}
/>
))}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/rewards/hooks/useStakeRewardsResetTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -135,8 +137,6 @@ const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => {
}
};

// console.log(daysToReset, 'daysToReset');

// Effect for handling fetch data for both arrays
useEffect(() => {
if (
Expand All @@ -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 };
1 change: 1 addition & 0 deletions src/queries/hooks/rewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from './useCreateRewardsUser';
export * from './useGetRewardsLedearboard';
export * from './useGetRewardActivityStatus';
export * from './useGetPushStakeEpoch';
export * from './useGetPreviousPushStakeEpoch';
export * from './useGetUniV2StakeEpoch';
9 changes: 9 additions & 0 deletions src/queries/hooks/rewards/useGetPreviousPushStakeEpoch.ts
Original file line number Diff line number Diff line change
@@ -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,
});
3 changes: 3 additions & 0 deletions src/queries/models/rewards/getPreviousPushStakeEpochModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RewardsStakeParams } from 'queries/types';

export const getPreviousPushStakeEpochModel = (response: RewardsStakeParams): RewardsStakeParams => response;
1 change: 1 addition & 0 deletions src/queries/models/rewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from './createUserRewardsDetailsModel';
export * from './getRewardsLeaderboardModalCreator';
export * from './getRewardActivityStatusModel';
export * from './getPushStakeEpochModel';
export * from './getPreviousPushStakeEpochModel';
export * from './getUniV2StakeEpochModel';
1 change: 1 addition & 0 deletions src/queries/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions src/queries/services/rewards/getPreviousPushStakeEpoch.ts
Original file line number Diff line number Diff line change
@@ -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));
1 change: 1 addition & 0 deletions src/queries/services/rewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 4 additions & 1 deletion src/queries/types/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading