This repository was archived by the owner on Nov 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathEntropyFeeTable.tsx
More file actions
87 lines (83 loc) · 2.51 KB
/
EntropyFeeTable.tsx
File metadata and controls
87 lines (83 loc) · 2.51 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { EntropyDeployment } from "./EntropyApiDataFetcher";
import { useEffect, useState } from "react";
import { ethers } from "ethers";
import EntropyAbi from "@pythnetwork/entropy-sdk-solidity/abis/IEntropyV2.json";
import { StyledTd } from "./Table";
const FeeTable = ({
deployments,
}: {
deployments: Record<string, EntropyDeployment>;
}) => {
const [fees, setFees] = useState<Record<string, string>>({});
useEffect(() => {
for (const [name, deployment] of Object.entries(deployments)) {
if (deployment.rpc) {
const contract = new ethers.Contract(
deployment.address,
EntropyAbi,
ethers.getDefaultProvider(deployment.rpc)
);
contract
.getFeeV2()
.then((fee: bigint) => {
const formattedFee = ethers.formatEther(fee);
setFees((prev) => ({ ...prev, [name]: formattedFee }));
})
.catch((error: any) => {
console.error(`Error fetching fee for ${name}:`, error);
if (deployment.default_fee) {
const fallbackFee = (deployment.default_fee / 1e18).toFixed(9);
setFees((prev) => ({ ...prev, [name]: fallbackFee }));
}
});
} else {
// No RPC available, use default_fee
if (deployment.default_fee) {
const fallbackFee = (deployment.default_fee / 1e18).toFixed(9);
setFees((prev) => ({ ...prev, [name]: fallbackFee }));
}
}
}
}, [deployments]);
const sortedDeployments = Object.entries(deployments)
.filter(([name]) => name !== "etherlink-testnet")
.sort();
return (
<table>
<thead>
<tr>
<th>Chain Id</th>
<th>Fee</th>
</tr>
</thead>
<tbody>
{sortedDeployments.map(([name, deployment]) => (
<tr key={name}>
<StyledTd>
{deployment.explorer ? (
<a
href={deployment.explorer + "/address/" + deployment.address}
target={"_blank"}
>
{name}
</a>
) : (
name
)}
</StyledTd>
<StyledTd>
{fees[name] === undefined ? (
"Loading..."
) : (
<>
{fees[name]} <b>{deployment.nativeCurrency ?? "ETH"}</b>
</>
)}
</StyledTd>
</tr>
))}
</tbody>
</table>
);
};
export default FeeTable;