From c3939299d001f1137467897c362c1dd3cc488bfd Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Tue, 25 Mar 2025 12:33:58 -0700 Subject: [PATCH 1/4] fix: init name sort fix --- .../assets/asset-list/sort-control/sort-control.tsx | 8 ++------ .../assets/token-cell/cells/token-cell-title.tsx | 2 ++ ui/components/app/assets/token-list/token-list.tsx | 13 ++++--------- ui/components/app/assets/types.ts | 1 + ui/selectors/assets.ts | 11 ++++++++++- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ui/components/app/assets/asset-list/sort-control/sort-control.tsx b/ui/components/app/assets/asset-list/sort-control/sort-control.tsx index 890c351cc418..40b359217a1e 100644 --- a/ui/components/app/assets/asset-list/sort-control/sort-control.tsx +++ b/ui/components/app/assets/asset-list/sort-control/sort-control.tsx @@ -18,10 +18,7 @@ import { MetaMetricsEventName, MetaMetricsUserTrait, } from '../../../../../../shared/constants/metametrics'; -import { - getIsEvmMultichainNetworkSelected, - getTokenSortConfig, -} from '../../../../../selectors'; +import { getTokenSortConfig } from '../../../../../selectors'; import { getCurrentCurrency } from '../../../../../ducks/metamask/metamask'; import { useI18nContext } from '../../../../../hooks/useI18nContext'; import { getCurrencySymbol } from '../../../../../helpers/utils/common.util'; @@ -79,7 +76,6 @@ const SortControl = ({ handleClose }: SortControlProps) => { const trackEvent = useContext(MetaMetricsContext); const tokenSortConfig = useSelector(getTokenSortConfig); const currentCurrency = useSelector(getCurrentCurrency); - const isEvmSelected = useSelector(getIsEvmMultichainNetworkSelected); const dispatch = useDispatch(); @@ -113,7 +109,7 @@ const SortControl = ({ handleClose }: SortControlProps) => { } onClick={() => // TODO: consolidate name and title fields in token to avoid this switch - handleSort(isEvmSelected ? 'name' : 'title', 'alphaNumeric', 'asc') + handleSort('title', 'alphaNumeric', 'asc') } testId="sortByAlphabetically" > diff --git a/ui/components/app/assets/token-cell/cells/token-cell-title.tsx b/ui/components/app/assets/token-cell/cells/token-cell-title.tsx index 0b311e71d731..2f10e7ca0f23 100644 --- a/ui/components/app/assets/token-cell/cells/token-cell-title.tsx +++ b/ui/components/app/assets/token-cell/cells/token-cell-title.tsx @@ -22,6 +22,8 @@ export const TokenCellTitle = React.memo( ({ token }: TokenCellTitleProps) => { const t = useI18nContext(); + console.log('this: ', token); + if (token.title.length > 12) { return ( { if (sortedFilteredTokens) { endTrace({ name: TraceName.AccountOverviewAssetListTab }); diff --git a/ui/components/app/assets/types.ts b/ui/components/app/assets/types.ts index 6eab815345c3..71ac58203cf9 100644 --- a/ui/components/app/assets/types.ts +++ b/ui/components/app/assets/types.ts @@ -35,6 +35,7 @@ export type NonEvmBaseToken = { // Token type with optional aggregators export type Token = (BaseToken | NonEvmBaseToken) & { aggregators?: string[]; + name?: string; }; // Token with balance and optional display values diff --git a/ui/selectors/assets.ts b/ui/selectors/assets.ts index 350fbef3886c..63c21f436f57 100644 --- a/ui/selectors/assets.ts +++ b/ui/selectors/assets.ts @@ -106,6 +106,7 @@ export const getTokenBalancesEvm = createDeepEqualSelector( const tokenList = tokens as Token[]; tokenList.forEach((token: Token) => { const { isNative, address, decimals } = token; + const balance = calculateTokenBalance({ isNative, @@ -138,6 +139,14 @@ export const getTokenBalancesEvm = createDeepEqualSelector( balance !== '0' || (token.isNative && isOnCurrentNetwork) ) { + // title is used for sorting. We override native ETH to Ethereum + let title; + if (token.isNative) { + title = token.symbol === 'ETH' ? 'Ethereum' : token.symbol; + } else { + title = token.name || token.symbol; + } + tokensWithBalance.push({ ...token, address: token.address as CaipAssetType, @@ -147,7 +156,7 @@ export const getTokenBalancesEvm = createDeepEqualSelector( string: String(balance), primary: '', secondary: 0, - title: '', + title, }); } }); From 250519a3c03c4d6be215b49a13ef61fc58654c8e Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Tue, 25 Mar 2025 12:52:12 -0700 Subject: [PATCH 2/4] fix: Cleanup --- ui/components/app/assets/token-cell/cells/token-cell-title.tsx | 2 -- ui/components/app/assets/token-list/token-list.tsx | 2 -- 2 files changed, 4 deletions(-) diff --git a/ui/components/app/assets/token-cell/cells/token-cell-title.tsx b/ui/components/app/assets/token-cell/cells/token-cell-title.tsx index 2f10e7ca0f23..0b311e71d731 100644 --- a/ui/components/app/assets/token-cell/cells/token-cell-title.tsx +++ b/ui/components/app/assets/token-cell/cells/token-cell-title.tsx @@ -22,8 +22,6 @@ export const TokenCellTitle = React.memo( ({ token }: TokenCellTitleProps) => { const t = useI18nContext(); - console.log('this: ', token); - if (token.title.length > 12) { return ( { if (sortedFilteredTokens) { endTrace({ name: TraceName.AccountOverviewAssetListTab }); From 7d52232b86b051cea9022ff0fc87c8bb3388537e Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Tue, 25 Mar 2025 13:20:56 -0700 Subject: [PATCH 3/4] fix: Update unit test snapshot --- ui/hooks/useMultichainBalances.test.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/hooks/useMultichainBalances.test.ts b/ui/hooks/useMultichainBalances.test.ts index 37a60bdfdf98..4c07dc668c58 100644 --- a/ui/hooks/useMultichainBalances.test.ts +++ b/ui/hooks/useMultichainBalances.test.ts @@ -29,7 +29,7 @@ describe('useMultichainBalances', () => { secondary: 0, string: '0.000000000000000014', symbol: 'ETH', - title: '', + title: 'Ethereum', tokenFiatAmount: 3.53395e-14, type: 'NATIVE', }, @@ -45,7 +45,7 @@ describe('useMultichainBalances', () => { secondary: 0, string: '0.00000000000000001', symbol: 'ETH', - title: '', + title: 'Ethereum', tokenFiatAmount: 2.5242500000000003e-14, type: 'NATIVE', }, @@ -72,7 +72,7 @@ describe('useMultichainBalances', () => { primary: '', secondary: 0, string: '0.00184', - title: '', + title: undefined, tokenFiatAmount: 0.004232, type: 'TOKEN', }, @@ -88,7 +88,7 @@ describe('useMultichainBalances', () => { secondary: 0, string: '0.000000000000000014', symbol: 'ETH', - title: '', + title: 'Ethereum', tokenFiatAmount: 3.53395e-14, type: 'NATIVE', }, @@ -104,7 +104,7 @@ describe('useMultichainBalances', () => { secondary: 0, string: '0.00000000000000001', symbol: 'ETH', - title: '', + title: 'Ethereum', tokenFiatAmount: 2.5242500000000003e-14, type: 'NATIVE', }, @@ -113,24 +113,24 @@ describe('useMultichainBalances', () => { balance: '1', chainId: '0x1', isNative: false, + primary: '', + secondary: 0, string: '1', + title: undefined, tokenFiatAmount: null, type: 'TOKEN', - primary: '', - secondary: 0, - title: '', }, { address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', balance: '0', chainId: '0xe708', isNative: false, + primary: '', + secondary: 0, string: '0', + title: undefined, tokenFiatAmount: null, type: 'TOKEN', - primary: '', - secondary: 0, - title: '', }, ]), ); From 75953252abccdd39e0809fd8ff7fddf0ded15875 Mon Sep 17 00:00:00 2001 From: Nicholas Gambino Date: Tue, 25 Mar 2025 13:53:37 -0700 Subject: [PATCH 4/4] chore: trigger CI