Skip to content

Commit

Permalink
Experiment: add support for sorting against market cap
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Dec 30, 2024
1 parent f5d690f commit 4e1774f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/__swaps__/types/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export type TokenSearchThreshold = 'CONTAINS' | 'CASE_SENSITIVE_EQUAL';

export type TokenSearchListId = 'highLiquidityAssets' | 'lowLiquidityAssets' | 'verifiedAssets';

interface Market {
market_cap: {
value: number;
};
volume_24h: number;
circulating_supply: number;
}

export type SearchAsset = {
address: AddressOrEth;
chainId: ChainId;
Expand All @@ -22,6 +30,7 @@ export type SearchAsset = {
isNativeAsset?: boolean;
isVerified: boolean;
mainnetAddress: AddressOrEth;
market?: Market;
name: string;
networks: {
[chainId in ChainId]?: {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSearchCurrencyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const useSearchCurrencyList = (searchQuery: string) => {
const topResults = results
.sort((a, b) => {
if (a.isNativeAsset !== b.isNativeAsset) return a.isNativeAsset ? -1 : 1;
if (a.market?.market_cap?.value !== b.market?.market_cap?.value)
return (b.market?.market_cap?.value || 0) - (a.market?.market_cap?.value || 0);
if (a.highLiquidity !== b.highLiquidity) return a.highLiquidity ? -1 : 1;
return Object.keys(b.networks).length - Object.keys(a.networks).length;
})
Expand Down

0 comments on commit 4e1774f

Please sign in to comment.