diff --git a/apps/explorer/src/app/components/blocks/home/blocks-table.tsx b/apps/explorer/src/app/components/blocks/home/blocks-table.tsx index 0f38617e3..a0f7d8c93 100644 --- a/apps/explorer/src/app/components/blocks/home/blocks-table.tsx +++ b/apps/explorer/src/app/components/blocks/home/blocks-table.tsx @@ -21,7 +21,7 @@ export const BlocksTable = ({ data, showTransactions }: BlocksProps) => { return ( - + 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 ; + } + const truncatedText = truncateByChars(text, startChars, endChars); + + const wrapperProps = { + title: text, + style, + className, + }; + + if (children !== undefined) { + return {children(truncatedText)}; + } else { + return {truncatedText}; + } +} + +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; +} diff --git a/apps/explorer/src/app/components/txs/txs-per-block/index.tsx b/apps/explorer/src/app/components/txs/txs-per-block/index.tsx index 063e35abe..b049ee06f 100644 --- a/apps/explorer/src/app/components/txs/txs-per-block/index.tsx +++ b/apps/explorer/src/app/components/txs/txs-per-block/index.tsx @@ -2,11 +2,14 @@ import useFetch from '../../../hooks/use-fetch'; import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response'; import { DATA_SOURCES } from '../../../config'; import { Link } from 'react-router-dom'; +import { TruncateInline } from '../../truncate/truncate'; interface TxsPerBlockProps { blockHeight: string | undefined; } +const truncateLength = 14; + export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => { const { state: { data: decodedBlockData }, @@ -24,28 +27,44 @@ export const TxsPerBlock = ({ blockHeight }: TxsPerBlockProps) => { }); return ( - - - - - - - - - - {decodedBlockData && - decodedBlockData.map(({ TxHash, PubKey, Type }, index) => { - return ( - - - - - - ); - })} - -
TransactionFromType
- {TxHash} - {PubKey}{Type}
+
+ + + + + + + + + + {decodedBlockData && + decodedBlockData.map(({ TxHash, PubKey, Type }, index) => { + return ( + + + + + + ); + })} + +
TransactionFromType
+ + + + + + {Type}
+
); }; diff --git a/apps/explorer/src/app/routes/blocks/id/index.tsx b/apps/explorer/src/app/routes/blocks/id/index.tsx index 8e15087f6..3cd71d404 100644 --- a/apps/explorer/src/app/routes/blocks/id/index.tsx +++ b/apps/explorer/src/app/routes/blocks/id/index.tsx @@ -23,24 +23,29 @@ const Block = () => { return (
-

BLOCK {block}

+

BLOCK {block}

- - - + + - - - + +
Mined by - +
Mined by + {header.proposer_address}
Time +
Time
- + {blockData?.result.block.data.txs.length > 0 && ( + + )}
); }; diff --git a/apps/explorer/src/styles.css b/apps/explorer/src/styles.css index e2f897184..e4fe0d84b 100644 --- a/apps/explorer/src/styles.css +++ b/apps/explorer/src/styles.css @@ -6,6 +6,14 @@ @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 */ .form-input { @apply bg-neutral-800 border-white border px-8 py-4 placeholder-neutral-300;