Skip to content

Commit

Permalink
feat: add LatestGasPrice component (#470)
Browse files Browse the repository at this point in the history
* feat: add LatestGasPrice component

* feat: Add Blob gas price to ExplorerDetails component

* feat: Update ExplorerDetails component to display Blob gas price with EtherUnitDisplay

* chore: update changeset
  • Loading branch information
luis-herasme authored Aug 2, 2024
1 parent f1484d7 commit 4bc7884
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-boxes-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/api": minor
---

Added procedure to get the latest block
5 changes: 5 additions & 0 deletions .changeset/quiet-ladybugs-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/web": minor
---

Added blob gas price to the ExplorerDetails component
14 changes: 14 additions & 0 deletions apps/web/src/components/ExplorerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Skeleton from "react-loading-skeleton";

import { api } from "~/api-client";
import { env } from "~/env.mjs";
import Gas from "~/icons/gas.svg";
import { capitalize, formatNumber, formatTtl } from "~/utils";
import { EtherUnitDisplay } from "./Displays/EtherUnitDisplay";

type ExplorerDetailsItemProps = {
name: string;
Expand Down Expand Up @@ -35,6 +37,8 @@ function ExplorerDetailsItem({
export function ExplorerDetails() {
const { data: syncStateData } = api.syncState.getState.useQuery();
const { data: blobStoragesState } = api.blobStoragesState.getState.useQuery();
const { data: latestBlock } = api.block.getLatestBlock.useQuery();

const explorerDetailsItems: ExplorerDetailsItemProps[] = [
{ name: "Network", value: capitalize(env.NEXT_PUBLIC_NETWORK_NAME) },
{
Expand All @@ -43,6 +47,16 @@ export function ExplorerDetails() {
? formatNumber(syncStateData.lastUpperSyncedSlot ?? 0)
: undefined,
},
{
name: "Blob gas price",
icon: <Gas className="h-4 w-4" />,
value: latestBlock && (
<EtherUnitDisplay
amount={Number(latestBlock.blobGasPrice.toString())}
toUnit="Gwei"
/>
),
},
];

if (blobStoragesState && blobStoragesState.swarmDataTTL) {
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/icons/gas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/api/src/routers/block/getGasPrice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { prisma } from "@blobscan/db";

import { publicProcedure } from "../../procedures";

export const getLatestBlock = publicProcedure.query(async () => {
return await prisma.block.findLatest();
});
2 changes: 2 additions & 0 deletions packages/api/src/routers/block/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { t } from "../../trpc-client";
import { getAll } from "./getAll";
import { getByBlockId } from "./getByBlockId";
import { getLatestBlock } from "./getGasPrice";

export const blockRouter = t.router({
getAll,
getByBlockId,
getLatestBlock,
});

0 comments on commit 4bc7884

Please sign in to comment.