MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / useAssetSearch

Function useAssetSearch

ui/src/components/market/useAssetSearch.ts:11–35  ·  view source on GitHub ↗
(query: string, limit = 24)

Source from the content-addressed store, hash-verified

9 * merged. Pick a result → open the chart on exactly that source.
10 */
11export function useAssetSearch(query: string, limit = 24): { results: BarSourceCandidate[]; loading: boolean } {
12 const [results, setResults] = useState<BarSourceCandidate[]>([])
13 const [loading, setLoading] = useState(false)
14
15 useEffect(() => {
16 const q = query.trim()
17 if (!q) { setResults([]); setLoading(false); return }
18 setLoading(true)
19 let cancelled = false
20 const timer = setTimeout(async () => {
21 try {
22 const res = await barsApi.searchSources(q, limit)
23 if (!cancelled) setResults(res.candidates)
24 } catch (e) {
25 console.error('asset search failed', e)
26 if (!cancelled) setResults([])
27 } finally {
28 if (!cancelled) setLoading(false)
29 }
30 }, 300)
31 return () => { cancelled = true; clearTimeout(timer) }
32 }, [query, limit])
33
34 return { results, loading }
35}

Callers 2

MarketSidebarFunction · 0.90
SearchBoxFunction · 0.90

Calls 1

errorMethod · 0.65

Tested by

no test coverage detected