Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 153 additions & 1 deletion components/EntropyDeploymentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,163 @@
import React, { useEffect, useState } from "react";
import { ethers } from "ethers";
import { EntropyDeployment } from "./EntropyDeployments";
import { StyledTd } from "./Table";

const ENTROPY_V2_ABI = [
{
inputs: [],
name: "getDefaultProvider",
outputs: [
{
internalType: "address",
name: "provider",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "provider",
type: "address",
},
],
name: "getProviderInfoV2",
outputs: [
{
components: [
{
internalType: "uint128",
name: "feeInWei",
type: "uint128",
},
{
internalType: "uint128",
name: "accruedFeesInWei",
type: "uint128",
},
{
internalType: "bytes32",
name: "originalCommitment",
type: "bytes32",
},
{
internalType: "uint64",
name: "originalCommitmentSequenceNumber",
type: "uint64",
},
{
internalType: "bytes",
name: "commitmentMetadata",
type: "bytes",
},
{
internalType: "bytes",
name: "uri",
type: "bytes",
},
{
internalType: "uint64",
name: "endSequenceNumber",
type: "uint64",
},
{
internalType: "uint64",
name: "sequenceNumber",
type: "uint64",
},
{
internalType: "bytes32",
name: "currentCommitment",
type: "bytes32",
},
{
internalType: "uint64",
name: "currentCommitmentSequenceNumber",
type: "uint64",
},
{
internalType: "address",
name: "feeManager",
type: "address",
},
{
internalType: "bool",
name: "withCallback",
type: "bool",
},
{
internalType: "uint32",
name: "defaultGasLimit",
type: "uint32",
},
],
internalType: "struct EntropyStructsV2.ProviderInfo",
name: "info",
type: "tuple",
},
],
stateMutability: "view",
type: "function",
},
];

const EntropyDeploymentTable = ({
deployments,
showReveal,
}: {
deployments: Record<string, EntropyDeployment>;
showReveal: boolean;
}) => {
const [gasLimits, setGasLimits] = useState<Record<string, string>>({});

useEffect(() => {
for (const [name, deployment] of Object.entries(deployments)) {
if (deployment.rpc) {
try {
const contract = new ethers.Contract(
deployment.address,
ENTROPY_V2_ABI,
ethers.getDefaultProvider(deployment.rpc)
);
contract
.getDefaultProvider()
.then((defaultProvider: string) => {
contract
.getProviderInfoV2(defaultProvider)
.then((providerInfo: any) => {
const gasLimit = providerInfo.defaultGasLimit;
const formattedGasLimit = gasLimit.toString();
setGasLimits((prev) => ({
...prev,
[name]: formattedGasLimit,
}));
})
.catch(() => {
setGasLimits((prev) => ({
...prev,
[name]: deployment.gasLimit,
}));
});
})
.catch(() => {
setGasLimits((prev) => ({
...prev,
[name]: deployment.gasLimit,
}));
});
} catch {
setGasLimits((prev) => ({ ...prev, [name]: deployment.gasLimit }));
}
} else {
setGasLimits((prev) => ({ ...prev, [name]: deployment.gasLimit }));
}
}
}, [deployments]);

const sortedDeployments = Object.entries(deployments).sort();
return (
<table>
Expand Down Expand Up @@ -44,7 +194,9 @@ const EntropyDeploymentTable = ({
</a>
</StyledTd>
{showReveal && <StyledTd>{deployment.delay}</StyledTd>}
<StyledTd>{deployment.gasLimit}</StyledTd>
<StyledTd>
{gasLimits[name] === undefined ? "Loading..." : gasLimits[name]}
</StyledTd>
</tr>
))}
</tbody>
Expand Down
Loading