Skip to content

Commit

Permalink
(feat) Multi-column display for block list; ability to display propos…
Browse files Browse the repository at this point in the history
…er (#66)
  • Loading branch information
rrw-zilliqa authored Nov 20, 2024
1 parent f0c8fc0 commit c5d5d3b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/execution/BlockList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useEmptyBlocksToggler,
} from "../search/useEmptyBlocksToggler";
import { useFeeToggler } from "../search/useFeeToggler";
import { useMultiColumnDisplayToggler } from "../search/useMultiColumnDisplayToggler";
import StandardSelectionBoundary from "../selection/StandardSelectionBoundary";
import { useRecentBlocks } from "../useErigonHooks";
import { useLatestBlockNumber } from "../useLatestBlock";
Expand All @@ -26,6 +27,8 @@ const BlockList: React.FC = () => {
const [feeDisplay, feeDisplayToggler] = useFeeToggler();
const [emptyBlocksDisplay, emptyBlocksDisplayToggler] =
useEmptyBlocksToggler();
const [multiColumnDisplay, multiColumnDisplayToggler] =
useMultiColumnDisplayToggler();

const [searchParams] = useSearchParams();
let pageNumber = 1;
Expand All @@ -35,7 +38,6 @@ const BlockList: React.FC = () => {
pageNumber = parseInt(p);
} catch (err) {}
}

const { data, isLoading } = useRecentBlocks(
provider,
latestBlockNum,
Expand All @@ -60,6 +62,8 @@ const BlockList: React.FC = () => {
feeDisplayToggler={feeDisplayToggler}
emptyBlocksDisplay={emptyBlocksDisplay}
emptyBlocksDisplayToggler={emptyBlocksDisplayToggler}
multiColumnDisplay={multiColumnDisplay}
multiColumnDisplayToggler={multiColumnDisplayToggler}
/>
{data ? (
<StandardSelectionBoundary>
Expand All @@ -72,6 +76,7 @@ const BlockList: React.FC = () => {
key={block.number}
block={block}
feeDisplay={feeDisplay}
multiColumnDisplay={multiColumnDisplay}
/>
) : undefined,
)
Expand Down
26 changes: 23 additions & 3 deletions src/search/BlockItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HexValue from "../components/HexValue";
import Timestamp from "../components/Timestamp";
import { formatValue } from "../components/formatter";
import BlockReward from "../execution/components/BlockReward";
import { MultiColumnDisplay } from "../search/useMultiColumnDisplayToggler";
import { blockTxsURL } from "../url";
import { ExtendedBlock } from "../useErigonHooks";
import TransactionItemFiatFee from "./TransactionItemFiatFee";
Expand All @@ -13,12 +14,17 @@ import { FeeDisplay } from "./useFeeToggler";
type BlockItemProps = {
block: ExtendedBlock;
feeDisplay: FeeDisplay;
multiColumnDisplay: MultiColumnDisplay;
};

const BlockItem: React.FC<BlockItemProps> = ({ block, feeDisplay }) => {
const BlockItem: React.FC<BlockItemProps> = ({
block,
feeDisplay,
multiColumnDisplay,
}) => {
return (
<div
className="grid grid-cols-9 items-baseline gap-x-1 border-t border-gray-200 text-sm
className="grid grid-cols-10 items-baseline gap-x-1 border-t border-gray-200 text-sm
hover:bg-skin-table-hover px-2 py-3"
>
<span>
Expand All @@ -32,9 +38,23 @@ const BlockItem: React.FC<BlockItemProps> = ({ block, feeDisplay }) => {
{block.transactionCount} transactions
</NavLink>
</span>
<span className="col-span-4">
<span className="col-span-3">
<HexValue value={block.hash ?? "null"} />
</span>
<span className="col-span-2">
{multiColumnDisplay == MultiColumnDisplay.SHOW_PROPOSER && (
<div>
{" "}
<HexValue value={block.miner ?? "none"} />
</div>
)}
{multiColumnDisplay == MultiColumnDisplay.SHOW_PARENT && (
<div>
{" "}
<HexValue value={block.parentHash ?? "none"} />
</div>
)}
</span>
<span className="truncate font-balance text-xs text-gray-500">
{feeDisplay === FeeDisplay.TX_FEE && formatValue(block.feeReward, 18)}
{feeDisplay === FeeDisplay.TX_FEE_USD && (
Expand Down
18 changes: 16 additions & 2 deletions src/search/BlockResultHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import React from "react";
import { EmptyBlocksDisplay } from "./useEmptyBlocksToggler";
import { FeeDisplay } from "./useFeeToggler";
import { MultiColumnDisplay } from "./useMultiColumnDisplayToggler";

export type ResultHeaderProps = {
feeDisplay: FeeDisplay;
emptyBlocksDisplay: EmptyBlocksDisplay;
feeDisplayToggler: () => void;
emptyBlocksDisplayToggler: () => void;
multiColumnDisplay: MultiColumnDisplay;
multiColumnDisplayToggler: () => void;
};

const BlockResultHeader: React.FC<ResultHeaderProps> = ({
feeDisplay,
feeDisplayToggler,
emptyBlocksDisplay,
emptyBlocksDisplayToggler,
multiColumnDisplay,
multiColumnDisplayToggler,
}) => (
<div className="grid grid-cols-9 gap-x-1 border-t border-b border-gray-200 bg-gray-100 px-2 py-2 text-sm font-bold text-gray-500">
<div className="grid grid-cols-10 gap-x-1 border-t border-b border-gray-200 bg-gray-100 px-2 py-2 text-sm font-bold text-gray-500">
<div>Height</div>
<div>
<button
Expand All @@ -28,7 +33,16 @@ const BlockResultHeader: React.FC<ResultHeaderProps> = ({
"Txns [non-empty-blks]"}
</button>
</div>
<div className="col-span-4">Block Hash</div>
<div className="col-span-3">Block Hash</div>
<div className="col-span-2">
<button
className="text-link-blue hover:text-link-blue-hover"
onClick={multiColumnDisplayToggler}
>
{multiColumnDisplay == MultiColumnDisplay.SHOW_PARENT && "Parent"}
{multiColumnDisplay == MultiColumnDisplay.SHOW_PROPOSER && "Proposer"}
</button>
</div>
<div>
<button
className="text-link-blue hover:text-link-blue-hover"
Expand Down
22 changes: 22 additions & 0 deletions src/search/useMultiColumnDisplayToggler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useState } from "react";

export enum MultiColumnDisplay {
SHOW_PARENT = 0,
SHOW_PROPOSER = 1,
}

export const useMultiColumnDisplayToggler = (): [
MultiColumnDisplay,
() => void,
] => {
const [multiColumnDisplay, setMultiColumnDisplay] =
useState<MultiColumnDisplay>(MultiColumnDisplay.SHOW_PARENT);
const multiColumnDisplayToggler = () => {
if (multiColumnDisplay === MultiColumnDisplay.SHOW_PARENT) {
setMultiColumnDisplay(MultiColumnDisplay.SHOW_PROPOSER);
} else {
setMultiColumnDisplay(MultiColumnDisplay.SHOW_PARENT);
}
};
return [multiColumnDisplay, multiColumnDisplayToggler];
};

0 comments on commit c5d5d3b

Please sign in to comment.