otterscan/src/components/BlockLink.tsx

31 lines
703 B
TypeScript
Raw Normal View History

2021-07-01 18:21:40 +00:00
import React from "react";
import { NavLink } from "react-router-dom";
import { BlockTag } from "@ethersproject/abstract-provider";
import { commify } from "@ethersproject/units";
import { blockURL } from "../url";
2021-07-01 18:21:40 +00:00
type BlockLinkProps = {
blockTag: BlockTag;
2021-07-01 18:21:40 +00:00
};
const BlockLink: React.FC<BlockLinkProps> = ({ blockTag }) => {
const isNum = typeof blockTag === "number";
let text = blockTag;
if (isNum) {
text = commify(blockTag);
2021-07-01 18:21:40 +00:00
}
return (
<NavLink
className={`text-link-blue hover:text-link-blue-hover ${
isNum ? "font-blocknum" : "font-hash"
}`}
to={blockURL(blockTag)}
2021-07-01 18:21:40 +00:00
>
{text}
</NavLink>
);
};
export default React.memo(BlockLink);