From 8f51e6433a1d367ee177742a729cd9e0ff610bbf Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 14 Jul 2021 16:57:08 -0300 Subject: [PATCH] Extract subcomponents --- src/BlockTransactionHeader.tsx | 21 +++++++++ src/BlockTransactionResults.tsx | 78 +++++++++++++++++++++++++++++++++ src/BlockTransactions.tsx | 72 ++++-------------------------- 3 files changed, 107 insertions(+), 64 deletions(-) create mode 100644 src/BlockTransactionHeader.tsx create mode 100644 src/BlockTransactionResults.tsx diff --git a/src/BlockTransactionHeader.tsx b/src/BlockTransactionHeader.tsx new file mode 100644 index 0000000..65a8288 --- /dev/null +++ b/src/BlockTransactionHeader.tsx @@ -0,0 +1,21 @@ +import React from "react"; +import { ethers } from "ethers"; +import StandardSubtitle from "./StandardSubtitle"; +import BlockLink from "./components/BlockLink"; + +type BlockTransactionHeaderProps = { + blockTag: ethers.providers.BlockTag; +}; + +const BlockTransactionHeader: React.FC = ({ + blockTag, +}) => ( + <> + Transactions +
+ For Block +
+ +); + +export default React.memo(BlockTransactionHeader); diff --git a/src/BlockTransactionResults.tsx b/src/BlockTransactionResults.tsx new file mode 100644 index 0000000..74e2783 --- /dev/null +++ b/src/BlockTransactionResults.tsx @@ -0,0 +1,78 @@ +import React, { useContext } from "react"; +import ContentFrame from "./ContentFrame"; +import PageControl from "./search/PageControl"; +import ResultHeader from "./search/ResultHeader"; +import PendingResults from "./search/PendingResults"; +import TransactionItem from "./search/TransactionItem"; +import { useFeeToggler } from "./search/useFeeToggler"; +import { RuntimeContext } from "./useRuntime"; +import { SelectionContext, useSelection } from "./useSelection"; +import { useENSCache } from "./useReverseCache"; +import { ProcessedTransaction } from "./types"; +import { PAGE_SIZE } from "./params"; + +type BlockTransactionResultsProps = { + page?: ProcessedTransaction[]; + total: number; + pageNumber: number; +}; + +const BlockTransactionResults: React.FC = ({ + page, + total, + pageNumber, +}) => { + const selectionCtx = useSelection(); + const [feeDisplay, feeDisplayToggler] = useFeeToggler(); + const { provider } = useContext(RuntimeContext); + const reverseCache = useENSCache(provider, page); + + return ( + +
+
+ {page === undefined ? ( + <>Waiting for search results... + ) : ( + <>A total of {total} transactions found + )} +
+ +
+ + {page ? ( + + {page.map((tx) => ( + + ))} +
+
+ A total of {total} transactions found +
+ +
+
+ ) : ( + + )} +
+ ); +}; + +export default React.memo(BlockTransactionResults); diff --git a/src/BlockTransactions.tsx b/src/BlockTransactions.tsx index 7578d31..8ded619 100644 --- a/src/BlockTransactions.tsx +++ b/src/BlockTransactions.tsx @@ -3,19 +3,11 @@ import { useParams, useLocation } from "react-router"; import { ethers } from "ethers"; import queryString from "query-string"; import StandardFrame from "./StandardFrame"; -import StandardSubtitle from "./StandardSubtitle"; -import ContentFrame from "./ContentFrame"; -import PageControl from "./search/PageControl"; -import ResultHeader from "./search/ResultHeader"; -import PendingResults from "./search/PendingResults"; -import TransactionItem from "./search/TransactionItem"; -import BlockLink from "./components/BlockLink"; +import BlockTransactionHeader from "./BlockTransactionHeader"; +import BlockTransactionResults from "./BlockTransactionResults"; import { ProcessedTransaction } from "./types"; import { PAGE_SIZE } from "./params"; -import { useFeeToggler } from "./search/useFeeToggler"; import { RuntimeContext } from "./useRuntime"; -import { useENSCache } from "./useReverseCache"; -import { SelectionContext, useSelection } from "./useSelection"; type BlockParams = { blockNumber: string; @@ -111,64 +103,16 @@ const BlockTransactions: React.FC = () => { }, [txs, pageNumber]); const total = useMemo(() => txs?.length ?? 0, [txs]); - const reverseCache = useENSCache(provider, page); - document.title = `Block #${blockNumber} Txns | Otterscan`; - const [feeDisplay, feeDisplayToggler] = useFeeToggler(); - - const selectionCtx = useSelection(); - return ( - Transactions -
- For Block -
- -
-
- {page === undefined ? ( - <>Waiting for search results... - ) : ( - <>A total of {total} transactions found - )} -
- -
- - {page ? ( - - {page.map((tx) => ( - - ))} -
-
- A total of {total} transactions found -
- -
-
- ) : ( - - )} -
+ +
); };