Fix block number not found
This commit is contained in:
parent
eb32a7bb77
commit
9ca79e838f
|
@ -25,6 +25,7 @@ import { useLatestBlockNumber } from "./useLatestBlock";
|
||||||
import { blockTxsURL } from "./url";
|
import { blockTxsURL } from "./url";
|
||||||
import { useBlockData } from "./useErigonHooks";
|
import { useBlockData } from "./useErigonHooks";
|
||||||
import { useETHUSDOracle } from "./usePriceOracle";
|
import { useETHUSDOracle } from "./usePriceOracle";
|
||||||
|
import BlockNotFound from "./components/BlockNotFound";
|
||||||
|
|
||||||
const Block: React.FC = () => {
|
const Block: React.FC = () => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
@ -35,10 +36,10 @@ const Block: React.FC = () => {
|
||||||
|
|
||||||
const block = useBlockData(provider, blockNumberOrHash);
|
const block = useBlockData(provider, blockNumberOrHash);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (block) {
|
if (block !== undefined) {
|
||||||
document.title = `Block #${block.number} | Otterscan`;
|
document.title = `Block #${blockNumberOrHash} | Otterscan`;
|
||||||
}
|
}
|
||||||
}, [block]);
|
}, [blockNumberOrHash, block]);
|
||||||
|
|
||||||
const extraStr = useMemo(() => {
|
const extraStr = useMemo(() => {
|
||||||
try {
|
try {
|
||||||
|
@ -71,6 +72,9 @@ const Block: React.FC = () => {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</StandardSubtitle>
|
</StandardSubtitle>
|
||||||
|
{block === null && (
|
||||||
|
<BlockNotFound blockNumberOrHash={blockNumberOrHash} />
|
||||||
|
)}
|
||||||
{block && (
|
{block && (
|
||||||
<ContentFrame>
|
<ContentFrame>
|
||||||
<InfoRow title="Block Height">
|
<InfoRow title="Block Height">
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import React from "react";
|
||||||
|
import ContentFrame from "../ContentFrame";
|
||||||
|
|
||||||
|
type BlockNotFoundProps = {
|
||||||
|
blockNumberOrHash: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const BlockNotFound: React.FC<BlockNotFoundProps> = ({ blockNumberOrHash }) => (
|
||||||
|
<>
|
||||||
|
<ContentFrame>
|
||||||
|
<div className="py-4 text-sm">Block "{blockNumberOrHash}" not found.</div>
|
||||||
|
</ContentFrame>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default React.memo(BlockNotFound);
|
|
@ -75,6 +75,9 @@ const Blocks: React.FC<BlocksProps> = ({ latestBlock, targetBlockNumber }) => {
|
||||||
if (_blocks.length > 0 && blockNumber === _blocks[0].number) {
|
if (_blocks.length > 0 && blockNumber === _blocks[0].number) {
|
||||||
return _blocks;
|
return _blocks;
|
||||||
}
|
}
|
||||||
|
if (extBlock === null) {
|
||||||
|
return _blocks;
|
||||||
|
}
|
||||||
|
|
||||||
// Leave the last block because of transition animation
|
// Leave the last block because of transition animation
|
||||||
const newBlocks = [extBlock, ..._blocks].slice(
|
const newBlocks = [extBlock, ..._blocks].slice(
|
||||||
|
|
|
@ -36,7 +36,7 @@ export interface ExtendedBlock extends Block {
|
||||||
export const readBlock = async (
|
export const readBlock = async (
|
||||||
provider: JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
blockNumberOrHash: string
|
blockNumberOrHash: string
|
||||||
) => {
|
): Promise<ExtendedBlock | null> => {
|
||||||
let blockPromise: Promise<any>;
|
let blockPromise: Promise<any>;
|
||||||
if (isHexString(blockNumberOrHash, 32)) {
|
if (isHexString(blockNumberOrHash, 32)) {
|
||||||
blockPromise = provider.send("ots_getBlockDetailsByHash", [
|
blockPromise = provider.send("ots_getBlockDetailsByHash", [
|
||||||
|
@ -47,6 +47,9 @@ export const readBlock = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
const _rawBlock = await blockPromise;
|
const _rawBlock = await blockPromise;
|
||||||
|
if (_rawBlock === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const _block = provider.formatter.block(_rawBlock.block);
|
const _block = provider.formatter.block(_rawBlock.block);
|
||||||
const _rawIssuance = _rawBlock.issuance;
|
const _rawIssuance = _rawBlock.issuance;
|
||||||
|
|
||||||
|
@ -160,11 +163,11 @@ export const useBlockTransactions = (
|
||||||
export const useBlockData = (
|
export const useBlockData = (
|
||||||
provider: JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
blockNumberOrHash: string
|
blockNumberOrHash: string
|
||||||
) => {
|
): ExtendedBlock | null | undefined => {
|
||||||
const [block, setBlock] = useState<ExtendedBlock>();
|
const [block, setBlock] = useState<ExtendedBlock | null | undefined>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _readBlock = async () => {
|
const _readBlock = async () => {
|
||||||
|
@ -199,7 +202,7 @@ export const useTxData = (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _block: ExtendedBlock | undefined;
|
let _block: ExtendedBlock | null | undefined;
|
||||||
if (_response.blockNumber) {
|
if (_response.blockNumber) {
|
||||||
_block = await readBlock(provider, _response.blockNumber.toString());
|
_block = await readBlock(provider, _response.blockNumber.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue