From 5bb911274e02c7d24de0e8a62aae0a72363c98b8 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Wed, 18 Dec 2024 20:17:11 +0530 Subject: [PATCH 1/3] fix: refactor staking rewards query and update multisig nonces call --- frontend/context/RewardProvider.tsx | 19 ++++++++++--------- frontend/service/agents/Memeooor.ts | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/context/RewardProvider.tsx b/frontend/context/RewardProvider.tsx index dab0b040..73229153 100644 --- a/frontend/context/RewardProvider.tsx +++ b/frontend/context/RewardProvider.tsx @@ -64,17 +64,18 @@ const useStakingRewardsDetails = () => { ), queryFn: async () => { if (!multisig || !token || !selectedStakingProgramId) return null; - const response = - await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({ - agentMultisigAddress: multisig, - serviceId: token, - stakingProgramId: selectedStakingProgramId, - chainId: currentChainId, - }); - - if (!response) return null; try { + const response = + await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({ + agentMultisigAddress: multisig, + serviceId: token, + stakingProgramId: selectedStakingProgramId, + chainId: currentChainId, + }); + + if (!response) return null; + const parsed = StakingRewardsInfoSchema.parse(response); return parsed; } catch (e) { diff --git a/frontend/service/agents/Memeooor.ts b/frontend/service/agents/Memeooor.ts index 81f84267..9161aa79 100644 --- a/frontend/service/agents/Memeooor.ts +++ b/frontend/service/agents/Memeooor.ts @@ -48,7 +48,7 @@ export abstract class MemeooorBaseService extends StakedAgentService { stakingTokenProxyContract.minStakingDeposit(), stakingTokenProxyContract.tsCheckpoint(), activityChecker.livenessRatio(), - activityChecker.getMultisigNonces(), + activityChecker.getMultisigNonces(agentMultisigAddress), ]; const multicallResponse = await provider.all(contractCalls); From a574a32d0bd315af373594ca5d6333eab626ef6a Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Wed, 18 Dec 2024 20:52:55 +0530 Subject: [PATCH 2/3] fix: improve staking rewards logic and enhance loading state handling --- .../RewardsSection/StakingRewardsThisEpoch.tsx | 3 +++ .../MainPage/sections/RewardsSection/index.tsx | 3 ++- frontend/context/RewardProvider.tsx | 8 +++----- frontend/service/agents/Memeooor.ts | 18 +++++++++++------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/frontend/components/MainPage/sections/RewardsSection/StakingRewardsThisEpoch.tsx b/frontend/components/MainPage/sections/RewardsSection/StakingRewardsThisEpoch.tsx index d88812f1..2dc1c0ac 100644 --- a/frontend/components/MainPage/sections/RewardsSection/StakingRewardsThisEpoch.tsx +++ b/frontend/components/MainPage/sections/RewardsSection/StakingRewardsThisEpoch.tsx @@ -38,6 +38,9 @@ const useEpochEndTime = () => { return { data, isLoading }; }; +/** + * Staking rewards for the current epoch + */ export const StakingRewardsThisEpoch = () => { const { data: epochEndTimeInMs } = useEpochEndTime(); diff --git a/frontend/components/MainPage/sections/RewardsSection/index.tsx b/frontend/components/MainPage/sections/RewardsSection/index.tsx index d64cb34a..44698a73 100644 --- a/frontend/components/MainPage/sections/RewardsSection/index.tsx +++ b/frontend/components/MainPage/sections/RewardsSection/index.tsx @@ -35,8 +35,9 @@ const DisplayRewards = () => { const reward = getFormattedReward(availableRewardsForEpochEth); const earnedTag = useMemo(() => { - if (isStakingRewardsDetailsLoading && !isStakingRewardsDetailsError) + if (isStakingRewardsDetailsLoading && !isStakingRewardsDetailsError) { return ; + } if (isEligibleForRewards) { return Earned; } diff --git a/frontend/context/RewardProvider.tsx b/frontend/context/RewardProvider.tsx index 73229153..0c0a8bbe 100644 --- a/frontend/context/RewardProvider.tsx +++ b/frontend/context/RewardProvider.tsx @@ -63,14 +63,12 @@ const useStakingRewardsDetails = () => { token!, ), queryFn: async () => { - if (!multisig || !token || !selectedStakingProgramId) return null; - try { const response = await selectedAgentConfig.serviceApi.getAgentStakingRewardsInfo({ - agentMultisigAddress: multisig, - serviceId: token, - stakingProgramId: selectedStakingProgramId, + agentMultisigAddress: multisig!, + serviceId: token!, + stakingProgramId: selectedStakingProgramId!, chainId: currentChainId, }); diff --git a/frontend/service/agents/Memeooor.ts b/frontend/service/agents/Memeooor.ts index 9161aa79..956304b7 100644 --- a/frontend/service/agents/Memeooor.ts +++ b/frontend/service/agents/Memeooor.ts @@ -82,13 +82,17 @@ export abstract class MemeooorBaseService extends StakedAgentService { const lastMultisigNonces = serviceInfo[2]; const nowInSeconds = Math.floor(Date.now() / 1000); - const [isEligibleForRewards] = await provider.all([ - activityChecker.isRatioPass( - currentMultisigNonces, - lastMultisigNonces, - Math.ceil(nowInSeconds - tsCheckpoint), - ), - ]); + const isServiceStaked = serviceInfo[2].length > 0; + + const [isEligibleForRewards] = isServiceStaked + ? await provider.all([ + activityChecker.isRatioPass( + currentMultisigNonces, + lastMultisigNonces, + Math.ceil(nowInSeconds - tsCheckpoint), + ), + ]) + : [false]; const availableRewardsForEpoch = Math.max( rewardsPerSecond * livenessPeriod, // expected rewards for the epoch From 0c4281c35255d50b8e02078ee769ed131f07bb5a Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Wed, 18 Dec 2024 20:58:27 +0530 Subject: [PATCH 3/3] fix: handle error case in staking rewards details parsing --- frontend/context/RewardProvider.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/context/RewardProvider.tsx b/frontend/context/RewardProvider.tsx index 0c0a8bbe..fe0a29ed 100644 --- a/frontend/context/RewardProvider.tsx +++ b/frontend/context/RewardProvider.tsx @@ -79,6 +79,8 @@ const useStakingRewardsDetails = () => { } catch (e) { console.error('Error parsing staking rewards info', e); } + + return null; }, enabled: !!isOnline &&