From 4ec26ca297fc0ca835d2ae13ffc74e97ad0eaaaa Mon Sep 17 00:00:00 2001 From: mikasa Date: Sun, 3 Aug 2025 13:36:53 +0000 Subject: [PATCH] fix: handle long names and numbers --- .../common/Table/cells/TokenCell.tsx | 67 ++++++++++++++----- src/hooks/useIsTruncated.ts | 22 ++++++ 2 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 src/hooks/useIsTruncated.ts diff --git a/src/components/common/Table/cells/TokenCell.tsx b/src/components/common/Table/cells/TokenCell.tsx index 2dcda6e..6affc5d 100644 --- a/src/components/common/Table/cells/TokenCell.tsx +++ b/src/components/common/Table/cells/TokenCell.tsx @@ -1,10 +1,22 @@ /* eslint-disable @next/next/no-img-element */ +'use client'; + import { DEFAULT_TOKEN_LOGO } from 'src/constant'; import { CellProps } from '../Table.type'; +import { InfoIcon } from 'src/components/icons'; +import Tooltip from '../../Tooltip'; +import { useRef } from 'react'; +import useIsTruncated from 'src/hooks/useIsTruncated'; function TokenCell(props: CellProps) { const { swapItem, column } = props; const { stepsSummary } = swapItem; + const amountRef = useRef(null); + const tokenNameRef = useRef(null); + + const showAmountTooltip = useIsTruncated(amountRef); + const showTokenNameTooltip = useIsTruncated(tokenNameRef); + const firstStep = stepsSummary.length ? stepsSummary[0] : null; const lastStep = stepsSummary.length ? stepsSummary[stepsSummary.length - 1] @@ -19,6 +31,13 @@ function TokenCell(props: CellProps) { const { shortName: blockchainShortName, logo: blockchainLogo } = blockchainData || {}; + const amount = token?.realAmount || token?.expectedAmount; + + const roundedAmount = parseFloat( + Number(token?.realAmount || token?.expectedAmount).toFixed(3), + ); + const tokenName = symbol || name; + return ( <> {column.tokenType === 'source' ? ( @@ -26,7 +45,7 @@ function TokenCell(props: CellProps) { ) : (
)} -
+
-
-
- - {`${!token?.realAmount ? '~' : ''}${parseFloat( - Number(token?.realAmount || token?.expectedAmount).toFixed(3), - )}`} - - - {symbol || name} - +
+
+
+ + {`${!token?.realAmount ? '~' : ''}${roundedAmount}`} + + {amount && showAmountTooltip && ( + + + + )} +
+
+ + {tokenName} + + {tokenName && showTokenNameTooltip && ( + + + + )} +
{blockchainShortName} diff --git a/src/hooks/useIsTruncated.ts b/src/hooks/useIsTruncated.ts new file mode 100644 index 0000000..22c2cb3 --- /dev/null +++ b/src/hooks/useIsTruncated.ts @@ -0,0 +1,22 @@ +import { useEffect, useState, RefObject } from 'react'; + +function useIsTruncated(ref: RefObject): boolean { + const [isTruncated, setIsTruncated] = useState(false); + + useEffect(() => { + const element = ref.current; + if (!element) return; + + const resizeObserver = new ResizeObserver(() => { + setIsTruncated(element.scrollWidth > element.clientWidth); + }); + + resizeObserver.observe(element); + + return () => resizeObserver.disconnect(); + }, [ref]); + + return isTruncated; +} + +export default useIsTruncated;