Block id styling

This commit is contained in:
sam-keen 2022-03-07 19:51:13 +00:00
parent f2f1083260
commit 9739e4b467
5 changed files with 122 additions and 33 deletions

View File

@ -21,7 +21,7 @@ export const BlocksTable = ({ data, showTransactions }: BlocksProps) => {
return ( return (
<React.Fragment key={index}> <React.Fragment key={index}>
<tr className="bg-neutral-850 border-b-4 border-b-black"> <tr className="bg-neutral-850 border-b-4 border-b-black">
<td className="pl-4"> <td className="pl-4 py-2">
<Link <Link
to={`/blocks/${block.header?.height}`} to={`/blocks/${block.header?.height}`}
className="text-vega-yellow" className="text-vega-yellow"

View File

@ -0,0 +1,57 @@
import * as React from 'react';
const ELLIPSIS = '\u2026';
interface TruncateInlineProps {
text: string | null;
className?: string;
style?: React.CSSProperties;
children?: (truncatedText: string) => React.ReactElement;
startChars?: number; // number chars to show before ellipsis
endChars?: number; // number of chars to show after ellipsis
}
/**
* Truncates a string of text from the center showing a specified number
* of characters from the start and end. Optionally takes a children as
* a render props so truncated text can be used inside other elements such
* as links
*/
export function TruncateInline({
text,
className,
style,
children,
startChars,
endChars,
}: TruncateInlineProps) {
if (text === null) {
return <span data-testid="empty-truncation" />;
}
const truncatedText = truncateByChars(text, startChars, endChars);
const wrapperProps = {
title: text,
style,
className,
};
if (children !== undefined) {
return <span {...wrapperProps}>{children(truncatedText)}</span>;
} else {
return <span {...wrapperProps}>{truncatedText}</span>;
}
}
export function truncateByChars(s: string, startChars = 6, endChars = 6) {
// if the text is shorted than the total number of chars to show
// no truncation is needed. Plus one is to account for the ellipsis
if (s.length <= startChars + endChars + 1) {
return s;
}
const start = s.slice(0, startChars);
const end = s.slice(-endChars);
return start + ELLIPSIS + end;
}

View File

@ -2,11 +2,14 @@ import useFetch from '../../../hooks/use-fetch';
import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response'; import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response';
import { DATA_SOURCES } from '../../../config'; import { DATA_SOURCES } from '../../../config';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { TruncateInline } from '../../truncate/truncate';
interface TxsPerBlockProps { interface TxsPerBlockProps {
blockHeight: string | undefined; blockHeight: string | undefined;
} }
const truncateLength = 14;
export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => { export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => {
const { const {
state: { data: decodedBlockData }, state: { data: decodedBlockData },
@ -24,9 +27,10 @@ export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => {
}); });
return ( return (
<table> <div className="overflow-x-auto whitespace-nowrap mb-28">
<table className="w-full">
<thead> <thead>
<tr> <tr className="font-mono">
<td>Transaction</td> <td>Transaction</td>
<td>From</td> <td>From</td>
<td>Type</td> <td>Type</td>
@ -38,14 +42,29 @@ export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => {
return ( return (
<tr key={index}> <tr key={index}>
<td> <td>
<Link to={`/txs/${TxHash}`}>{TxHash}</Link> <Link to={`/txs/${TxHash}`}>
<TruncateInline
text={TxHash}
startChars={truncateLength}
endChars={truncateLength}
className="text-vega-yellow font-mono"
/>
</Link>
</td>
<td>
<TruncateInline
text={PubKey}
startChars={truncateLength}
endChars={truncateLength}
className="font-mono"
/>
</td> </td>
<td>{PubKey}</td>
<td>{Type}</td> <td>{Type}</td>
</tr> </tr>
); );
})} })}
</tbody> </tbody>
</table> </table>
</div>
); );
}; };

View File

@ -23,24 +23,29 @@ const Block = () => {
return ( return (
<section> <section>
<h1>BLOCK {block}</h1> <h1 className="route-header">BLOCK {block}</h1>
<Table> <Table>
<tr> <tr className="table-bordered-tr">
<td>Mined by</td> <td className="table-bordered-td">Mined by</td>
<td> <td className="table-bordered-td">
<Link to={`/validators/${header.proposer_address}`}> <Link
className="text-vega-yellow"
to={`/validators/${header.proposer_address}`}
>
{header.proposer_address} {header.proposer_address}
</Link> </Link>
</td> </td>
</tr> </tr>
<tr> <tr className="table-bordered-tr">
<td>Time</td> <td className="table-bordered-td">Time</td>
<td> <td className="table-bordered-td">
<SecondsAgo date={header.time} /> <SecondsAgo date={header.time} />
</td> </td>
</tr> </tr>
</Table> </Table>
{blockData?.result.block.data.txs.length > 0 && (
<TxsPerBlock blockHeight={block} /> <TxsPerBlock blockHeight={block} />
)}
</section> </section>
); );
}; };

View File

@ -6,6 +6,14 @@
@apply font-alpha text-h3 uppercase mt-12 mb-28; @apply font-alpha text-h3 uppercase mt-12 mb-28;
} }
.table-bordered-tr {
@apply border-b border-neutral-500;
}
.table-bordered-td {
@apply py-4;
}
/* Used for text, tel input */ /* Used for text, tel input */
.form-input { .form-input {
@apply bg-neutral-800 border-white border px-8 py-4 placeholder-neutral-300; @apply bg-neutral-800 border-white border px-8 py-4 placeholder-neutral-300;