1
1
import { useState , useEffect } from "react" ;
2
- import {
3
- Table ,
4
- TableHead ,
5
- TableBody ,
6
- TableRow ,
7
- TableCell ,
8
- TextField ,
9
- Select ,
10
- MenuItem ,
11
- Box ,
12
- Snackbar ,
13
- } from "@mui/material" ;
2
+ import { TextField , Select , MenuItem , Box } from "@mui/material" ;
14
3
import { HermesClient } from "@pythnetwork/hermes-client" ;
15
- import copy from "copy-to-clipboard " ;
4
+ import { Table , Td , Th , Tr , CopyToClipboard } from "nextra/components " ;
16
5
17
6
interface PriceFeed {
18
7
id : string ;
@@ -24,7 +13,58 @@ export function PriceFeedTable() {
24
13
const [ priceFeeds , setPriceFeeds ] = useState < PriceFeed [ ] > ( [ ] ) ;
25
14
const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
26
15
const [ selectedAssetType , setSelectedAssetType ] = useState ( "All" ) ;
27
- const [ openSnackbar , setOpenSnackbar ] = useState ( false ) ;
16
+
17
+ // enum AssetTypesStateType {
18
+ // NotLoaded,
19
+ // Loading,
20
+ // Loaded,
21
+ // Error,
22
+ // }
23
+
24
+ // const AssetTypesState = {
25
+ // NotLoaded: () => ({ type: AssetTypesStateType.NotLoaded as const }),
26
+ // Loading: () => ({ type: AssetTypesStateType.Loading as const }),
27
+ // Loaded: (assetTypes: string[]) => ({
28
+ // type: AssetTypesStateType.Loaded as const,
29
+ // assetTypes,
30
+ // }),
31
+ // Error: (error: unknown) => ({
32
+ // type: AssetTypesStateType.Error as const,
33
+ // error,
34
+ // }),
35
+ // };
36
+
37
+ const fetchAssetTypes = async ( ) => {
38
+ const hermesClient = new HermesClient ( "https://hermes.pyth.network" ) ;
39
+ const feeds = await hermesClient . getPriceFeeds ( ) ;
40
+ return Array . from (
41
+ new Set ( feeds . map ( ( feed ) => feed . attributes . asset_type ?? "" ) )
42
+ ) ;
43
+ } ;
44
+
45
+ // const useAssetTypes = (): typeof AssetTypesState => {
46
+ // const [assetTypes, setAssetTypes] = useState<typeof AssetTypesState>(
47
+ // AssetTypesState.NotLoaded()
48
+ // );
49
+
50
+ // useEffect(() => {
51
+ // setAssetTypes(AssetTypesState.Loading());
52
+ // }, []);
53
+
54
+ // return assetTypes;
55
+ // };
56
+
57
+ // type AssetTypesSelectorProps = {
58
+ // selectedAssetType: string;
59
+ // setSelectedAssetType: (assetType: string) => void;
60
+ // };
61
+
62
+ // const AssetTypesSelector = ({
63
+ // selectedAssetType,
64
+ // setSelectedAssetType,
65
+ // }: AssetTypesSelectorProps) => {
66
+ // const assetTypes = useAssetTypes();
67
+ // };
28
68
29
69
useEffect ( ( ) => {
30
70
const fetchPriceFeeds = async ( ) => {
@@ -49,12 +89,6 @@ export function PriceFeedTable() {
49
89
selectedAssetType === "All" || feed . assetType === selectedAssetType ;
50
90
return matchesSearch && matchesAssetType ;
51
91
} ) ;
52
-
53
- const handleCopy = ( id : string ) => {
54
- copy ( id ) ;
55
- setOpenSnackbar ( true ) ;
56
- } ;
57
-
58
92
return (
59
93
< Box >
60
94
< Box sx = { { mb : 3 , display : "flex" , gap : 2 } } >
@@ -84,40 +118,26 @@ export function PriceFeedTable() {
84
118
</ Box >
85
119
86
120
< Table >
87
- < TableHead >
88
- < TableRow >
89
- < TableCell > Ticker</ TableCell >
90
- < TableCell > Asset Type</ TableCell >
91
- < TableCell > Feed ID</ TableCell >
92
- </ TableRow >
93
- </ TableHead >
94
- < TableBody >
121
+ < thead >
122
+ < Tr >
123
+ < Th > Ticker</ Th >
124
+ < Th > Asset Type</ Th >
125
+ < Th > Feed ID</ Th >
126
+ </ Tr >
127
+ </ thead >
128
+ < tbody >
95
129
{ filteredData . map ( ( feed ) => (
96
- < TableRow key = { feed . id } >
97
- < TableCell > { feed . name } </ TableCell >
98
- < TableCell > { feed . assetType } </ TableCell >
99
- < TableCell
100
- onClick = { ( ) => handleCopy ( feed . id ) }
101
- sx = { {
102
- cursor : "pointer" ,
103
- "&:hover" : {
104
- backgroundColor : "#BB86FC" ,
105
- } ,
106
- } }
107
- >
130
+ < Tr key = { feed . id } >
131
+ < Td > { feed . name } </ Td >
132
+ < Td > { feed . assetType } </ Td >
133
+ < Td >
108
134
{ feed . id }
109
- </ TableCell >
110
- </ TableRow >
135
+ < CopyToClipboard getValue = { ( ) => feed . id } />
136
+ </ Td >
137
+ </ Tr >
111
138
) ) }
112
- </ TableBody >
139
+ </ tbody >
113
140
</ Table >
114
-
115
- < Snackbar
116
- open = { openSnackbar }
117
- autoHideDuration = { 2000 }
118
- onClose = { ( ) => setOpenSnackbar ( false ) }
119
- message = "Feed ID copied to clipboard"
120
- />
121
141
</ Box >
122
142
) ;
123
143
}
0 commit comments