Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 15 additions & 5 deletions frontend/src/app/[lang]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,11 @@ export default function DashboardPage() {
</p>
)}

{/* Latest blocks + transactions */}
{/* Latest blocks + transactions: side by side they show one-line rows and the columns that
fit half the page (View, Fee and Height are on /blocks and /transactions), so the two
cards line up row for row (one row height) and end at the same height. */}
<div className="grid gap-6 xl:grid-cols-2">
<section className="space-y-4">
<section className="flex min-w-0 flex-col gap-4">
<SectionHeading
label={t('home.latestBlocks')}
actions={
Expand All @@ -376,10 +378,16 @@ export default function DashboardPage() {
</L>
}
/>
<BlocksTable blocks={blocks} isLoading={blocksLoading && blocks.length === 0} />
<BlocksTable
blocks={blocks}
isLoading={blocksLoading && blocks.length === 0}
hideColumns={['view']}
compact
className="flex-1 [&_td]:h-[52px] [&_td]:px-3 [&_th]:px-3"
/>
</section>

<section className="space-y-4">
<section className="flex min-w-0 flex-col gap-4">
<SectionHeading
label={t('home.latestTransactions')}
actions={
Expand All @@ -391,7 +399,9 @@ export default function DashboardPage() {
<TransactionsTable
transactions={transactions}
isLoading={txsLoading && transactions.length === 0}
hideColumns={['fee']}
hideColumns={['fee', 'height']}
compact
className="flex-1 [&_td]:h-[52px] [&_td]:px-3 [&_th]:px-3"
/>
</section>
</div>
Expand Down
60 changes: 46 additions & 14 deletions frontend/src/components/Tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import type { BlockSummary, TokenInfo, TransactionSummary } from '@/types';

type TFn = ReturnType<typeof useT>['t'];

export function blockColumns(t: TFn, fmt: Fmt): Column<BlockSummary>[] {
/** Hash lengths: `compact` is for a table sharing the row with another (the home page). */
const HASH = { start: 8, end: 6 };
const HASH_COMPACT = { start: 6, end: 4 };

export function blockColumns(t: TFn, fmt: Fmt, compact = false): Column<BlockSummary>[] {
const h = compact ? HASH_COMPACT : HASH;
return [
{
key: 'height',
Expand All @@ -27,13 +32,18 @@ export function blockColumns(t: TFn, fmt: Fmt): Column<BlockSummary>[] {
{
key: 'hash',
header: t('components.tables.blocks.hash'),
render: (block) => <Hash value={block.hash} href={`/blocks/${block.hash}`} />,
render: (block) => <Hash value={block.hash} href={`/blocks/${block.hash}`} {...h} />,
},
{
key: 'proposer',
header: t('components.tables.blocks.proposer'),
render: (block) => (
<Hash value={block.proposer} href={`/validators/${block.proposer}`} start={6} end={6} />
<Hash
value={block.proposer}
href={`/validators/${block.proposer}`}
start={compact ? 4 : 6}
end={compact ? 4 : 6}
/>
),
},
{
Expand Down Expand Up @@ -62,14 +72,27 @@ interface BlocksTableProps {
blocks: BlockSummary[];
isLoading?: boolean;
emptyMessage?: string;
/** Drop columns that are redundant in the surrounding context. */
hideColumns?: string[];
/** Shorter hashes, for a table that shares the row with another. */
compact?: boolean;
className?: string;
}

export function BlocksTable({ blocks, isLoading, emptyMessage }: BlocksTableProps) {
export function BlocksTable({
blocks,
isLoading,
emptyMessage,
hideColumns = [],
compact = false,
className,
}: BlocksTableProps) {
const { t } = useT();
const fmt = useFmt();
return (
<DataTable
columns={blockColumns(t, fmt)}
columns={blockColumns(t, fmt, compact).filter((column) => !hideColumns.includes(column.key))}
className={className}
data={blocks}
keyExtractor={(block) => block.hash}
isLoading={isLoading}
Expand All @@ -88,11 +111,12 @@ export function BlocksTable({ blocks, isLoading, emptyMessage }: BlocksTableProp
* nothing, by design — its asset is private, and `tokens` (the cached registry) resolves an RPL
* amount's index to its symbol ("12.50 zUSD") rather than a bare unit count.
*/
function actionCell(tx: TransactionSummary, t: TFn, fmt: Fmt, tokens?: TokenInfo[]) {
function actionCell(tx: TransactionSummary, t: TFn, fmt: Fmt, tokens?: TokenInfo[], compact = false) {
const parts: React.ReactNode[] = [];
const n = compact ? 4 : 6;
if (tx.program) {
parts.push(
<Hash key="program" value={tx.program} href={`/programs/${tx.program}`} start={6} end={6} />
<Hash key="program" value={tx.program} href={`/programs/${tx.program}`} start={n} end={n} />
);
}
if (tx.validator) {
Expand All @@ -101,8 +125,8 @@ function actionCell(tx: TransactionSummary, t: TFn, fmt: Fmt, tokens?: TokenInfo
key="validator"
value={tx.validator}
href={`/validators/${tx.validator}`}
start={6}
end={6}
start={n}
end={n}
/>
);
}
Expand All @@ -120,19 +144,21 @@ function actionCell(tx: TransactionSummary, t: TFn, fmt: Fmt, tokens?: TokenInfo
</span>
);
}
return <span className="inline-flex flex-wrap items-center gap-2">{parts}</span>;
return <span className="inline-flex items-center gap-2">{parts}</span>;
}

export function transactionColumns(
t: TFn,
fmt: Fmt,
tokens?: TokenInfo[]
tokens?: TokenInfo[],
compact = false
): Column<TransactionSummary>[] {
const h = compact ? HASH_COMPACT : HASH;
return [
{
key: 'hash',
header: t('components.tables.txs.hash'),
render: (tx) => <Hash value={tx.hash} href={`/transactions/${tx.hash}`} />,
render: (tx) => <Hash value={tx.hash} href={`/transactions/${tx.hash}`} {...h} />,
},
{
key: 'kind',
Expand All @@ -151,7 +177,7 @@ export function transactionColumns(
{
key: 'action',
header: t('components.tables.txs.action'),
render: (tx) => actionCell(tx, t, fmt, tokens),
render: (tx) => actionCell(tx, t, fmt, tokens, compact),
},
{
key: 'fee',
Expand Down Expand Up @@ -183,24 +209,30 @@ interface TransactionsTableProps {
emptyMessage?: string;
/** Drop columns that are redundant in the surrounding context. */
hideColumns?: string[];
/** Shorter hashes, for a table that shares the row with another. */
compact?: boolean;
className?: string;
}

export function TransactionsTable({
transactions,
isLoading,
emptyMessage,
hideColumns = [],
compact = false,
className,
}: TransactionsTableProps) {
const { data: tokenList } = useTokens();
const { t } = useT();
const fmt = useFmt();
const columns = transactionColumns(t, fmt, tokenList?.tokens).filter((column) => !hideColumns.includes(column.key));
const columns = transactionColumns(t, fmt, tokenList?.tokens, compact).filter((column) => !hideColumns.includes(column.key));

return (
<DataTable
columns={columns}
data={transactions}
keyExtractor={(tx) => tx.hash}
className={className}
isLoading={isLoading}
emptyMessage={emptyMessage ?? t('components.tables.txs.empty')}
/>
Expand Down
Loading