otterscan/src/BlockTransactions.tsx

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-02 02:53:36 +00:00
import React, { useMemo, useContext } from "react";
2021-11-25 09:28:45 +00:00
import { useParams } from "react-router";
import { BigNumber } from "@ethersproject/bignumber";
2021-07-01 18:21:40 +00:00
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-11-25 09:28:45 +00:00
import { useSearchParams } from "react-router-dom";
2021-07-01 18:21:40 +00:00
const BlockTransactions: React.FC = () => {
2021-07-09 05:07:20 +00:00
const { provider } = useContext(RuntimeContext);
2021-11-25 09:28:45 +00:00
const params = useParams();
const [searchParams] = useSearchParams();
2021-07-01 18:21:40 +00:00
let pageNumber = 1;
2021-11-25 09:28:45 +00:00
const p = searchParams.get("p");
if (p) {
2021-07-01 18:21:40 +00:00
try {
2021-11-25 09:28:45 +00:00
pageNumber = parseInt(p);
2021-07-01 18:21:40 +00:00
} catch (err) {}
}
const blockNumber = useMemo(
() => 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-31 19:49:52 +00:00
blockTag={blockNumber.toNumber()}
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>
);
};
2021-11-25 09:28:45 +00:00
export default BlockTransactions;