otterscan/src/special/london/BlockRow.tsx

71 lines
2.2 KiB
TypeScript
Raw Normal View History

import React from "react";
import { ethers, FixedNumber } from "ethers";
2021-07-30 07:41:29 +00:00
import BlockLink from "../../components/BlockLink";
import TimestampAge from "../../components/TimestampAge";
import { ExtendedBlock } from "../../useErigonHooks";
2021-08-04 05:09:08 +00:00
import Blip from "./Blip";
const ELASTICITY_MULTIPLIER = 2;
2021-07-30 07:42:39 +00:00
type BlockRowProps = {
2021-07-30 02:46:59 +00:00
now: number;
block: ExtendedBlock;
2021-08-04 05:09:08 +00:00
baseFeeDelta: number;
};
2021-08-04 05:09:08 +00:00
const BlockRow: React.FC<BlockRowProps> = ({ now, block, baseFeeDelta }) => {
const gasTarget = block.gasLimit.div(ELASTICITY_MULTIPLIER);
const burntFees =
block?.baseFeePerGas && block.baseFeePerGas.mul(block.gasUsed);
const netFeeReward = block && block.feeReward.sub(burntFees ?? 0);
const totalReward = block.blockReward.add(netFeeReward ?? 0);
return (
2021-08-05 13:01:05 +00:00
<div className="grid grid-cols-9 gap-x-2 px-3 py-2 hover:bg-gray-100">
<div>
<BlockLink blockTag={block.number} />
</div>
<div
className={`text-right ${
block.gasUsed.gt(gasTarget)
? "text-green-500"
: block.gasUsed.lt(gasTarget)
? "text-red-500"
: ""
}`}
>
{ethers.utils.commify(block.gasUsed.toString())}
</div>
2021-07-30 08:18:28 +00:00
<div className="text-right text-gray-400">
2021-07-30 02:05:23 +00:00
{ethers.utils.commify(gasTarget.toString())}
</div>
2021-08-04 05:09:08 +00:00
<div className="text-right">
<div className="relative">
<span>
{FixedNumber.from(block.baseFeePerGas)
.divUnsafe(FixedNumber.from(1e9))
.round(0)
.toUnsafeFloat()}{" "}
Gwei
</span>
2021-08-04 05:09:08 +00:00
<Blip value={baseFeeDelta} />
</div>
</div>
2021-07-30 02:05:23 +00:00
<div className="text-right col-span-2">
{ethers.utils.commify(ethers.utils.formatEther(totalReward))} Ether
</div>
2021-08-05 13:01:05 +00:00
<div className="text-right col-span-2 line-through text-orange-500">
{ethers.utils.commify(
2021-08-05 13:01:05 +00:00
ethers.utils.formatEther(block.gasUsed.mul(block.baseFeePerGas!))
)}{" "}
2021-08-05 13:51:31 +00:00
Ether
</div>
2021-07-30 08:18:28 +00:00
<div className="text-right text-gray-400">
2021-07-30 02:46:59 +00:00
<TimestampAge now={now / 1000} timestamp={block.timestamp} />
2021-07-30 02:32:29 +00:00
</div>
</div>
);
};
2021-07-30 07:42:39 +00:00
export default React.memo(BlockRow);