Skip to content

Commit

Permalink
hotfix: undefined fixes in useStakingContractInfo hook for build 126
Browse files Browse the repository at this point in the history
  • Loading branch information
truemiller committed Sep 9, 2024
1 parent fd18e36 commit c8bd590
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frontend/hooks/useStakingContractInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isNil } from 'lodash';
import { useContext } from 'react';

import { StakingContractInfoContext } from '@/context/StakingContractInfoProvider';
Expand All @@ -24,7 +25,10 @@ export const useStakingContractInfo = () => {
} = activeStakingContractInfo;

const isRewardsAvailable = true; // availableRewards > 0;
const hasEnoughServiceSlots = serviceIds.length < maxNumServices;
const hasEnoughServiceSlots =
!isNil(serviceIds) &&
!isNil(maxNumServices) &&
serviceIds.length < maxNumServices;
const hasEnoughRewardsAndSlots = isRewardsAvailable && hasEnoughServiceSlots;

const isAgentEvicted = serviceStakingState === 2;
Expand All @@ -41,8 +45,10 @@ export const useStakingContractInfo = () => {
*
*/
const isServiceStakedForMinimumDuration =
!isNil(serviceStakingStartTime) &&
!isNil(minimumStakingDuration) &&
Math.round(Date.now() / 1000) - serviceStakingStartTime >=
minimumStakingDuration;
minimumStakingDuration;

/**
* user can start the agent iff,
Expand All @@ -51,7 +57,7 @@ export const useStakingContractInfo = () => {
* - if agent is evicted, then service should be staked for minimum duration
*/
const isEligibleForStaking =
hasEnoughRewardsAndSlots &&
!isNil(hasEnoughRewardsAndSlots) &&
(isAgentEvicted ? isServiceStakedForMinimumDuration : true);

return {
Expand Down

0 comments on commit c8bd590

Please sign in to comment.