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 Rewards Point - LifeTime Issue #1950

Merged
merged 3 commits into from
Oct 30, 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
4 changes: 3 additions & 1 deletion src/modules/rewards/components/ActivityButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ActivityButtonProps = {
isLoadingActivity: boolean;
label?: string;
isStakeSection?: boolean;
lifeTime?: boolean;
};

const ActivityButton: FC<ActivityButtonProps> = ({
Expand All @@ -31,10 +32,11 @@ const ActivityButton: FC<ActivityButtonProps> = ({
isLoadingActivity,
label,
isStakeSection,
lifeTime,
}) => {
const { resetEpoch } = useRewardsContext();

if (usersSingleActivity?.status === 'COMPLETED' && isStakeSection && resetEpoch) {
if (usersSingleActivity?.status === 'COMPLETED' && isStakeSection && resetEpoch && !lifeTime) {
return (
// default verify button
<ActivityVerificationButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const RewardsActivitiesBottomSection: FC<RewardsActivitiesBottomSectionProps> =
>
<StakePushSection
title="Stake Push to Earn Points"
subtitle="Visit [app.push.org/yieldv2](https://app.push.org/yieldv2) and stake tokens in the Fee Pool or LP Pool to redeem points."
subtitle="Visit [app.push.org/yield](https://app.push.org/yield) and stake tokens in the Fee Pool or LP Pool to redeem points."
timeline={true}
/>
</Box>
Expand All @@ -53,9 +53,9 @@ const RewardsActivitiesBottomSection: FC<RewardsActivitiesBottomSectionProps> =
margin="spacing-none spacing-none spacing-md spacing-none"
>
<StakePushSection
multiplier={true}
lifeTime={true}
title="Stake Push to Earn Multipliers"
subtitle="Visit [app.push.org/yieldv2](https://app.push.org/yieldv2) and stake tokens in the Fee Pool or LP Pool to activate multipliers."
subtitle="Visit [app.push.org/yield](https://app.push.org/yield) and stake tokens in the Fee Pool or LP Pool to activate multipliers."
/>
</Box>
</Box>
Expand Down
26 changes: 24 additions & 2 deletions src/modules/rewards/components/StakePushActivitiesListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type StakeActivitiesItemProps = {
allUsersActivity: StakeActivityResponse;
isAllActivitiesLoading: boolean;
refetchActivity: () => void;
lifeTime?: boolean;
};
const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
userId,
Expand All @@ -31,6 +32,7 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
allUsersActivity,
isAllActivitiesLoading,
refetchActivity,
lifeTime,
}) => {
const { isWalletConnected } = useAccount();

Expand All @@ -40,6 +42,7 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
const hasActivityEndedUnclaimed = usersSingleActivity?.status !== 'COMPLETED' && hasEpochEnded;

const isLockedOrNotConnected = isLocked || !isWalletConnected;

return (
<Skeleton
isLoading={isLoadingItem}
Expand Down Expand Up @@ -163,7 +166,7 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
</Button>
)}

{hasActivityEndedUnclaimed && !isLocked && isWalletConnected && (
{hasActivityEndedUnclaimed && !isLocked && isWalletConnected && !lifeTime && (
<Button
variant="tertiary"
size="small"
Expand All @@ -173,7 +176,25 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
</Button>
)}

{!hasActivityEndedUnclaimed && !isLocked && isWalletConnected && (
{/* stake reset/one-time button */}
{!hasActivityEndedUnclaimed && !isLocked && isWalletConnected && !lifeTime && (
<ActivityButton
userId={userId}
activityTypeId={activity.id}
activityTypeIndex={activity.index}
activityType={activity.activityType}
refetchActivity={refetchActivity}
setErrorMessage={setErrorMessage}
usersSingleActivity={usersSingleActivity}
isLoadingActivity={isLoading}
label="Claim"
isStakeSection
lifeTime={lifeTime}
/>
)}

{/* stake lifetime button */}
{lifeTime && !isLocked && isWalletConnected && (
<ActivityButton
userId={userId}
activityTypeId={activity.id}
Expand All @@ -185,6 +206,7 @@ const StakePushActivitiesListItem: FC<StakeActivitiesItemProps> = ({
isLoadingActivity={isLoading}
label="Claim"
isStakeSection
lifeTime={lifeTime}
/>
)}
</Box>
Expand Down
18 changes: 10 additions & 8 deletions src/modules/rewards/components/StakePushSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export type StakePushPoints = {
title: string;
subtitle: string;
timeline?: boolean;
multiplier?: boolean;
lifeTime?: boolean;
};

const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, multiplier }) => {
const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, lifeTime }) => {
const { account, isWalletConnected } = useAccount();
const { isLocked } = useRewardsContext();
const { stakePushArray, uniV2PushArray, isLoading, daysToReset } = useStakeRewardsResetTime({
multiplier,
lifeTime,
});
const [errorMessage, setErrorMessage] = useState<string>('');

Expand All @@ -39,12 +39,12 @@ const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, mult
const activityResetDate = (daysToReset as number) + 7;

const isEpochStatusActive = useMemo(() => {
return daysToReset != null && !multiplier && daysToReset >= 0 && activityResetDate > 7 && isWalletConnected;
}, [daysToReset, multiplier, activityResetDate, isWalletConnected]);
return daysToReset != null && !lifeTime && daysToReset >= 0 && activityResetDate > 7 && isWalletConnected;
}, [daysToReset, lifeTime, activityResetDate, isWalletConnected]);

const hasEpochEnded = useMemo(() => {
return daysToReset != null && activityResetDate >= 0 && activityResetDate <= 7 && !multiplier && isWalletConnected;
}, [daysToReset, activityResetDate, multiplier, isWalletConnected]);
return daysToReset != null && activityResetDate >= 0 && activityResetDate <= 7 && !lifeTime && isWalletConnected;
}, [daysToReset, activityResetDate, lifeTime, isWalletConnected]);

// Combine all activities into a single array
const allActivities = [...uniV2PushArray, ...stakePushArray];
Expand Down Expand Up @@ -185,6 +185,7 @@ const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, mult
allUsersActivity={allUsersActivity as StakeActivityResponse}
isAllActivitiesLoading={isAllActivitiesLoading}
refetchActivity={refetchActivity}
lifeTime={lifeTime}
/>
))}
</Box>
Expand All @@ -207,12 +208,13 @@ const StakePushSection: FC<StakePushPoints> = ({ title, subtitle, timeline, mult
allUsersActivity={allUsersActivity as StakeActivityResponse}
isAllActivitiesLoading={isAllActivitiesLoading}
refetchActivity={refetchActivity}
lifeTime={lifeTime}
/>
))}
</Box>
</Box>

{!multiplier && (
{!lifeTime && (
<Text
textAlign="center"
variant="bs-semibold"
Expand Down
12 changes: 6 additions & 6 deletions src/modules/rewards/hooks/useStakeRewardsResetTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { filterAndSortActivities, filterAndSortAllActivities } from '../utils/st
import { CommonLocalStorageKeys } from 'common';

export type StakeRewardsResetTime = {
multiplier?: boolean;
lifeTime?: boolean;
};

const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => {
const useStakeRewardsResetTime = ({ lifeTime }: StakeRewardsResetTime) => {
const [resetDate, setResetDate] = useState<number | null>(null); // Local state for latest timestamp
const { account, isWalletConnected } = useAccount();
const { setResetEpoch } = useRewardsContext();
Expand All @@ -42,17 +42,17 @@ const useStakeRewardsResetTime = ({ multiplier }: StakeRewardsResetTime) => {
return filterAndSortActivities(
'push',
rewardActivitiesResponse?.activities.flatMap((page) => page) || [],
multiplier
lifeTime
);
}, [rewardActivitiesResponse, multiplier, isLoadingActivities]);
}, [rewardActivitiesResponse, lifeTime, isLoadingActivities]);

const uniV2PushArray = useMemo(() => {
return filterAndSortActivities(
'uni-v2',
rewardActivitiesResponse?.activities.flatMap((page) => page) || [],
multiplier
lifeTime
);
}, [rewardActivitiesResponse, multiplier, isLoadingActivities]);
}, [rewardActivitiesResponse, lifeTime, isLoadingActivities]);

// Combined array for both multiplier and point activities for push and uniV2
const allPushArray = useMemo(() => {
Expand Down
Loading