From 2c1b5f59a38c8e31e61a3fa9de7f6baeeeab08c7 Mon Sep 17 00:00:00 2001 From: Tommy Verrall Date: Mon, 8 Jun 2026 12:38:09 +0200 Subject: [PATCH] Last fixes - Pending Delegate events with registry-miss identity keep explorer navigation; unbonded label limited to pending Undelegate rows (`isPendingUndelegateWithRegistryMiss`, `formatPendingDelegationLinkLabel`). - Tests in `delegationIdentity.test.ts`. --- .../components/Delegation/DelegationList.tsx | 25 +++---------------- .../Delegation/PendingDelegationCard.tsx | 13 +++++++--- .../src/utils/delegationIdentity.test.ts | 19 ++++++++++++++ nym-wallet/src/utils/delegationIdentity.ts | 15 ++++++++++- .../src/utils/unbondedDelegation.fixture.ts | 16 ++++++++++++ 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/nym-wallet/src/components/Delegation/DelegationList.tsx b/nym-wallet/src/components/Delegation/DelegationList.tsx index b239a16283..c1dbf69856 100644 --- a/nym-wallet/src/components/Delegation/DelegationList.tsx +++ b/nym-wallet/src/components/Delegation/DelegationList.tsx @@ -319,28 +319,9 @@ export const DelegationList: FCWithChildren<{ Pending - {pendingItems.map((item: any, index: number) => { - if ( - item.event && - item.event.kind === 'Delegate' && - (!item.node_identity || item.node_identity === '') - ) { - return ( - - ); - } - - return ( - - ); - })} + {pendingItems.map((item: any, index: number) => ( + + ))} )} diff --git a/nym-wallet/src/components/Delegation/PendingDelegationCard.tsx b/nym-wallet/src/components/Delegation/PendingDelegationCard.tsx index 7c4eac65d7..2c4ac35422 100644 --- a/nym-wallet/src/components/Delegation/PendingDelegationCard.tsx +++ b/nym-wallet/src/components/Delegation/PendingDelegationCard.tsx @@ -2,11 +2,16 @@ import React from 'react'; import { Box, Chip, Paper, Stack, Tooltip, Typography } from '@mui/material'; import { WrappedDelegationEvent } from '@nymproject/types'; import { TauriLink as Link } from 'src/components/TauriLinkWrapper'; -import { formatDelegationNodeIdentityForDisplay, isUnbondedNodeIdentity } from 'src/utils/delegationIdentity'; +import { + formatDelegationNodeIdentityForDisplay, + formatPendingDelegationLinkLabel, + isPendingUndelegateWithRegistryMiss, +} from 'src/utils/delegationIdentity'; export const PendingDelegationCard = ({ item, explorerUrl }: { item: WrappedDelegationEvent; explorerUrl: string }) => { + const pendingUndelegateRegistryMiss = isPendingUndelegateWithRegistryMiss(item); const displayIdentity = formatDelegationNodeIdentityForDisplay(item.node_identity, item.event.mix_id); - const nodeIsUnbonded = isUnbondedNodeIdentity(item.node_identity); + const linkLabel = formatPendingDelegationLinkLabel(item.node_identity, item.event.mix_id); return ( - {nodeIsUnbonded ? ( + {pendingUndelegateRegistryMiss ? ( {displayIdentity} @@ -28,7 +33,7 @@ export const PendingDelegationCard = ({ item, explorerUrl }: { item: WrappedDele diff --git a/nym-wallet/src/utils/delegationIdentity.test.ts b/nym-wallet/src/utils/delegationIdentity.test.ts index c0f38d8ed5..9a83b52791 100644 --- a/nym-wallet/src/utils/delegationIdentity.test.ts +++ b/nym-wallet/src/utils/delegationIdentity.test.ts @@ -2,9 +2,12 @@ import { UNBONDED_NODE_IDENTITY_PREFIX, formatUnbondedNodeLabel, formatDelegationNodeIdentityForDisplay, + formatPendingDelegationLinkLabel, isFullyUnbondedDelegation, + isPendingUndelegateWithRegistryMiss, isUnbondedNodeIdentity, } from './delegationIdentity'; +import { buildPendingDelegateEvent, buildPendingUndelegateEvent } from './unbondedDelegation.fixture'; describe('delegationIdentity', () => { it('treats empty identity as unbonded', () => { @@ -35,4 +38,20 @@ describe('delegationIdentity', () => { '2Abcdefghijklmnopqrstuvwxyz1234567890', ); }); + + it('uses unbonded label only for pending undelegate registry misses', () => { + const pendingDelegate = buildPendingDelegateEvent(`unbonded:${42}`); + const pendingUndelegate = buildPendingUndelegateEvent(`unbonded:${42}`); + + expect(isPendingUndelegateWithRegistryMiss(pendingDelegate)).toBe(false); + expect(isPendingUndelegateWithRegistryMiss(pendingUndelegate)).toBe(true); + }); + + it('formats pending delegate explorer link label by mix id when identity lookup missed', () => { + expect(formatPendingDelegationLinkLabel('', 788)).toBe('Mix 788'); + expect(formatPendingDelegationLinkLabel('unbonded:788', 788)).toBe('Mix 788'); + expect(formatPendingDelegationLinkLabel('2Abcdefghijklmnopqrstuvwxyz1234567890', 788)).toBe( + '2Abcde...567890', + ); + }); }); diff --git a/nym-wallet/src/utils/delegationIdentity.ts b/nym-wallet/src/utils/delegationIdentity.ts index 04cc394be2..7b09466fe1 100644 --- a/nym-wallet/src/utils/delegationIdentity.ts +++ b/nym-wallet/src/utils/delegationIdentity.ts @@ -1,4 +1,4 @@ -import type { DelegationWithEverything } from '@nymproject/types'; +import type { DelegationWithEverything, WrappedDelegationEvent } from '@nymproject/types'; export const UNBONDED_NODE_IDENTITY_PREFIX = 'unbonded:'; @@ -25,3 +25,16 @@ export function formatDelegationNodeIdentityForDisplay(nodeIdentity: string, mix } return nodeIdentity; } + +export function isPendingUndelegateWithRegistryMiss( + item: Pick, +): boolean { + return item.event.kind === 'Undelegate' && isUnbondedNodeIdentity(item.node_identity); +} + +export function formatPendingDelegationLinkLabel(nodeIdentity: string, mixId: number): string { + if (!nodeIdentity || isUnbondedNodeIdentity(nodeIdentity)) { + return `Mix ${mixId}`; + } + return `${nodeIdentity.slice(0, 6)}...${nodeIdentity.slice(-6)}`; +} diff --git a/nym-wallet/src/utils/unbondedDelegation.fixture.ts b/nym-wallet/src/utils/unbondedDelegation.fixture.ts index 4b2befb28d..5cdb9a949b 100644 --- a/nym-wallet/src/utils/unbondedDelegation.fixture.ts +++ b/nym-wallet/src/utils/unbondedDelegation.fixture.ts @@ -69,3 +69,19 @@ export function buildPendingUndelegateEvent( }, }; } + +export function buildPendingDelegateEvent( + nodeIdentity: string, + mixId: number = EXAMPLE_UNBONDED_MIX_ID, +): WrappedDelegationEvent { + return { + node_identity: nodeIdentity, + event: { + kind: 'Delegate', + mix_id: mixId, + address: EXAMPLE_DELEGATOR_ADDRESS, + amount: { amount: '1000000', denom: 'nym' }, + proxy: null, + }, + }; +}