-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swap seach popular in rainbow #1696
base: master
Are you sure you want to change the base?
Changes from 3 commits
fc70db3
3d24e33
b218829
b3e65e3
6859d67
32687d4
d75df08
bf1e49f
8efc4c5
98186b9
8b75994
f33df1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AddressOrEth } from '~/core/types/assets'; | ||
import { ChainId } from '~/core/types/chains'; | ||
import { SearchAsset } from '~/core/types/search'; | ||
import { isNativeAsset } from '~/core/utils/chains'; | ||
|
||
export function parseTokenSearch( | ||
asset: SearchAsset, | ||
chainId: ChainId, | ||
): SearchAsset { | ||
const networkInfo = asset.networks[chainId]; | ||
|
||
return { | ||
...asset, | ||
address: networkInfo ? networkInfo.address : asset.address, | ||
chainId, | ||
decimals: networkInfo ? networkInfo.decimals : asset.decimals, | ||
isNativeAsset: isNativeAsset(asset.address, chainId), | ||
mainnetAddress: asset.uniqueId as AddressOrEth, | ||
uniqueId: `${networkInfo?.address || asset.uniqueId}_${chainId}`, | ||
}; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { createHttpClient } from '~/core/network/internal/createHttpClient'; | ||
import { QueryFunctionArgs, createQueryKey } from '~/core/react-query'; | ||
import { ChainId } from '~/core/types/chains'; | ||
import { SearchAsset } from '~/core/types/search'; | ||
|
||
import { parseTokenSearch } from './parseTokenSearch'; | ||
|
||
const tokenSearchDiscoveryHttp = createHttpClient({ | ||
baseUrl: 'https://token-search.rainbow.me/v3/discovery', | ||
timeout: 30000, | ||
}); | ||
|
||
type TokenDiscoveryArgs = { | ||
chainId: ChainId; | ||
}; | ||
|
||
const tokenDiscoveryQueryKey = ({ chainId }: TokenDiscoveryArgs) => | ||
createQueryKey('TokenDiscovery', { chainId }, { persisterVersion: 1 }); | ||
|
||
async function tokenSearchQueryFunction({ | ||
queryKey: [{ chainId }], | ||
}: QueryFunctionArgs<typeof tokenDiscoveryQueryKey>) { | ||
const url = `/${chainId}`; | ||
|
||
try { | ||
const tokenSearch = await tokenSearchDiscoveryHttp.get<{ | ||
data: SearchAsset[]; | ||
}>(url); | ||
return tokenSearch.data.data.map((asset) => | ||
parseTokenSearch(asset, chainId), | ||
); | ||
} catch (e) { | ||
return []; | ||
} | ||
} | ||
|
||
export function useTokenDiscovery({ chainId }: TokenDiscoveryArgs) { | ||
return useQuery({ | ||
queryKey: tokenDiscoveryQueryKey({ chainId }), | ||
queryFn: tokenSearchQueryFunction, | ||
staleTime: 15 * 60 * 1000, // 15 min | ||
gcTime: 24 * 60 * 60 * 1000, // 1 day | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { Address } from 'viem'; | |
import { SUPPORTED_CHAINS } from '~/core/references/chains'; | ||
import { useAssetSearchMetadataAllNetworks } from '~/core/resources/assets/assetMetadata'; | ||
import { useTokenSearch } from '~/core/resources/search'; | ||
import { useTokenDiscovery } from '~/core/resources/search/tokenDiscovery'; | ||
import { useTokenSearchAllNetworks } from '~/core/resources/search/tokenSearch'; | ||
import { useTestnetModeStore } from '~/core/state/currentSettings/testnetMode'; | ||
import { ParsedSearchAsset } from '~/core/types/assets'; | ||
|
@@ -43,7 +44,8 @@ export type AssetToBuySectionId = | |
| 'favorites' | ||
| 'verified' | ||
| 'unverified' | ||
| 'other_networks'; | ||
| 'other_networks' | ||
| 'popular'; | ||
|
||
export interface AssetToBuySection { | ||
data: SearchAsset[]; | ||
|
@@ -279,6 +281,8 @@ export function useSearchCurrencyLists({ | |
}, | ||
); | ||
|
||
const { data: popularAssets } = useTokenDiscovery({ chainId: outputChainId }); | ||
|
||
const { favorites } = useFavoriteAssets(); | ||
|
||
const favoritesList = useMemo(() => { | ||
|
@@ -508,6 +512,10 @@ export function useSearchCurrencyLists({ | |
return sections; | ||
} | ||
|
||
if (popularAssets) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you need to make sure there is no overlap between assets in the popular section and assets in other sections. here's the app logic https://github.com/rainbow-me/rainbow/blob/develop/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts lmk if you want me to explain more |
||
sections.push({ id: 'popular', data: popularAssets }); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to limit to 3 results like in the app? |
||
if (bridgeAsset) { | ||
sections.push({ | ||
data: [bridgeAsset], | ||
|
@@ -616,6 +624,7 @@ export function useSearchCurrencyLists({ | |
targetUnverifiedAssets, | ||
enableUnverifiedSearch, | ||
crosschainExactMatches, | ||
popularAssets, | ||
]); | ||
|
||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced this with
isNativeAsset
from~/core/utils/chains
, fixes some chains like degen that was not getting the right native