From 66f6126171536a287675b70f2a81fe3566b05f3a Mon Sep 17 00:00:00 2001 From: Dhanraj30 Date: Tue, 7 Jan 2025 15:07:54 +0530 Subject: [PATCH] fix long recipient name and undo formatting --- .../TxRecipientCard/TxRecipientCard.tsx | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/packages/app/src/systems/Transaction/components/TxRecipientCard/TxRecipientCard.tsx b/packages/app/src/systems/Transaction/components/TxRecipientCard/TxRecipientCard.tsx index 80c03a39e..235cacbdd 100644 --- a/packages/app/src/systems/Transaction/components/TxRecipientCard/TxRecipientCard.tsx +++ b/packages/app/src/systems/Transaction/components/TxRecipientCard/TxRecipientCard.tsx @@ -1,8 +1,17 @@ import { cssObj } from '@fuel-ui/css'; -import { Avatar, Box, Card, Heading, Icon, Image, Text } from '@fuel-ui/react'; +import { + Avatar, + Box, + Card, + Heading, + Icon, + Image, + Text, + Tooltip, +} from '@fuel-ui/react'; import type { OperationTransactionAddress } from 'fuels'; import { Address, AddressType, ChainName, isB256, isBech32 } from 'fuels'; -import { type FC, useMemo } from 'react'; +import { type FC, useEffect, useMemo, useRef, useState } from 'react'; import { EthAddress, FuelAddress, useAccounts } from '~/systems/Account'; import { useContractMetadata } from '~/systems/Contract/hooks/useContractMetadata'; @@ -33,6 +42,8 @@ export const TxRecipientCard: TxRecipientCardComponent = ({ const isNetwork = address === 'Network'; const contract = useContractMetadata(address); + const nameRef = useRef(null); + const [isTruncated, setIsTruncated] = useState(false); const name = useMemo(() => { if (isContract) { @@ -42,6 +53,25 @@ export const TxRecipientCard: TxRecipientCardComponent = ({ return accounts?.find((a) => a.address === fuelAddress)?.name || 'unknown'; }, [isContract, contract, accounts, fuelAddress]); + useEffect(() => { + const checkIfTruncated = () => { + if (nameRef.current) { + const isNameTruncated = + nameRef.current.offsetWidth < nameRef.current.scrollWidth; + setIsTruncated(isNameTruncated); + } + }; + + checkIfTruncated(); + window.addEventListener('resize', checkIfTruncated); + + return () => { + window.removeEventListener('resize', checkIfTruncated); + }; + }, [name]); + + const truncatedName = name.length > 15 ? `${name.slice(0, 15)}...` : name; + return ( - {isNetwork ? address : name} + +
+ {truncatedName} +
+
{!isNetwork && (