diff --git a/apps/staking/components/StakedNodeCard.tsx b/apps/staking/components/StakedNodeCard.tsx index 9642e37..0833e32 100644 --- a/apps/staking/components/StakedNodeCard.tsx +++ b/apps/staking/components/StakedNodeCard.tsx @@ -109,6 +109,13 @@ const hasRequestedUnlockHeight = (node: Stake): node is NodeRequestingExit => * @see {@link ExitedNode} * @see {@link DeregisteredNode} * @param stake - The stake to check. + * + * @note The `contract_id` check here is for and edge case. If a node has exited the smart contract + * and the network hasn't confirmed the event yet then the `contract_id` is `null`. BUT this should + * not happen as the node info should be stored in the database and the backend should use that data, + * which includes the contract_id. So it's a technically possible edge case but not likely to happen + * as long as the backend is doing its job well. BUT if people host their own backend there is no + * guarantee the database has the node in it so the `contract_id` might be `null`. */ const hasExited = (stake: Stake): stake is ExitedNode => stake.exited || ('contract_id' in stake && stake.contract_id === null); @@ -373,7 +380,10 @@ const DeregisteringNotification = ({ const soonString = generalDictionary('soon'); const isDeregistrationSoon = isDateSoonOrPast(date); - const relativeTime = (!isDeregistrationSoon ? timeString : soonString) ?? notFoundString; + const relativeTime = useMemo( + () => (!isDeregistrationSoon ? timeString : soonString) ?? notFoundString, + [isDeregistrationSoon, timeString, soonString, notFoundString] + ); return ( { +}: NodeSummaryProps) => { const allTimers = []; if (isReadyToExit(node, blockHeight)) { const readyToExitTimer = ( diff --git a/apps/staking/hooks/useRelativeTime.tsx b/apps/staking/hooks/useRelativeTime.tsx index f3ed33e..5d7eb99 100644 --- a/apps/staking/hooks/useRelativeTime.tsx +++ b/apps/staking/hooks/useRelativeTime.tsx @@ -41,6 +41,7 @@ export default function useRelativeTime( useEffect(() => { let timer: NodeJS.Timeout; + // TODO: investigate moving this outside the function and using a useCallback hook function updateRelativeTime() { let diffInMs: number | undefined; if (targetDate) { diff --git a/packages/sent-staking-js/test.ts b/packages/sent-staking-js/test.ts index 66633ad..b809ec0 100644 --- a/packages/sent-staking-js/test.ts +++ b/packages/sent-staking-js/test.ts @@ -1,5 +1,7 @@ import { GetStakesResponse, NODE_STATE, type Registration, Stake, StakeContributor } from './client'; +// NOTE: this file will be refactored at some point, it doesnt work very well + /** * Generates a random mock node public key. * @returns The generated node public key. @@ -81,26 +83,26 @@ type GenerateBasicNodeDataProps = { */ function generateBasicNodeData({ userAddress, - operatorAddress, + operatorAddress = generateWalletAddress(), minContributors, }: GenerateBasicNodeDataProps): Omit { const num_contributions = Math.max(minContributors ?? 0, Math.ceil(Math.random() * 10)); const contributors = generateContributors(num_contributions, userAddress); - const staked_balance = contributors.find(({ address }) => address === userAddress)?.amount; + const staked_balance = contributors.find(({ address }) => address === userAddress)?.amount ?? 0; return { service_node_pubkey: generateNodePubKey(), requested_unlock_height: 0, last_reward_block_height: 0, contract_id: 0, contributors: generateContributors(num_contributions, userAddress), - operator_address: operatorAddress ?? generateWalletAddress(), + operator_address: operatorAddress, last_uptime_proof: generatePastBlockHeight(), operator_fee: 0, exited: false, earned_downtime_blocks: 20, deregistration_unlock_height: null, liquidation_height: null, - staked_balance: staked_balance ?? 0, + staked_balance: staked_balance, }; }