Skip to content

Commit

Permalink
Merge branch 'dev' into registration_card_interactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym authored Sep 26, 2024
2 parents 0db7585 + 982201d commit 3b72b61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
40 changes: 26 additions & 14 deletions apps/staking/components/StakedNodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<Tooltip
Expand All @@ -393,6 +403,20 @@ const DeregisteringNotification = ({
);
};

type NodeSummaryProps = {
node: Stake;
blockHeight: number;
deregistrationDate: Date | null;
deregistrationTime: string | null;
requestedUnlockDate: Date | null;
requestedUnlockTime: string | null;
deregistrationUnlockDate: Date | null;
deregistrationUnlockTime: string | null;
liquidationDate: Date | null;
liquidationTime: string | null;
showAllTimers?: boolean;
};

const NodeSummary = ({
node,
blockHeight,
Expand All @@ -405,19 +429,7 @@ const NodeSummary = ({
liquidationDate,
liquidationTime,
showAllTimers,
}: {
node: Stake;
blockHeight: number;
deregistrationDate: Date | null;
deregistrationTime: string | null;
requestedUnlockDate: Date | null;
requestedUnlockTime: string | null;
deregistrationUnlockDate: Date | null;
deregistrationUnlockTime: string | null;
liquidationDate: Date | null;
liquidationTime: string | null;
showAllTimers?: boolean;
}) => {
}: NodeSummaryProps) => {
const allTimers = [];
if (isReadyToExit(node, blockHeight)) {
const readyToExitTimer = (
Expand Down
1 change: 1 addition & 0 deletions apps/staking/hooks/useRelativeTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions packages/sent-staking-js/test.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -81,26 +83,26 @@ type GenerateBasicNodeDataProps = {
*/
function generateBasicNodeData({
userAddress,
operatorAddress,
operatorAddress = generateWalletAddress(),
minContributors,
}: GenerateBasicNodeDataProps): Omit<Stake, 'state'> {
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,
};
}

Expand Down

0 comments on commit 3b72b61

Please sign in to comment.