11import { useEffect , useState } from "react" ;
22import { StyledTd } from "./Table" ;
33
4-
5-
64const fetchLazerPriceIdMetadata = async ( ) => {
7- const response = await fetch ( "https://pyth-lazer-staging.dourolabs.app/history/v1/symbols" ) ;
8- const data = await response . json ( ) ;
9- return data ;
10- }
5+ const response = await fetch (
6+ "https://pyth-lazer-staging.dourolabs.app/history/v1/symbols"
7+ ) ;
8+ const data = await response . json ( ) ;
9+ return data ;
10+ } ;
1111
1212type LazerPriceIdMetadata = {
13- asset_type : string ;
14- description : string ;
15- exponent : number ;
16- name : string ;
17- pyth_lazer_id : number ;
18- symbol : string ;
19- }
13+ asset_type : string ;
14+ description : string ;
15+ exponent : number ;
16+ name : string ;
17+ pyth_lazer_id : number ;
18+ symbol : string ;
19+ } ;
2020
2121enum LazerPriceIdStateType {
2222 NotLoaded ,
@@ -26,68 +26,73 @@ enum LazerPriceIdStateType {
2626}
2727
2828const LazerPriceIdState = {
29- NotLoaded : ( ) => ( { type : LazerPriceIdStateType . NotLoaded as const } ) ,
30- Loading : ( ) => ( { type : LazerPriceIdStateType . Loading as const } ) ,
31- Loaded : ( priceFeeds : LazerPriceIdMetadata [ ] ) => ( {
32- type : LazerPriceIdStateType . Loaded as const ,
33- priceFeeds,
34- } ) ,
35- Error : ( error : unknown ) => ( {
29+ NotLoaded : ( ) => ( { type : LazerPriceIdStateType . NotLoaded as const } ) ,
30+ Loading : ( ) => ( { type : LazerPriceIdStateType . Loading as const } ) ,
31+ Loaded : ( priceFeeds : LazerPriceIdMetadata [ ] ) => ( {
32+ type : LazerPriceIdStateType . Loaded as const ,
33+ priceFeeds,
34+ } ) ,
35+ Error : ( error : unknown ) => ( {
3636 type : LazerPriceIdStateType . Error as const ,
3737 error,
3838 } ) ,
3939} ;
4040
41- type LazerPriceIdState = ReturnType < typeof LazerPriceIdState [ keyof typeof LazerPriceIdState ] > ;
41+ type LazerPriceIdState = ReturnType <
42+ typeof LazerPriceIdState [ keyof typeof LazerPriceIdState ]
43+ > ;
4244
4345const useLazerPriceIdState = ( ) => {
44- const [ state , setState ] = useState < LazerPriceIdState > ( LazerPriceIdState . NotLoaded ( ) ) ;
46+ const [ state , setState ] = useState < LazerPriceIdState > (
47+ LazerPriceIdState . NotLoaded ( )
48+ ) ;
4549
46- useEffect ( ( ) => {
47- setState ( LazerPriceIdState . Loading ( ) ) ;
48- fetchLazerPriceIdMetadata ( ) . then ( priceFeeds => setState ( LazerPriceIdState . Loaded ( priceFeeds ) ) )
49- . catch ( error => setState ( LazerPriceIdState . Error ( error ) ) ) ;
50- } , [ ] ) ;
50+ useEffect ( ( ) => {
51+ setState ( LazerPriceIdState . Loading ( ) ) ;
52+ fetchLazerPriceIdMetadata ( )
53+ . then ( ( priceFeeds ) => setState ( LazerPriceIdState . Loaded ( priceFeeds ) ) )
54+ . catch ( ( error ) => setState ( LazerPriceIdState . Error ( error ) ) ) ;
55+ } , [ ] ) ;
5156
52- return state ;
53- }
57+ return state ;
58+ } ;
5459
5560export function LazerPriceIdTable ( ) {
56- const lazerPriceIdState = useLazerPriceIdState ( ) ;
61+ const lazerPriceIdState = useLazerPriceIdState ( ) ;
5762
58- switch ( lazerPriceIdState . type ) {
59- case LazerPriceIdStateType . NotLoaded :
60- return < div > Loading...</ div > ;
61- case LazerPriceIdStateType . Loading :
62- return < div > Loading...</ div > ;
63- case LazerPriceIdStateType . Loaded :
64- return (
65- < table >
66- < thead >
67- < tr >
68- < th > Asset Type</ th >
69- < th > Description</ th >
70- < th > Name</ th >
71- < th > Symbol</ th >
72- < th > Pyth Lazer Id</ th >
73- < th > Exponent</ th >
74- </ tr >
75- </ thead >
76- < tbody >
77- { lazerPriceIdState . priceFeeds . map ( priceFeed => (
78- < tr key = { priceFeed . symbol } >
79- < StyledTd > { priceFeed . asset_type } </ StyledTd >
80- < StyledTd > { priceFeed . description } </ StyledTd >
81- < StyledTd > { priceFeed . name } </ StyledTd >
82- < StyledTd > { priceFeed . symbol } </ StyledTd >
83- < StyledTd > { priceFeed . pyth_lazer_id } </ StyledTd >
84- < StyledTd > { priceFeed . exponent } </ StyledTd >
85- </ tr >
86- ) ) }
87- </ tbody >
88- </ table >
89- )
90- case LazerPriceIdStateType . Error :
91- return < div > Error</ div > ;
92- }
93- }
63+ switch ( lazerPriceIdState . type ) {
64+ case LazerPriceIdStateType . NotLoaded :
65+ return < div > Loading...</ div > ;
66+ case LazerPriceIdStateType . Loading :
67+ return < div > Loading...</ div > ;
68+ case LazerPriceIdStateType . Loaded :
69+ 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 >
90+ </ tr >
91+ ) ) }
92+ </ tbody >
93+ </ table >
94+ ) ;
95+ case LazerPriceIdStateType . Error :
96+ return < div > Error</ div > ;
97+ }
98+ }
0 commit comments