1
1
import { cssObj } from '@fuel-ui/css' ;
2
- import { Avatar , Box , Card , Heading , Icon , Image , Text } from '@fuel-ui/react' ;
2
+ import {
3
+ Avatar ,
4
+ Box ,
5
+ Card ,
6
+ Heading ,
7
+ Icon ,
8
+ Image ,
9
+ Text ,
10
+ Tooltip ,
11
+ } from '@fuel-ui/react' ;
3
12
import type { OperationTransactionAddress } from 'fuels' ;
4
13
import { Address , AddressType , ChainName , isB256 , isBech32 } from 'fuels' ;
5
- import { type FC , useMemo } from 'react' ;
14
+ import { type FC , useEffect , useMemo , useRef , useState } from 'react' ;
6
15
import { EthAddress , FuelAddress , useAccounts } from '~/systems/Account' ;
7
16
8
17
import { useContractMetadata } from '~/systems/Contract/hooks/useContractMetadata' ;
@@ -33,6 +42,8 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
33
42
const isNetwork = address === 'Network' ;
34
43
35
44
const contract = useContractMetadata ( address ) ;
45
+ const nameRef = useRef < HTMLHeadingElement > ( null ) ;
46
+ const [ isTruncated , setIsTruncated ] = useState ( false ) ;
36
47
37
48
const name = useMemo < string > ( ( ) => {
38
49
if ( isContract ) {
@@ -42,6 +53,23 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
42
53
return accounts ?. find ( ( a ) => a . address === fuelAddress ) ?. name || 'unknown' ;
43
54
} , [ isContract , contract , accounts , fuelAddress ] ) ;
44
55
56
+ useEffect ( ( ) => {
57
+ const checkIfTruncated = ( ) => {
58
+ if ( nameRef . current ) {
59
+ const isNameTruncated =
60
+ nameRef . current . offsetWidth < nameRef . current . scrollWidth ;
61
+ setIsTruncated ( isNameTruncated ) ;
62
+ }
63
+ } ;
64
+
65
+ checkIfTruncated ( ) ;
66
+ window . addEventListener ( 'resize' , checkIfTruncated ) ;
67
+
68
+ return ( ) => {
69
+ window . removeEventListener ( 'resize' , checkIfTruncated ) ;
70
+ } ;
71
+ } , [ name ] ) ;
72
+
45
73
return (
46
74
< Card
47
75
css = { styles . root }
@@ -97,7 +125,19 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
97
125
isNetwork ? 'Address' : 'Name'
98
126
} `}
99
127
>
100
- { isNetwork ? address : name }
128
+ < Tooltip content = { name } open = { isTruncated ? undefined : false } >
129
+ < div
130
+ ref = { nameRef }
131
+ style = { {
132
+ textOverflow : 'ellipsis' ,
133
+ whiteSpace : 'nowrap' ,
134
+ overflow : 'hidden' ,
135
+ maxWidth : '100px' ,
136
+ } }
137
+ >
138
+ { name }
139
+ </ div >
140
+ </ Tooltip >
101
141
</ Heading >
102
142
{ ! isNetwork && (
103
143
< FuelAddress
0 commit comments