-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseStocksFeed.ts
More file actions
40 lines (33 loc) · 1.24 KB
/
useStocksFeed.ts
File metadata and controls
40 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useMemo } from 'react';
import type { TrendingAsset } from '@metamask/assets-controllers';
import { useRwaTokens } from '../../../../UI/Trending/hooks/useRwaTokens/useRwaTokens';
import { useFeedRefresh } from '../../hooks/useFeedRefresh';
import type { RefreshConfig } from '../../hooks/useExploreRefresh';
const ETHEREUM_CAIP_CHAIN_ID = 'eip155:1/';
interface UseStocksFeedOptions {
query?: string;
refresh?: RefreshConfig;
}
export interface UseStocksFeedResult {
data: TrendingAsset[];
isLoading: boolean;
refetch: () => Promise<void>;
}
/** Tokenized stocks (RWAs). Only Ethereum mainnet tokens are shown in the section. */
export const useStocksFeed = ({
query,
refresh,
}: UseStocksFeedOptions = {}): UseStocksFeedResult => {
const { data, isLoading, refetch } = useRwaTokens({
searchQuery: query,
});
// Keep mainnet filtering here (not in the request) so all surfaces share the same
// RWA cache (server-side); chain-specific params would split the cache and diverge from the main feed.
const ethereumData = useMemo(
() =>
data.filter((asset) => asset.assetId.startsWith(ETHEREUM_CAIP_CHAIN_ID)),
[data],
);
useFeedRefresh(refresh, refetch);
return { data: ethereumData, isLoading, refetch };
};