-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathGasApiNetworks.tsx
47 lines (40 loc) · 1.07 KB
/
GasApiNetworks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useEffect, useState } from 'react';
interface NetworkData {
[chainId: string]: string;
}
const GasApiNetworks = () => {
const [networks, setNetworks] = useState<NetworkData>({});
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch('https://gas.api.cx.metamask.io/v1/supportedChainNames');
const data: NetworkData = await response.json();
setNetworks(data);
} catch (error) {
console.error('Error fetching data:', error);
}
};
fetchData();
}, []);
// Convert the networks object into an array of [chainId, networkName] pairs
const networksArray = Object.entries(networks);
return (
<table>
<thead>
<tr>
<th>Network</th>
<th>Chain ID</th>
</tr>
</thead>
<tbody>
{networksArray.map(([chainId, networkName]) => (
<tr key={chainId}>
<td>{networkName}</td>
<td>{chainId}</td>
</tr>
))}
</tbody>
</table>
);
};
export default GasApiNetworks;