Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add liquidation states to unlocked deregistered nodes #25

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 50 additions & 46 deletions apps/staking/components/StakedNodeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,21 @@ const NodeNotification = forwardRef<HTMLSpanElement, NodeNotificationProps>(
)
);

export const NodeOperatorIndicator = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => {
type NodeOperatorIndicatorProps = HTMLAttributes<HTMLDivElement> & {
isOperatorConnectedWallet?: boolean;
};

export const NodeOperatorIndicator = forwardRef<HTMLDivElement, NodeOperatorIndicatorProps>(
({ className, isOperatorConnectedWallet, ...props }, ref) => {
const dictionary = useTranslations('nodeCard.staked');
return (
<Tooltip tooltipContent={dictionary('operatorTooltip')}>
<Tooltip
tooltipContent={
isOperatorConnectedWallet
? dictionary('operatorTooltip')
: dictionary('operatorTooltipOther')
}
>
<div
ref={ref}
className={cn(
Expand Down Expand Up @@ -169,10 +179,12 @@ const ReadyForExitNotification = ({
date,
timeString,
className,
isDeregistered,
yougotwill marked this conversation as resolved.
Show resolved Hide resolved
}: {
date: Date | null;
timeString: string | null;
className?: string;
isDeregistered?: boolean;
}) => {
const dictionary = useTranslations('nodeCard.staked');
const dictionaryGeneral = useTranslations('general');
Expand All @@ -187,7 +199,11 @@ const ReadyForExitNotification = ({
return (
<Tooltip
tooltipContent={dictionary.rich(
isLiquidationSoon ? 'exitTimerDescriptionNow' : 'exitTimerDescription',
isDeregistered
? 'liquidationDescription'
: isLiquidationSoon
? 'exitTimerDescriptionNow'
: 'exitTimerDescription',
{
relativeTime,
link: externalLink(URL.NODE_LIQUIDATION_LEARN_MORE),
Expand All @@ -196,8 +212,11 @@ const ReadyForExitNotification = ({
>
<NodeNotification level={isLiquidationSoon ? 'error' : 'warning'} className={className}>
{isLiquidationSoon
? dictionary('exitTimerNotificationNow')
: dictionary('exitTimerNotification', { relativeTime })}
? dictionary(isDeregistered ? 'liquidationNotification' : 'exitTimerNotificationNow')
: dictionary(
isDeregistered ? 'deregistrationTimerDescription' : 'exitTimerNotification',
{ relativeTime }
)}
</NodeNotification>
</Tooltip>
);
Expand All @@ -207,9 +226,11 @@ const ExitUnlockTimerNotification = ({
date,
timeString,
className,
isDeregistered,
}: {
date: Date | null;
timeString: string | null;
isDeregistered?: boolean;
className?: string;
}) => {
const dictionary = useTranslations('nodeCard.staked');
Expand All @@ -225,15 +246,23 @@ const ExitUnlockTimerNotification = ({

return (
<Tooltip
tooltipContent={dictionary('exitUnlockTimerDescription', {
relativeTime,
date: date ? formatDate(date, { dateStyle: 'full', timeStyle: 'short' }) : notFoundString,
})}
tooltipContent={dictionary(
isDeregistered ? 'deregisteredTimerDescription' : 'exitUnlockTimerDescription',
{
relativeTime,
date: date ? formatDate(date, { dateStyle: 'full', timeStyle: 'short' }) : notFoundString,
}
)}
>
<NodeNotification level="warning" className={className}>
{relativeTime
? dictionary('exitUnlockTimerNotification', { relativeTime })
: dictionary('exitUnlockTimerProcessing')}
? dictionary(
isDeregistered ? 'deregisteredTimerNotification' : 'exitUnlockTimerNotification',
{
relativeTime,
}
)
: dictionary(isDeregistered ? 'deregisteredProcessing' : 'exitUnlockTimerProcessing')}
</NodeNotification>
</Tooltip>
);
Expand Down Expand Up @@ -329,11 +358,16 @@ const NodeSummary = ({
{contributors}
{!isExited ? (
isReadyToUnlockByDeregistration ? (
<ReadyForExitNotification date={liquidationDate} timeString={liquidationTime} />
<ReadyForExitNotification
timeString={liquidationTime}
date={liquidationDate}
isDeregistered
/>
) : (
<ExitUnlockTimerNotification
date={deregistrationUnlockDate}
timeString={deregistrationUnlockTime}
date={deregistrationUnlockDate}
isDeregistered
/>
)
) : null}
Expand Down Expand Up @@ -636,8 +670,6 @@ const StakedNodeCard = forwardRef<
stake={stake}
state={state}
blockHeight={blockHeight}
deregistrationUnlockDate={deregistrationUnlockDate}
deregistrationUnlockTime={deregistrationUnlockTime}
requestedUnlockDate={requestedUnlockDate}
requestedUnlockTime={requestedUnlockTime}
notFoundString={notFoundString}
Expand All @@ -656,56 +688,28 @@ function StakeNodeCardButton({
blockHeight,
notFoundString,
requestedUnlockDate,
deregistrationUnlockDate,
requestedUnlockTime,
deregistrationUnlockTime,
}: {
stake: Stake;
state: STAKE_STATE;
blockHeight: number;
deregistrationUnlockTime?: string | null;
deregistrationUnlockDate?: Date | null;
requestedUnlockDate?: Date | null;
requestedUnlockTime?: string | null;
notFoundString?: string;
}) {
const dictionary = useTranslations('nodeCard.staked');

const eventState = parseStakeEventState(stake);
const isReadyToExitByDeregistrationUnlock = useIsReadyToExitByDeregistrationUnlock(
state,
eventState,
stake.deregistration_height,
blockHeight
);

if (
state === STAKE_STATE.EXITED ||
eventState === STAKE_EVENT_STATE.EXITED ||
eventState === STAKE_EVENT_STATE.LIQUIDATED
eventState === STAKE_EVENT_STATE.LIQUIDATED ||
state === STAKE_STATE.DEREGISTERED
) {
return null;
}

if (state === STAKE_STATE.DEREGISTERED) {
if (isReadyToExitByDeregistrationUnlock) {
return <NodeExitButtonDialog node={stake} />;
}

return (
<Tooltip
tooltipContent={dictionary('exit.disabledButtonTooltipContent', {
relativeTime: deregistrationUnlockTime ?? notFoundString,
date: deregistrationUnlockDate
? formatDate(deregistrationUnlockDate, { dateStyle: 'full', timeStyle: 'short' })
: notFoundString,
})}
>
<NodeExitButton disabled />
</Tooltip>
);
}

if (isReadyToExitByUnlock(state, eventState, stake.requested_unlock_height, blockHeight)) {
return <NodeExitButtonDialog node={stake} />;
}
Expand Down
3 changes: 3 additions & 0 deletions apps/staking/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@
"exitTimerDescriptionNow": "Node is ready for exit. If you don't exit now, you may be subject to a small penalty. <link>Learn more</link>",
"deregistrationTimerNotification": "Deregistration {relativeTime}",
"deregistrationTimerDescription": "Time left until the node is deregistered and funds are locked for {lockedStakeTime}. Node will be deregistered {relativeTime} ({date})",
"deregisteredProcessing": "Deregistration is being processed",
"deregisteredTimerNotification": "Stake will unlock {relativeTime}",
"deregisteredTimerDescription": "Time left until the stake is unlocked and the node is available for liquidation. ({date})",
"liquidationNotification": "Awaiting liquidation",
"liquidationDescription": "The node is inactive and waiting to be removed by the network.",
"finalize": {
Expand Down
Loading