Skip to content

Commit

Permalink
fix: add check for contract id list before showing dereg status
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Jan 24, 2025
1 parent bc21332 commit 3c77db6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions apps/staking/components/StakedNodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from '@/components/StakedNode/state';
import { CopyToClipboardButton } from '@session/ui/components/CopyToClipboardButton';
import { NodeExitButtonDialog } from '@/components/StakedNode/NodeExitButtonDialog';
import { useStakes } from '@/hooks/useStakes';

/**
* Checks if a given stake is ready to exit the smart contract.
Expand Down Expand Up @@ -68,16 +69,13 @@ export const useIsReadyToExitByDeregistrationUnlock = (
deregistrationHeight?: number | null,
blockHeight?: number
) => {
const { chainId } = useWallet();
return !!(
state === STAKE_STATE.DEREGISTERED &&
eventState !== STAKE_EVENT_STATE.EXITED &&
eventState !== STAKE_EVENT_STATE.LIQUIDATED &&
deregistrationHeight &&
blockHeight &&
deregistrationHeight +
msInBlocks(SESSION_NODE_TIME(chainId).DEREGISTRATION_LOCKED_STAKE_SECONDS * 1000) <=
blockHeight
deregistrationHeight <= blockHeight
);
};

Expand Down Expand Up @@ -319,6 +317,7 @@ type NodeSummaryProps = {
liquidationTime: string | null;
showAllTimers?: boolean;
isOperator?: boolean;
isInContractIdList?: boolean;
};

const NodeSummary = ({
Expand All @@ -333,6 +332,7 @@ const NodeSummary = ({
deregistrationUnlockTime,
liquidationDate,
liquidationTime,
isInContractIdList,
}: NodeSummaryProps) => {
const eventState = parseStakeEventState(node);
const isExited =
Expand All @@ -356,7 +356,7 @@ const NodeSummary = ({
return (
<>
{contributors}
{!isExited ? (
{!isExited && isInContractIdList ? (
isReadyToUnlockByDeregistration ? (
<ReadyForExitNotification
timeString={liquidationTime}
Expand All @@ -379,7 +379,7 @@ const NodeSummary = ({
return (
<>
{contributors}
{isExited ? null : isReadyToExitByUnlock(
{isExited || !isInContractIdList ? null : isReadyToExitByUnlock(
state,
eventState,
node.requested_unlock_height,
Expand Down Expand Up @@ -484,6 +484,9 @@ const StakedNodeCard = forwardRef<

const address = targetWalletAddress ?? connectedAddress;

const { currentContractIds } = useStakes(address);
const isInContractIdList = currentContractIds?.has(stake.contract_id);

const {
operator_fee: fee,
operator_address: operatorAddress,
Expand Down Expand Up @@ -542,6 +545,7 @@ const StakedNodeCard = forwardRef<
node={stake}
state={state}
blockHeight={blockHeight}
isInContractIdList={isInContractIdList}
deregistrationDate={deregistrationDate}
deregistrationTime={deregistrationTime}
deregistrationUnlockDate={deregistrationUnlockDate}
Expand Down
6 changes: 5 additions & 1 deletion apps/staking/hooks/useStakes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ export function useStakes(overrideAddress?: Address) {
contracts,
hiddenContractsWithStakes,
addedBlsKeys,
currentContractIds,
runningStakesBlsKeys,
blockHeight,
networkTime,
network,
] = useMemo(() => {
if (!address || !data) return [[], [], [], null, null, null];
if (!address || !data) return [[], [], [], null, null, null, null];
const stakesArr = 'stakes' in data && Array.isArray(data.stakes) ? data.stakes : [];
const contractsArr = 'contracts' in data && Array.isArray(data.contracts) ? data.contracts : [];

Expand All @@ -169,6 +170,7 @@ export function useStakes(overrideAddress?: Address) {
: {};

const addedBlsKeysSet = new Set(Object.keys(blsKeysObject));
const currentContractIdsSet = new Set(Object.values(blsKeysObject));
const runningStakesBlsKeysSet = new Set(
stakesArr
.filter((stake) => parseStakeEventState(stake) === STAKE_EVENT_STATE.ACTIVE)
Expand Down Expand Up @@ -228,6 +230,7 @@ export function useStakes(overrideAddress?: Address) {
filteredContracts,
hiddenContracts,
addedBlsKeysSet,
currentContractIdsSet,
runningStakesBlsKeysSet,
blockHeight,
networkTime,
Expand All @@ -240,6 +243,7 @@ export function useStakes(overrideAddress?: Address) {
contracts,
hiddenContractsWithStakes,
addedBlsKeys,
currentContractIds,
runningStakesBlsKeys,
network,
blockHeight,
Expand Down
2 changes: 1 addition & 1 deletion packages/staking-api-js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export interface GetStakesResponse {
network: NetworkInfo;
contracts: Array<ContributorContractInfo>;
stakes: Array<Stake>;
added_bls_keys: Record<number, string>;
added_bls_keys: Record<string, number>;
}

/** /store */
Expand Down

0 comments on commit 3c77db6

Please sign in to comment.