2021-08-02 02:53:36 +00:00
|
|
|
import React, { useMemo, useContext } from "react";
|
2021-07-01 18:21:40 +00:00
|
|
|
import { useParams, useLocation } from "react-router";
|
2021-08-08 22:49:45 +00:00
|
|
|
import { BigNumber } from "@ethersproject/bignumber";
|
2021-07-01 18:21:40 +00:00
|
|
|
import queryString from "query-string";
|
|
|
|
import StandardFrame from "./StandardFrame";
|
2021-07-23 22:48:34 +00:00
|
|
|
import BlockTransactionHeader from "./block/BlockTransactionHeader";
|
|
|
|
import BlockTransactionResults from "./block/BlockTransactionResults";
|
2021-07-01 18:21:40 +00:00
|
|
|
import { PAGE_SIZE } from "./params";
|
2021-07-09 05:07:20 +00:00
|
|
|
import { RuntimeContext } from "./useRuntime";
|
2021-08-02 02:53:36 +00:00
|
|
|
import { useBlockTransactions } from "./useErigonHooks";
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
type BlockParams = {
|
|
|
|
blockNumber: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type PageParams = {
|
|
|
|
p?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
const BlockTransactions: React.FC = () => {
|
2021-07-09 05:07:20 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
2021-07-01 18:21:40 +00:00
|
|
|
const params = useParams<BlockParams>();
|
|
|
|
const location = useLocation<PageParams>();
|
|
|
|
const qs = queryString.parse(location.search);
|
|
|
|
let pageNumber = 1;
|
|
|
|
if (qs.p) {
|
|
|
|
try {
|
|
|
|
pageNumber = parseInt(qs.p as string);
|
|
|
|
} catch (err) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const blockNumber = useMemo(
|
2021-08-08 22:49:45 +00:00
|
|
|
() => BigNumber.from(params.blockNumber),
|
2021-07-01 18:21:40 +00:00
|
|
|
[params.blockNumber]
|
|
|
|
);
|
|
|
|
|
2021-08-03 03:45:07 +00:00
|
|
|
const [totalTxs, txs] = useBlockTransactions(
|
|
|
|
provider,
|
2021-08-03 04:34:14 +00:00
|
|
|
blockNumber.toNumber(),
|
|
|
|
pageNumber - 1,
|
|
|
|
PAGE_SIZE
|
2021-08-03 03:45:07 +00:00
|
|
|
);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
document.title = `Block #${blockNumber} Txns | Otterscan`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StandardFrame>
|
2021-07-14 19:57:08 +00:00
|
|
|
<BlockTransactionHeader blockTag={blockNumber.toNumber()} />
|
|
|
|
<BlockTransactionResults
|
2021-08-03 04:34:14 +00:00
|
|
|
page={txs}
|
|
|
|
total={totalTxs ?? 0}
|
2021-07-14 19:57:08 +00:00
|
|
|
pageNumber={pageNumber}
|
|
|
|
/>
|
2021-07-01 18:21:40 +00:00
|
|
|
</StandardFrame>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default React.memo(BlockTransactions);
|