Skip to content

Commit 1a298ee

Browse files
committed
improvements
1 parent a037765 commit 1a298ee

File tree

1 file changed

+70
-50
lines changed

1 file changed

+70
-50
lines changed

components/PriceFeedTable.tsx

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
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";
143
import { HermesClient } from "@pythnetwork/hermes-client";
15-
import copy from "copy-to-clipboard";
4+
import { Table, Td, Th, Tr, CopyToClipboard } from "nextra/components";
165

176
interface PriceFeed {
187
id: string;
@@ -24,7 +13,58 @@ export function PriceFeedTable() {
2413
const [priceFeeds, setPriceFeeds] = useState<PriceFeed[]>([]);
2514
const [searchTerm, setSearchTerm] = useState("");
2615
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+
// };
2868

2969
useEffect(() => {
3070
const fetchPriceFeeds = async () => {
@@ -49,12 +89,6 @@ export function PriceFeedTable() {
4989
selectedAssetType === "All" || feed.assetType === selectedAssetType;
5090
return matchesSearch && matchesAssetType;
5191
});
52-
53-
const handleCopy = (id: string) => {
54-
copy(id);
55-
setOpenSnackbar(true);
56-
};
57-
5892
return (
5993
<Box>
6094
<Box sx={{ mb: 3, display: "flex", gap: 2 }}>
@@ -84,40 +118,26 @@ export function PriceFeedTable() {
84118
</Box>
85119

86120
<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>
95129
{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>
108134
{feed.id}
109-
</TableCell>
110-
</TableRow>
135+
<CopyToClipboard getValue={() => feed.id} />
136+
</Td>
137+
</Tr>
111138
))}
112-
</TableBody>
139+
</tbody>
113140
</Table>
114-
115-
<Snackbar
116-
open={openSnackbar}
117-
autoHideDuration={2000}
118-
onClose={() => setOpenSnackbar(false)}
119-
message="Feed ID copied to clipboard"
120-
/>
121141
</Box>
122142
);
123143
}

0 commit comments

Comments
 (0)