Add block navigation buttons
This commit is contained in:
parent
13980c7431
commit
290d5a8b11
|
@ -1,10 +1,16 @@
|
||||||
import React, { useEffect, useState, useMemo } from "react";
|
import React, { useEffect, useState, useMemo } from "react";
|
||||||
import { useParams, NavLink } from "react-router-dom";
|
import { useParams, NavLink } from "react-router-dom";
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { ethers, BigNumber } from "ethers";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import {
|
||||||
|
faChevronLeft,
|
||||||
|
faChevronRight,
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { provider } from "./ethersconfig";
|
import { provider } from "./ethersconfig";
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
import StandardSubtitle from "./StandardSubtitle";
|
import StandardSubtitle from "./StandardSubtitle";
|
||||||
import ContentFrame from "./ContentFrame";
|
import ContentFrame from "./ContentFrame";
|
||||||
|
import NavButton from "./components/NavButton";
|
||||||
import Timestamp from "./components/Timestamp";
|
import Timestamp from "./components/Timestamp";
|
||||||
import GasValue from "./components/GasValue";
|
import GasValue from "./components/GasValue";
|
||||||
import BlockLink from "./components/BlockLink";
|
import BlockLink from "./components/BlockLink";
|
||||||
|
@ -101,9 +107,23 @@ const Block: React.FC = () => {
|
||||||
{block && (
|
{block && (
|
||||||
<ContentFrame>
|
<ContentFrame>
|
||||||
<InfoRow title="Block Height">
|
<InfoRow title="Block Height">
|
||||||
<span className="font-bold">
|
<div className="flex space-x-1 items-baseline">
|
||||||
{ethers.utils.commify(block.number)}
|
<span className="font-bold mr-1">
|
||||||
</span>
|
{ethers.utils.commify(block.number)}
|
||||||
|
</span>
|
||||||
|
<NavButton
|
||||||
|
blockNum={block.number - 1}
|
||||||
|
disabled={block.number === 0}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faChevronLeft} />
|
||||||
|
</NavButton>
|
||||||
|
<NavButton
|
||||||
|
blockNum={block.number + 1}
|
||||||
|
disabled={block.number === 0}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faChevronRight} />
|
||||||
|
</NavButton>
|
||||||
|
</div>
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Timestamp">
|
<InfoRow title="Timestamp">
|
||||||
<Timestamp value={block.timestamp} />
|
<Timestamp value={block.timestamp} />
|
||||||
|
@ -156,7 +176,7 @@ const Block: React.FC = () => {
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Ether Price">N/A</InfoRow>
|
<InfoRow title="Ether Price">N/A</InfoRow>
|
||||||
<InfoRow title="Hash">
|
<InfoRow title="Hash">
|
||||||
<HexValue value={block.hash} />
|
<HexValue value={block.hash} />
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Parent Hash">
|
<InfoRow title="Parent Hash">
|
||||||
<BlockLink blockTag={block.parentHash} />
|
<BlockLink blockTag={block.parentHash} />
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { NavLink } from "react-router-dom";
|
||||||
|
|
||||||
|
type NavButtonProps = {
|
||||||
|
blockNum: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const NavButton: React.FC<NavButtonProps> = ({
|
||||||
|
blockNum,
|
||||||
|
disabled,
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
if (disabled) {
|
||||||
|
return (
|
||||||
|
<span className="bg-link-blue bg-opacity-10 text-gray-400 rounded px-2 py-1 text-xs">
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NavLink
|
||||||
|
className="transition-colors bg-link-blue bg-opacity-10 text-link-blue hover:bg-opacity-100 hover:text-white disabled:bg-link-blue disabled:text-gray-400 disabled:cursor-default rounded px-2 py-1 text-xs"
|
||||||
|
to={`/block/${blockNum}`}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</NavLink>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NavButton;
|
Loading…
Reference in New Issue