Added Table presentational component for a little cleanup

This commit is contained in:
sam-keen 2022-03-03 14:09:40 +00:00 committed by Dexter Edwards
parent 1b6c42c031
commit 3f47eed917
5 changed files with 91 additions and 83 deletions

View File

@ -2,6 +2,7 @@ import { TendermintBlockchainResponse } from '../../../routes/blocks/tendermint-
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { SecondsAgo } from '../../seconds-ago'; import { SecondsAgo } from '../../seconds-ago';
import { TxsPerBlock } from '../../txs/txs-per-block'; import { TxsPerBlock } from '../../txs/txs-per-block';
import { Table } from '../../table';
interface BlocksProps { interface BlocksProps {
data: TendermintBlockchainResponse | undefined; data: TendermintBlockchainResponse | undefined;
@ -14,8 +15,7 @@ export const BlocksTable = ({ data, showTransactions }: BlocksProps) => {
} }
return ( return (
<table> <Table>
<tbody>
{data.result?.block_metas?.map((block) => { {data.result?.block_metas?.map((block) => {
return ( return (
<> <>
@ -49,7 +49,6 @@ export const BlocksTable = ({ data, showTransactions }: BlocksProps) => {
</> </>
); );
})} })}
</tbody> </Table>
</table>
); );
}; };

View File

@ -0,0 +1,13 @@
import React from 'react';
interface TableProps {
children: React.ReactNode;
}
export const Table = ({ children }: TableProps) => {
return (
<table>
<tbody>{children}</tbody>
</table>
);
};

View File

@ -1,5 +1,6 @@
import { Codeblock } from '../../codeblock'; import { Codeblock } from '../../codeblock';
import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response'; import { ChainExplorerTxResponse } from '../../../routes/types/chain-explorer-response';
import { Table } from '../../table';
interface TxContentProps { interface TxContentProps {
data: ChainExplorerTxResponse | undefined; data: ChainExplorerTxResponse | undefined;
@ -21,14 +22,12 @@ export const TxContent = ({ data }: TxContentProps) => {
return ( return (
<> <>
<table> <Table>
<tbody>
<tr> <tr>
<td>Type</td> <td>Type</td>
<td>{data.Type}</td> <td>{data.Type}</td>
</tr> </tr>
</tbody> </Table>
</table>
<h3>Decoded transaction content</h3> <h3>Decoded transaction content</h3>
<Codeblock code={displayCode} language={'javascript'} /> <Codeblock code={displayCode} language={'javascript'} />

View File

@ -1,6 +1,7 @@
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { Routes } from '../../../routes/router-config'; import { Routes } from '../../../routes/router-config';
import { Result } from '../../../routes/txs/tendermint-transaction-response.d'; import { Result } from '../../../routes/txs/tendermint-transaction-response.d';
import { Table } from '../../table';
interface TxDetailsProps { interface TxDetailsProps {
txData: Result | undefined; txData: Result | undefined;
@ -13,8 +14,7 @@ export const TxDetails = ({ txData, pubKey }: TxDetailsProps) => {
} }
return ( return (
<table> <Table>
<tbody>
<tr> <tr>
<td>Hash</td> <td>Hash</td>
<td>{txData.hash}</td> <td>{txData.hash}</td>
@ -42,7 +42,6 @@ export const TxDetails = ({ txData, pubKey }: TxDetailsProps) => {
<td>Encoded tnx</td> <td>Encoded tnx</td>
<td>{txData.tx}</td> <td>{txData.tx}</td>
</tr> </tr>
</tbody> </Table>
</table>
); );
}; };

View File

@ -5,6 +5,7 @@ import useFetch from '../../../hooks/use-fetch';
import { TendermintBlocksResponse } from '../tendermint-blocks-response'; import { TendermintBlocksResponse } from '../tendermint-blocks-response';
import { TxsPerBlock } from '../../../components/txs/txs-per-block'; import { TxsPerBlock } from '../../../components/txs/txs-per-block';
import { SecondsAgo } from '../../../components/seconds-ago'; import { SecondsAgo } from '../../../components/seconds-ago';
import { Table } from '../../../components/table';
const Block = () => { const Block = () => {
const { block } = useParams<{ block: string }>(); const { block } = useParams<{ block: string }>();
@ -17,8 +18,7 @@ const Block = () => {
return ( return (
<section> <section>
<h1>BLOCK {block}</h1> <h1>BLOCK {block}</h1>
<table> <Table>
<tbody>
<tr> <tr>
<td>Mined by</td> <td>Mined by</td>
<td>{blockData?.result.block.header?.proposer_address}</td> <td>{blockData?.result.block.header?.proposer_address}</td>
@ -29,9 +29,7 @@ const Block = () => {
<SecondsAgo date={blockData?.result.block.header?.time} /> <SecondsAgo date={blockData?.result.block.header?.time} />
</td> </td>
</tr> </tr>
</tbody> </Table>
</table>
<TxsPerBlock blockHeight={block} /> <TxsPerBlock blockHeight={block} />
</section> </section>
); );