Skip to content

Commit

Permalink
Update RainbowToken search result to SearchAsset for imported asset r…
Browse files Browse the repository at this point in the history
…esult
  • Loading branch information
jinchung committed Dec 30, 2024
1 parent 35ab396 commit c9b9fa8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/__swaps__/screens/Swap/resources/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Contract } from '@ethersproject/contracts';
import { useQuery } from '@tanstack/react-query';
import qs from 'qs';
import { parseTokenSearch } from './utils';
import { RainbowToken } from '@/entities';
import { getProvider } from '@/handlers/web3';
import { erc20ABI } from '@/references';

Expand Down Expand Up @@ -65,7 +64,7 @@ type TokenSearchAllNetworksQueryKey = ReturnType<typeof tokenSearchAllNetworksQu

// ///////////////////////////////////////////////
// Query Function
const getImportedAsset = async (searchQuery: string, chainId: number = ChainId.mainnet): Promise<RainbowToken[] | null> => {
const getImportedAsset = async (searchQuery: string, chainId: number = ChainId.mainnet): Promise<SearchAsset[]> => {
if (isAddress(searchQuery)) {
const provider = getProvider({ chainId });
const tokenContract = new Contract(searchQuery, erc20ABI, provider);
Expand All @@ -83,10 +82,10 @@ const getImportedAsset = async (searchQuery: string, chainId: number = ChainId.m
chainId,
address,
decimals,
favorite: false,
highLiquidity: false,
isRainbowCurated: false,
isVerified: false,
mainnetAddress: address,
name,
networks: {
[chainId]: {
Expand All @@ -95,16 +94,15 @@ const getImportedAsset = async (searchQuery: string, chainId: number = ChainId.m
},
},
symbol,
network: useBackendNetworksStore.getState().getChainsName()[chainId],
uniqueId,
} as RainbowToken,
} as SearchAsset,
];
} catch (e) {
logger.warn('[useSearchCurrencyList]: error getting token data', { error: (e as Error).message });
return null;
logger.warn('[getImportedAsset]: error getting imported token data', { error: (e as Error).message });
return [];
}
}
return null;
return [];
};

async function tokenSearchQueryFunction({
Expand Down Expand Up @@ -179,7 +177,8 @@ async function tokenSearchQueryFunctionAllNetworks({ queryKey: [{ query }] }: Qu
return parseTokenSearch(tokenSearch.data.data);
}

return [];
const result = await getImportedAsset(query);
return result;
} else {
const tokenSearch = await tokenSearchHttp.get<{ data: SearchAsset[] }>(url);
return parseTokenSearch(tokenSearch.data.data);
Expand Down

0 comments on commit c9b9fa8

Please sign in to comment.