1- import { useEffect , useState } from "react" ;
1+ import { ChangeEvent , useCallback , useEffect , useMemo , useState } from "react" ;
22import { StyledTd } from "./Table" ;
33import { Spinner } from "./Spinner" ;
44const fetchLazerPriceIdMetadata = async ( ) => {
@@ -59,6 +59,24 @@ const useLazerPriceIdState = () => {
5959
6060export function LazerPriceIdTable ( ) {
6161 const lazerPriceIdState = useLazerPriceIdState ( ) ;
62+ const [ search , setSearch ] = useState ( "" ) ;
63+
64+ const updateSearch = useCallback ( ( event : ChangeEvent < HTMLInputElement > ) => {
65+ setSearch ( event . target . value ) ;
66+ } , [ ] ) ;
67+
68+ const filteredFeeds = useMemo ( ( ) => {
69+ if ( lazerPriceIdState . type !== LazerPriceIdStateType . Loaded ) return [ ] ;
70+ return lazerPriceIdState . priceFeeds . filter ( ( feed ) => {
71+ const searchLower = search . toLowerCase ( ) ;
72+ return (
73+ feed . symbol . toLowerCase ( ) . includes ( searchLower ) ||
74+ feed . name . toLowerCase ( ) . includes ( searchLower ) ||
75+ feed . description . toLowerCase ( ) . includes ( searchLower ) ||
76+ feed . pyth_lazer_id . toString ( ) . includes ( searchLower )
77+ ) ;
78+ } ) ;
79+ } , [ lazerPriceIdState , search ] ) ;
6280
6381 switch ( lazerPriceIdState . type ) {
6482 case LazerPriceIdStateType . NotLoaded :
@@ -67,30 +85,39 @@ export function LazerPriceIdTable() {
6785 return < Spinner /> ;
6886 case LazerPriceIdStateType . Loaded :
6987 return (
70- < table >
71- < thead >
72- < tr >
73- < th > Asset Type</ th >
74- < th > Description</ th >
75- < th > Name</ th >
76- < th > Symbol</ th >
77- < th > Pyth Lazer Id</ th >
78- < th > Exponent</ th >
79- </ tr >
80- </ thead >
81- < tbody >
82- { lazerPriceIdState . priceFeeds . map ( ( priceFeed ) => (
83- < tr key = { priceFeed . symbol } >
84- < StyledTd > { priceFeed . asset_type } </ StyledTd >
85- < StyledTd > { priceFeed . description } </ StyledTd >
86- < StyledTd > { priceFeed . name } </ StyledTd >
87- < StyledTd > { priceFeed . symbol } </ StyledTd >
88- < StyledTd > { priceFeed . pyth_lazer_id } </ StyledTd >
89- < StyledTd > { priceFeed . exponent } </ StyledTd >
88+ < div >
89+ < input
90+ type = "text"
91+ placeholder = "Search by symbol, name, description, or pyth lazer id..."
92+ value = { search }
93+ onChange = { updateSearch }
94+ className = "w-full p-2 mb-4 border border-gray-300 rounded-md"
95+ />
96+ < table >
97+ < thead >
98+ < tr >
99+ < th > Asset Type</ th >
100+ < th > Description</ th >
101+ < th > Name</ th >
102+ < th > Symbol</ th >
103+ < th > Pyth Lazer Id</ th >
104+ < th > Exponent</ th >
90105 </ tr >
91- ) ) }
92- </ tbody >
93- </ table >
106+ </ thead >
107+ < tbody >
108+ { filteredFeeds . map ( ( priceFeed ) => (
109+ < tr key = { priceFeed . symbol } >
110+ < StyledTd > { priceFeed . asset_type } </ StyledTd >
111+ < StyledTd > { priceFeed . description } </ StyledTd >
112+ < StyledTd > { priceFeed . name } </ StyledTd >
113+ < StyledTd > { priceFeed . symbol } </ StyledTd >
114+ < StyledTd > { priceFeed . pyth_lazer_id } </ StyledTd >
115+ < StyledTd > { priceFeed . exponent } </ StyledTd >
116+ </ tr >
117+ ) ) }
118+ </ tbody >
119+ </ table >
120+ </ div >
94121 ) ;
95122 case LazerPriceIdStateType . Error :
96123 return < div > Error</ div > ;
0 commit comments