Skip to content

Commit f9f5c11

Browse files
fix(frontend): add tooltips and improved unknown token icons in swap tracker (#79)
1 parent 368acfb commit f9f5c11

File tree

2 files changed

+74
-13
lines changed

2 files changed

+74
-13
lines changed
Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import Image from 'next/image'
2+
import {
3+
Tooltip,
4+
TooltipContent,
5+
TooltipTrigger,
6+
} from '@/components/ui/tooltip'
27
import { getTokenFromList } from '@/lib/token-list'
8+
import { cn, shortenHex } from '@/lib/utils'
9+
import { UnknownTokenIcon } from './unknown-token-icon'
310

411
interface TokenIconProps {
512
address?: string
@@ -14,26 +21,50 @@ export function TokenIcon({
1421
}: TokenIconProps) {
1522
const token = address ? getTokenFromList(address) : null
1623
const logoURI = token?.logoURI
24+
const name = token?.name
1725
const symbol = token?.symbol
1826

27+
const getTooltipText = () => {
28+
if (name) return name
29+
if (symbol) return symbol
30+
if (address) return shortenHex(address)
31+
return 'Unknown token'
32+
}
33+
34+
const getAltText = () => {
35+
if (symbol) return symbol.slice(0, 2).toUpperCase()
36+
return 'Unknown token'
37+
}
38+
39+
// If we have a logo URI, show the image
1940
if (logoURI) {
2041
return (
21-
<Image
22-
src={logoURI}
23-
alt={symbol ?? ''}
24-
width={size}
25-
height={size}
26-
className={`rounded-full ${className}`}
27-
/>
42+
<Tooltip>
43+
<TooltipTrigger asChild>
44+
<Image
45+
src={logoURI}
46+
alt={getAltText()}
47+
width={size}
48+
height={size}
49+
className={cn('rounded-full', className)}
50+
/>
51+
</TooltipTrigger>
52+
<TooltipContent sideOffset={5}>
53+
<p>{getTooltipText()}</p>
54+
</TooltipContent>
55+
</Tooltip>
2856
)
2957
}
3058

31-
// Gray circle placeholder when no logo is available
59+
// For unknown tokens, use the UnknownTokenIcon component
3260
return (
33-
<div
34-
className={`rounded-full bg-zinc-600 ${className}`}
35-
style={{ width: size, height: size }}
36-
title={symbol ?? ''}
37-
/>
61+
<Tooltip>
62+
<TooltipTrigger>
63+
<UnknownTokenIcon symbol={symbol} size={size} className={className} />
64+
</TooltipTrigger>
65+
<TooltipContent sideOffset={5}>
66+
<p>{getTooltipText()}</p>
67+
</TooltipContent>
68+
</Tooltip>
3869
)
3970
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { cn } from '@/lib/utils'
2+
3+
interface UnknownTokenIconProps {
4+
symbol?: string
5+
size?: number
6+
className?: string
7+
}
8+
9+
export function UnknownTokenIcon({
10+
symbol,
11+
size = 16,
12+
className,
13+
}: UnknownTokenIconProps) {
14+
const displayText = symbol ? symbol.slice(0, 2).toUpperCase() : '?'
15+
const textSize =
16+
size <= 16 ? 'text-[0.5625rem]' : size <= 24 ? 'text-xs' : 'text-sm'
17+
18+
return (
19+
<div
20+
className={cn(
21+
'flex items-center justify-center rounded-full bg-muted text-muted-foreground font-medium select-none shrink-0',
22+
textSize,
23+
className,
24+
)}
25+
style={{ width: size, height: size }}
26+
>
27+
{displayText}
28+
</div>
29+
)
30+
}

0 commit comments

Comments
 (0)