11import React , { Fragment , useMemo } from 'react' ;
2- import { Box , Card , CardContent , Skeleton , useTheme } from '@mui/material' ;
3- import CircularProgress from '@mui/material/CircularProgress' ;
4- import ListItemButton from '@mui/material/ListItemButton' ;
2+ import { Card , CardContent , useTheme } from '@mui/material' ;
53import Typography from '@mui/material/Typography' ;
6-
74import type { ChainConfig } from 'config/types' ;
85import type { Token } from 'config/tokens' ;
96import type { WalletData } from 'store/wallet' ;
107import SearchableList from 'views/v3/Bridge/AssetPicker/SearchableList' ;
118import TokenItem from 'views/v3/Bridge/AssetPicker/TokenItem' ;
129import { getUSDFormat , calculateUSDPriceRaw } from 'utils' ;
1310import config from 'config' ;
14- import { useTokens } from 'contexts/TokensContext' ;
1511import type { Balances } from 'utils/wallet/types' ;
1612import { useTokenListWithSearch } from 'hooks/useTokenListWithSearch' ;
1713import TokenSectionHeader from './TokenSectionHeader' ;
@@ -38,7 +34,6 @@ type Props = {
3834const TokenList = ( props : Props ) => {
3935 const theme = useTheme ( ) ;
4036 const tokenPastingIsEnabled = config . ui . disableUserInputtedTokens !== true ;
41- const { isFetchingToken } = useTokens ( ) ;
4237
4338 const { sortedTokens, tokenPrices } = useTokenListWithSearch ( {
4439 baseTokenList : props . tokenList ,
@@ -87,10 +82,10 @@ const TokenList = (props: Props) => {
8782 fontSize : 14 ,
8883 marginBottom : '8px' ,
8984 } ,
90- tokenLoader : {
91- padding : 0 ,
85+ tokenLoaderRow : {
9286 display : 'flex' ,
9387 justifyContent : 'space-between' ,
88+ padding : '8px 16px' ,
9489 } ,
9590 tokenList : {
9691 maxHeight : '360px' ,
@@ -118,9 +113,6 @@ const TokenList = (props: Props) => {
118113 return 'ready' ;
119114 } , [ props . isFetching , sortedTokens . length ] ) ;
120115
121- const shouldShowLoadingState = listState === 'loading' ;
122- const shouldShowEmptyMessage = listState === 'empty' ;
123-
124116 // Build sectioned list for source picker when not searching
125117 const isGroupingEnabled = props . isSource && ! props . searchQuery ;
126118 const isWalletConnected = Boolean ( props . wallet ?. address ) ;
@@ -132,76 +124,52 @@ const TokenList = (props: Props) => {
132124 balances : props . balances ,
133125 } ) ;
134126
135- const searchList = (
136- < SearchableList < Token >
137- searchPlaceholder = { placeholder }
138- sx = { styles . tokenList }
139- dataTestId = "token-search-list"
140- searchQuery = { props . searchQuery }
141- listTitle = { shouldShowEmptyMessage ? emptyMessage : '' }
142- loading = {
143- shouldShowLoadingState &&
144- [ 1 , 2 , 3 ] . map ( ( x ) => (
145- < ListItemButton sx = { styles . tokenLoader } dense key = { x } >
146- < Box padding = "8px 16px" >
147- < Skeleton variant = "circular" width = "36px" height = "36px" />
148- </ Box >
149- </ ListItemButton >
150- ) )
151- }
152- items = { listItems }
153- onQueryChange = { ( query ) => {
154- props . onSearchQueryChange ( query ) ;
155- } }
156- renderFn = { ( token : Token , index : number ) => {
157- const balance = props . balances ?. [ token . key ] ?. balance ;
158- const tokenPrice = tokenPrices . get ( token . key ) ;
159- const price =
160- balance && tokenPrice !== undefined
161- ? getUSDFormat ( calculateUSDPriceRaw ( tokenPrice , balance , token ) )
162- : null ;
163-
164- // Do not dim when no wallet is connected
165- const isRestSection =
166- isGroupingEnabled && isWalletConnected && index >= ownedCount ;
167-
168- return (
169- < Fragment key = { token . key } >
170- < TokenSectionHeader
171- index = { index }
172- ownedCount = { ownedCount }
173- isGroupingEnabled = { isGroupingEnabled }
174- />
175- < TokenItem
176- key = { token . key }
177- token = { token }
178- chain = { props . selectedChainConfig . sdkName }
179- onClick = { ( ) => props . onSelectToken ( token ) }
180- isSource = { props . isSource }
181- balance = { balance }
182- price = { price }
183- isSelected = { token . key === props . selectedToken ?. key }
184- isFetchingBalance = { props . isFetchingBalances }
185- isDimmed = { isRestSection }
186- />
187- </ Fragment >
188- ) ;
189- } }
190- />
191- ) ;
192-
193127 return (
194128 < Card sx = { styles . card } variant = "elevation" >
195129 < CardContent sx = { styles . tokenListContainer } >
196- < Box sx = { { display : 'flex' , padding : '0 16px' } } >
197- { isFetchingToken || props . isFetchingBalances ? (
198- < CircularProgress
199- sx = { { alignSelf : 'flex-end' , marginBottom : '12px' } }
200- size = { 14 }
201- />
202- ) : null }
203- </ Box >
204- { searchList }
130+ < SearchableList < Token >
131+ searchPlaceholder = { placeholder }
132+ sx = { styles . tokenList }
133+ dataTestId = "token-search-list"
134+ searchQuery = { props . searchQuery }
135+ listTitle = { listState === 'empty' ? emptyMessage : '' }
136+ items = { listItems }
137+ onQueryChange = { props . onSearchQueryChange }
138+ renderFn = { ( token : Token , index : number ) => {
139+ const balance = props . balances ?. [ token . key ] ?. balance ;
140+ const tokenPrice = tokenPrices . get ( token . key ) ;
141+ const price =
142+ balance && tokenPrice !== undefined
143+ ? getUSDFormat ( calculateUSDPriceRaw ( tokenPrice , balance , token ) )
144+ : null ;
145+
146+ // Do not dim when no wallet is connected
147+ const isRestSection =
148+ isGroupingEnabled && isWalletConnected && index >= ownedCount ;
149+
150+ return (
151+ < Fragment key = { token . key } >
152+ < TokenSectionHeader
153+ index = { index }
154+ ownedCount = { ownedCount }
155+ isGroupingEnabled = { isGroupingEnabled }
156+ />
157+ < TokenItem
158+ key = { token . key }
159+ token = { token }
160+ chain = { props . selectedChainConfig . sdkName }
161+ onClick = { ( ) => props . onSelectToken ( token ) }
162+ isSource = { props . isSource }
163+ balance = { balance }
164+ price = { price }
165+ isSelected = { token . key === props . selectedToken ?. key }
166+ isFetchingBalance = { props . isFetchingBalances }
167+ isDimmed = { isRestSection }
168+ />
169+ </ Fragment >
170+ ) ;
171+ } }
172+ />
205173 </ CardContent >
206174 </ Card >
207175 ) ;
0 commit comments