otterscan/src/block/BlockTransactionResults.tsx

83 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-09-01 10:19:36 +00:00
import React, { useContext, useMemo } from "react";
2021-08-31 19:49:52 +00:00
import { BlockTag } from "@ethersproject/abstract-provider";
2021-07-23 22:48:34 +00:00
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 { ProcessedTransaction } from "../types";
2021-07-23 22:48:34 +00:00
import { PAGE_SIZE } from "../params";
2021-08-31 19:49:52 +00:00
import { useMultipleETHUSDOracle } from "../usePriceOracle";
2021-07-14 19:57:08 +00:00
type BlockTransactionResultsProps = {
2021-08-31 19:49:52 +00:00
blockTag: BlockTag;
2021-07-14 19:57:08 +00:00
page?: ProcessedTransaction[];
total: number;
pageNumber: number;
};
const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
2021-08-31 19:49:52 +00:00
blockTag,
2021-07-14 19:57:08 +00:00
page,
total,
pageNumber,
}) => {
const { provider } = useContext(RuntimeContext);
2021-07-14 19:57:08 +00:00
const selectionCtx = useSelection();
const [feeDisplay, feeDisplayToggler] = useFeeToggler();
2021-09-01 10:19:36 +00:00
const blockTags = useMemo(() => [blockTag], [blockTag]);
const priceMap = useMultipleETHUSDOracle(provider, blockTags);
2021-07-14 19:57:08 +00:00
return (
<ContentFrame>
<div className="flex justify-between items-baseline py-3">
<div className="text-sm text-gray-500">
{page === undefined ? (
<>Waiting for search results...</>
) : (
<>A total of {total} transactions found</>
)}
</div>
<PageControl
pageNumber={pageNumber}
pageSize={PAGE_SIZE}
total={total}
/>
</div>
<ResultHeader
feeDisplay={feeDisplay}
feeDisplayToggler={feeDisplayToggler}
/>
{page ? (
<SelectionContext.Provider value={selectionCtx}>
{page.map((tx) => (
<TransactionItem
key={tx.hash}
tx={tx}
feeDisplay={feeDisplay}
2021-08-31 19:49:52 +00:00
priceMap={priceMap}
2021-07-14 19:57:08 +00:00
/>
))}
<div className="flex justify-between items-baseline py-3">
<div className="text-sm text-gray-500">
A total of {total} transactions found
</div>
<PageControl
pageNumber={pageNumber}
pageSize={PAGE_SIZE}
total={total}
/>
</div>
</SelectionContext.Provider>
) : (
<PendingResults />
)}
</ContentFrame>
);
};
export default React.memo(BlockTransactionResults);