Skip to content

Commit

Permalink
refactor(web): merge blobs paginated table utils in blobs view (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
xFJA committed Jul 30, 2024
1 parent 1565d37 commit 31eb9cf
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 122 deletions.
114 changes: 0 additions & 114 deletions apps/web/src/components/PaginatedTable/helpers/blobs.tsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/web/src/components/PaginatedTable/helpers/index.ts

This file was deleted.

111 changes: 104 additions & 7 deletions apps/web/src/pages/blobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,45 @@ import NextError from "next/error";
import { useRouter } from "next/router";

import { getPaginationParams } from "~/utils/pagination";
import { Link } from "~/components/Link";
import { PaginatedTable } from "~/components/PaginatedTable/PaginatedTable";
import {
blobsTableHeaders,
getBlobsTableRows,
} from "~/components/PaginatedTable/helpers";
import { StorageIcon } from "~/components/StorageIcon";
import { api } from "~/api-client";
import { formatNumber } from "~/utils";
import {
buildBlobRoute,
buildBlockRoute,
buildTransactionRoute,
formatBytes,
formatNumber,
formatTimestamp,
shortenAddress,
} from "~/utils";

const BLOBS_TABLE_DEFAULT_PAGE_SIZE = 50;
const BLOBS_TABLE_HEADERS = [
{
cells: [
{
item: "Versioned Hash",
},
{
item: "Transaction Hash",
},
{
item: "Block Number",
},
{
item: "Timestamp",
},
{
item: "Size",
},
{
item: "Storage",
},
],
},
];

const Blobs: NextPage = function () {
const router = useRouter();
Expand All @@ -24,7 +54,74 @@ const Blobs: NextPage = function () {
const { data, error, isLoading } = api.blob.getAll.useQuery({ p, ps });
const { blobs, totalBlobs } = data || {};

const blobRows = useMemo(() => getBlobsTableRows(blobs), [blobs]);
const blobRows = useMemo(() => {
return blobs
? blobs.map(
({
versionedHash,
size,
dataStorageReferences,
txHash,
blockTimestamp,
blockNumber,
}) => ({
cells: [
{
item: (
<Link href={buildBlobRoute(versionedHash)}>
{shortenAddress(versionedHash, 8)}
</Link>
),
},
{
item: (
<Link href={buildTransactionRoute(txHash)}>
{shortenAddress(txHash, 8)}
</Link>
),
},
{
item: (
<div className="text-contentTertiary-light dark:text-contentTertiary-dark">
<Link href={buildBlockRoute(blockNumber)}>
{blockNumber}
</Link>
</div>
),
},
{
item: (
<div className="whitespace-break-spaces">
{formatTimestamp(blockTimestamp, true)}
</div>
),
},
{
item: (
<div className="flex gap-2 text-xs">
<span>{formatBytes(size)}</span>
</div>
),
},
{
item: (
<div className="flex flex-row gap-1">
{dataStorageReferences.map(({ storage, url }) => (
<StorageIcon
key={storage}
storage={storage}
url={url}
size="md"
/>
))}
</div>
),
},
],
})
)
: undefined;
}, [blobs]);

if (error) {
return (
Expand All @@ -39,7 +136,7 @@ const Blobs: NextPage = function () {
<PaginatedTable
title={`Blobs ${totalBlobs ? `(${formatNumber(totalBlobs)})` : ""}`}
isLoading={isLoading}
headers={blobsTableHeaders}
headers={BLOBS_TABLE_HEADERS}
rows={blobRows}
totalItems={totalBlobs}
paginationData={{ pageSize: ps, page: p }}
Expand Down

0 comments on commit 31eb9cf

Please sign in to comment.