Skip to content

Commit

Permalink
fix long recipient name and undo formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhanraj30 committed Jan 7, 2025
1 parent 4c53007 commit 66f6126
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,6 +42,8 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
const isNetwork = address === 'Network';

const contract = useContractMetadata(address);
const nameRef = useRef<HTMLHeadingElement>(null);
const [isTruncated, setIsTruncated] = useState(false);

const name = useMemo<string>(() => {
if (isContract) {
Expand All @@ -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 (
<Card
css={styles.root}
Expand Down Expand Up @@ -97,7 +127,19 @@ export const TxRecipientCard: TxRecipientCardComponent = ({
isNetwork ? 'Address' : 'Name'
}`}
>
{isNetwork ? address : name}
<Tooltip content={name} isOpen={isTruncated}>
<div
ref={nameRef}
style={{
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
maxWidth: '200px',
}}
>
{truncatedName}
</div>
</Tooltip>
</Heading>
{!isNetwork && (
<FuelAddress
Expand Down

0 comments on commit 66f6126

Please sign in to comment.