Skip to content

Commit 2015bba

Browse files
authored
feat(dapp): enhance formatName and create TruncatedNameWithTooltip (#481)
1 parent e9510a7 commit 2015bba

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2025 IOTA Stiftung
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Tooltip, TooltipPosition } from '@iota/apps-ui-kit';
5+
import { normalizeIotaName } from '@iota/iota-names-sdk';
6+
7+
interface TruncatedNameWithTooltipProps {
8+
name: string;
9+
tooltipPosition?: TooltipPosition;
10+
}
11+
12+
export function TruncatedNameWithTooltip({
13+
name,
14+
tooltipPosition = TooltipPosition.Bottom,
15+
}: TruncatedNameWithTooltipProps) {
16+
const truncated = normalizeIotaName(name, 'at', { truncateLongParts: true });
17+
const full = normalizeIotaName(name, 'at', { truncateLongParts: false });
18+
const showTooltip = truncated !== full;
19+
20+
const content = <span>{truncated}</span>;
21+
22+
return showTooltip ? (
23+
<Tooltip text={full} position={tooltipPosition}>
24+
{content}
25+
</Tooltip>
26+
) : (
27+
content
28+
);
29+
}

dapp/src/components/dialogs/ConnectToAddressDialog.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
InputType,
2424
LoadingIndicator,
2525
Panel,
26+
TooltipPosition,
2627
} from '@iota/apps-ui-kit';
2728
import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '@iota/dapp-kit';
2829
import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
@@ -36,6 +37,8 @@ import { NameUpdate, useUpdateNameTransaction } from '@/hooks/useUpdateNameTrans
3637
import { copyToClipboard } from '@/lib/utils/copyToClipboard';
3738
import { getNameObject, isNameRecordExpired } from '@/lib/utils/names';
3839

40+
import { TruncatedNameWithTooltip } from '../TruncatedNameWithTooltip';
41+
3942
interface ConnectToAddressDialogProps {
4043
name: string;
4144
setOpen: (open: boolean) => void;
@@ -189,7 +192,7 @@ export function ConnectToAddressDialog({ name, setOpen }: ConnectToAddressDialog
189192
</span>
190193
<Input
191194
type={InputType.Text}
192-
label={`Select a target address to connect to @${cleanName}`}
195+
label={`Select a target address to connect to ${cleanName}`}
193196
placeholder="Enter Address"
194197
value={editTargetAddress}
195198
onChange={handleAddressChange}
@@ -259,7 +262,12 @@ export function ConnectToAddressDialog({ name, setOpen }: ConnectToAddressDialog
259262
<Panel hasBorder bgColor="bg-names-neutral-10">
260263
<div className="flex flex-col items-center gap-y-xxs py-md px-xs">
261264
<span className="text-title-lg text-names-neutral-100">
262-
{cleanName}
265+
<TruncatedNameWithTooltip
266+
name={name}
267+
tooltipPosition={
268+
TooltipPosition.Top
269+
}
270+
/>
263271
</span>
264272
<Chip
265273
label={formatAddress(

dapp/src/components/dialogs/CreateSubnameDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export function CreateSubnameDialog({ name, setOpen }: CreateSubnameProps) {
168168
!editSubname.trim() ||
169169
editSubname.length < MIN_LABEL_SIZE;
170170

171+
const cleanName = normalizeIotaName(name, 'at', { truncateLongParts: true });
172+
171173
return (
172174
<Dialog open onOpenChange={setOpen}>
173175
<DialogContent containerId="overlay-portal-container" position={DialogPosition.Right}>
@@ -179,7 +181,7 @@ export function CreateSubnameDialog({ name, setOpen }: CreateSubnameProps) {
179181
type={InfoBoxType.Default}
180182
style={InfoBoxStyle.Elevated}
181183
icon={<Info />}
182-
supportingText={`Create as many Subnames as you want under ${normalizeIotaName(name)}, each with its own profile page and features`}
184+
supportingText={`Create as many Subnames as you want under ${cleanName}, each with its own profile page and features`}
183185
/>
184186
<Input
185187
type={InputType.Text}

dapp/src/components/dialogs/GeneralInfoDialog.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ import {
1111
Header,
1212
KeyValueInfo,
1313
TitleSize,
14+
TooltipPosition,
1415
truncate,
1516
} from '@iota/apps-ui-kit';
1617
import { useCurrentAccount } from '@iota/dapp-kit';
17-
import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
18+
import { isSubname } from '@iota/iota-names-sdk';
1819
import Link from 'next/link';
1920

2021
import { NameRecordData, useNameRecord, useRegistrationNfts } from '@/hooks';
2122
import { formatDate } from '@/lib/utils/format/formatDate';
2223

2324
import { Collapsible } from '../Collapsible';
2425
import { AvatarDisplay } from '../name-record/AvatarDisplay';
26+
import { TruncatedNameWithTooltip } from '../TruncatedNameWithTooltip';
2527

2628
interface InfoLinks {
2729
key: string;
@@ -81,7 +83,10 @@ export function GeneralInfoDialog({ name, setOpen }: GeneralInfoDialogProps) {
8183
<div className="flex flex-col justify-center items-center gap-lg">
8284
<AvatarDisplay name={name} />
8385
<span className="text-headline-sm text-names-neutral-92 break-words max-w-full">
84-
{normalizeIotaName(name)}
86+
<TruncatedNameWithTooltip
87+
name={name}
88+
tooltipPosition={TooltipPosition.Bottom}
89+
/>
8590
</span>
8691
</div>
8792
<div className="flex flex-col gap-md mt-lg">

dapp/src/components/dialogs/PersonalizeAvatarDialog.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import {
1414
InfoBoxStyle,
1515
InfoBoxType,
1616
LoadingIndicator,
17+
TooltipPosition,
1718
VisualAssetCard,
1819
} from '@iota/apps-ui-kit';
1920
import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '@iota/dapp-kit';
20-
import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
21+
import { isSubname } from '@iota/iota-names-sdk';
2122
import { useMutation, useQueryClient } from '@tanstack/react-query';
2223
import { useState } from 'react';
2324

@@ -33,6 +34,8 @@ import { useGetVisualAssets } from '@/hooks/useGetVisualAssets';
3334
import { getNameObject } from '@/lib/utils/names';
3435
import { BrandedAssets } from '@/public/icons';
3536

37+
import { TruncatedNameWithTooltip } from '../TruncatedNameWithTooltip';
38+
3639
interface PersonalizeAvatarDialogProps {
3740
name: string;
3841
setOpen: (bool: boolean) => void;
@@ -116,7 +119,10 @@ export function PersonalizeAvatarDialog({ name, setOpen }: PersonalizeAvatarDial
116119
<BrandedAssets className="w-12 h-12" />
117120
<div className="flex flex-col gap-xs text-center">
118121
<span className="text-title-md text-names-neutral-92">
119-
{normalizeIotaName(name)}
122+
<TruncatedNameWithTooltip
123+
name={name}
124+
tooltipPosition={TooltipPosition.Top}
125+
/>
120126
</span>
121127
<span className="text-body-md text-names-neutral-70">
122128
Use an NFT to personalize your avatar

0 commit comments

Comments
 (0)