Skip to content

Commit

Permalink
Improve loading state for external tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ted-palmer committed Oct 23, 2024
1 parent 631f997 commit a73cfa3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
40 changes: 21 additions & 19 deletions packages/ui/src/components/common/TokenSelector/TokenSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,26 @@ const TokenSelector: FC<TokenSelectorProps> = ({
}
)

const { data: externalTokenList } = useTokenList(
relayClient?.baseApiUrl,
{
chainIds: chainFilter.id ? [chainFilter.id] : configuredChainIds,
address: isAddress(debouncedTokenSearchValue)
? debouncedTokenSearchValue
: undefined,
term: !isAddress(debouncedTokenSearchValue)
? debouncedTokenSearchValue
: undefined,
defaultList: false,
limit: 20,
...(tokenListQuery ? { tokens: tokenListQuery } : {}),
useExternalSearch: true
},
{
enabled: !!debouncedTokenSearchValue
}
)
const { data: externalTokenList, isLoading: isLoadingExternalTokenList } =
useTokenList(
relayClient?.baseApiUrl,
{
chainIds: chainFilter.id ? [chainFilter.id] : configuredChainIds,
address: isAddress(debouncedTokenSearchValue)
? debouncedTokenSearchValue
: undefined,
term: !isAddress(debouncedTokenSearchValue)
? debouncedTokenSearchValue
: undefined,
defaultList: false,
limit: 20,
...(tokenListQuery ? { tokens: tokenListQuery } : {}),
useExternalSearch: true
},
{
enabled: !!debouncedTokenSearchValue
}
)

const {
data: duneTokens,
Expand Down Expand Up @@ -562,6 +563,7 @@ const TokenSelector: FC<TokenSelectorProps> = ({
chainFilter={chainFilter}
setChainFilter={setChainFilter}
isLoading={isLoading}
isLoadingExternalTokenList={isLoadingExternalTokenList}
isLoadingDuneBalances={isLoadingDuneBalances}
enhancedCurrencyList={
enhancedCurrencyList as EnhancedCurrencyList[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type SetCurrencyProps = {
chainFilter: ChainFilterValue
setChainFilter: (value: React.SetStateAction<ChainFilterValue>) => void
isLoading: boolean
isLoadingExternalTokenList: boolean
isLoadingDuneBalances: boolean
enhancedCurrencyList?: EnhancedCurrencyList[]
token?: Token
Expand Down Expand Up @@ -77,6 +78,7 @@ export const SetCurrencyStep: FC<SetCurrencyProps> = ({
chainFilter,
setChainFilter,
isLoading,
isLoadingExternalTokenList,
isLoadingDuneBalances,
enhancedCurrencyList,
selectToken,
Expand Down Expand Up @@ -401,6 +403,7 @@ export const SetCurrencyStep: FC<SetCurrencyProps> = ({
/>
</Flex>
) : null}

{/* Data State */}
{!isLoading &&
enhancedCurrencyList &&
Expand Down Expand Up @@ -429,8 +432,25 @@ export const SetCurrencyStep: FC<SetCurrencyProps> = ({
}
})
: null}

{/* External Token List Loading State */}
{!isLoading && isLoadingExternalTokenList ? (
<Flex direction="column" align="center" css={{ py: '5' }}>
{enhancedCurrencyList && enhancedCurrencyList?.length > 0 ? (
<Text style="subtitle2" css={{ color: 'primary-color' }}>
Searching for additional tokens...
</Text>
) : (
<LoadingSpinner
css={{ height: 40, width: 40, fill: 'primary-color' }}
/>
)}
</Flex>
) : null}

{/* Empty State */}
{!isLoading &&
!isLoadingExternalTokenList &&
(!enhancedCurrencyList || enhancedCurrencyList?.length === 0) ? (
<Text css={{ textAlign: 'center', py: '5' }}>
No results found.
Expand Down

0 comments on commit a73cfa3

Please sign in to comment.