From 73c782d9ed9a553a0f09f3477efdd39540e14ec6 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Fri, 10 Jan 2025 15:27:45 -0500 Subject: [PATCH] Fix long token symbol overflow (#6391) * truncate symbol, name, and price together * Update src/components/Discover/TrendingTokens.tsx Co-authored-by: Kane Thomas --------- Co-authored-by: Kane Thomas --- src/components/Discover/TrendingTokens.tsx | 66 ++++++++++++++++++---- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/src/components/Discover/TrendingTokens.tsx b/src/components/Discover/TrendingTokens.tsx index d8a597c8208..0a0bb423f49 100644 --- a/src/components/Discover/TrendingTokens.tsx +++ b/src/components/Discover/TrendingTokens.tsx @@ -322,10 +322,33 @@ function getPriceChangeColor(priceChange: number) { return priceChange > 0 ? 'green' : 'red'; } +const TOKEN_LIST_INSET = 20 * 2; +const TOKEN_ICON_WIDTH = 40 + 12; +const TOKEN_PRICE_CHANGE_WIDTH = 75; + +const TOKEN_DETAILS_WIDTH = DEVICE_WIDTH - TOKEN_LIST_INSET - TOKEN_ICON_WIDTH - TOKEN_PRICE_CHANGE_WIDTH; + +function getTextWidths(symbol: string, price: string) { + const minPriceWidth = price.length * 9 + 8; // 9px per character + some padding + + const remainingWidth = TOKEN_DETAILS_WIDTH - minPriceWidth - 12; // 12 for gaps + + const maxSymbolWidth = Math.min(symbol.length * 8 + 16, remainingWidth * 0.3); + + const nameWidth = remainingWidth - maxSymbolWidth; + + return { + nameWidth, + symbolWidth: maxSymbolWidth, + minPriceWidth, + }; +} + function TrendingTokenRow({ token }: { token: TrendingToken }) { const separatorSecondary = useForegroundColor('separatorSecondary'); const price = formatCurrency(token.price); + const { nameWidth, symbolWidth, minPriceWidth } = getTextWidths(token.symbol, price); const marketCap = formatNumber(token.marketCap, { useOrderSuffix: true, decimals: 1, style: '$' }); const volume = formatNumber(token.volume, { useOrderSuffix: true, decimals: 1, style: '$' }); @@ -381,21 +404,44 @@ function TrendingTokenRow({ token }: { token: TrendingToken }) { alignItems: IS_IOS ? 'baseline' : 'flex-end', flexDirection: 'row', gap: 6, - height: 10, - maxWidth: - DEVICE_WIDTH - - 40 - // horizontal list padding - (40 + 12) - // token icon width + 12px gap - 70, // approx. % price change width + height: 12, + width: TOKEN_DETAILS_WIDTH, }} > - + {token.name} - + {token.symbol} - + {price} @@ -423,7 +469,7 @@ function TrendingTokenRow({ token }: { token: TrendingToken }) { - + {formatNumber(token.priceChange.day, { decimals: 2, useOrderSuffix: true })}%