Skip to content

Commit e7f7a32

Browse files
committed
show block gas limit on the chain page (#7101)
## [Dashboard] Feature: Add Block Gas Limit to Chain Live Stats ## Notes for the reviewer as requested by @0xFirekeeper This PR enhances the chain live stats component by adding the block gas limit information. The RPC method has been updated from `eth_blockNumber` to `eth_getBlockByNumber` to fetch additional block data including the gas limit. ## How to test The block gas limit should now be displayed alongside other chain statistics in the dashboard. The component handles loading and error states appropriately. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added display of the latest block's gas limit in the live stats section, including proper handling of loading, error, and unavailable states. - **Enhancements** - Improved the accuracy of live stats by retrieving and displaying more detailed block information. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- start pr-codex --> --- ## PR-Codex overview This PR updates the `live-stats.tsx` component to fetch the latest block information using the `eth_getBlockByNumber` method instead of `eth_blockNumber`. It also introduces the display of the block gas limit in the UI. ### Detailed summary - Changed JSON-RPC method from `eth_blockNumber` to `eth_getBlockByNumber`. - Updated parameters to fetch the latest block. - Added parsing for `blockGasLimit` from the response. - Modified return object to include `blockGasLimit`. - Introduced a new UI section to display the block gas limit. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent d2098ad commit e7f7a32

File tree

1 file changed

+21
-3
lines changed
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client

1 file changed

+21
-3
lines changed

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/live-stats.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ function useChainStatswithRPC(_rpcUrl: string) {
3232
method: "POST",
3333
body: JSON.stringify({
3434
jsonrpc: "2.0",
35-
method: "eth_blockNumber",
36-
params: [],
35+
method: "eth_getBlockByNumber",
36+
params: ["latest", false],
3737
id: 1,
3838
}),
3939
});
4040

4141
const json = await res.json();
4242
const latency = (performance.now() - startTimeStamp).toFixed(0);
4343

44+
const blockNumber = Number.parseInt(json.result.number, 16);
45+
const blockGasLimit = Number.parseInt(json.result.gasLimit, 16);
4446
return {
4547
latency,
46-
blockNumber: Number.parseInt(json.result, 16),
48+
blockNumber,
49+
blockGasLimit,
4750
};
4851
},
4952
refetchInterval: (query) => {
@@ -115,6 +118,21 @@ export function ChainLiveStats(props: { rpc: string }) {
115118
</div>
116119
)}
117120
</PrimaryInfoItem>
121+
122+
{/* Block Gas Limit */}
123+
<PrimaryInfoItem title="Block Gas Limit" titleIcon={<PulseDot />}>
124+
{stats.isError ? (
125+
<p className="fade-in-0 animate-in text-destructive-text">N/A</p>
126+
) : stats.data ? (
127+
<p className="fade-in-0 animate-in">
128+
{stats.data.blockGasLimit ?? "N/A"}
129+
</p>
130+
) : (
131+
<div className="flex h-[28px] w-[140px] py-1">
132+
<Skeleton className="h-full w-full" />
133+
</div>
134+
)}
135+
</PrimaryInfoItem>
118136
</>
119137
);
120138
}

0 commit comments

Comments
 (0)