Calculate and display block fees

This commit is contained in:
Willian Mitsuda 2021-07-03 19:14:03 -03:00
parent a62fa1df56
commit 78c2555689
2 changed files with 22 additions and 4 deletions

View File

@ -43,16 +43,24 @@ const Block: React.FC = () => {
false, false,
]); ]);
} }
const [_rawBlock, _rawIssuance] = await Promise.all([ const [_rawBlock, _rawIssuance, _rawReceipts] = await Promise.all([
blockPromise, blockPromise,
provider.send("erigon_issuance", [params.blockNumberOrHash]), provider.send("erigon_issuance", [params.blockNumberOrHash]),
provider.send("eth_getBlockReceipts", [params.blockNumberOrHash]),
]); ]);
const receipts = (_rawReceipts as any[]).map((r) =>
provider.formatter.receipt(r)
);
const fees = receipts.reduce(
(acc, r) => acc.add(r.effectiveGasPrice.mul(r.gasUsed)),
BigNumber.from(0)
);
const _block = provider.formatter.block(_rawBlock); const _block = provider.formatter.block(_rawBlock);
const extBlock: ExtendedBlock = { const extBlock: ExtendedBlock = {
blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward), blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward),
unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward), unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward),
feeReward: provider.formatter.bigNumber("0"), feeReward: fees,
size: provider.formatter.number(_rawBlock.size), size: provider.formatter.number(_rawBlock.size),
sha3Uncles: _rawBlock.sha3Uncles, sha3Uncles: _rawBlock.sha3Uncles,
stateRoot: _rawBlock.stateRoot, stateRoot: _rawBlock.stateRoot,
@ -113,7 +121,14 @@ const Block: React.FC = () => {
</div> </div>
</InfoRow> </InfoRow>
<InfoRow title="Block Reward"> <InfoRow title="Block Reward">
<TransactionValue value={block.blockReward} /> <TransactionValue value={block.blockReward.add(block.feeReward)} />
{!block.feeReward.isZero() && (
<>
{" "}
(<TransactionValue value={block.blockReward} hideUnit /> +{" "}
<TransactionValue value={block.feeReward} hideUnit />)
</>
)}
</InfoRow> </InfoRow>
<InfoRow title="Uncles Reward"> <InfoRow title="Uncles Reward">
<TransactionValue value={block.unclesReward} /> <TransactionValue value={block.unclesReward} />

View File

@ -5,11 +5,13 @@ import { formatValue } from "./formatter";
type TransactionValueProps = { type TransactionValueProps = {
value: BigNumber; value: BigNumber;
decimals?: number; decimals?: number;
hideUnit?: boolean;
}; };
const TransactionValue: React.FC<TransactionValueProps> = ({ const TransactionValue: React.FC<TransactionValueProps> = ({
value, value,
decimals = 18, decimals = 18,
hideUnit,
}) => { }) => {
const formattedValue = formatValue(value, decimals); const formattedValue = formatValue(value, decimals);
@ -18,7 +20,8 @@ const TransactionValue: React.FC<TransactionValueProps> = ({
className={`text-sm ${value.isZero() ? "text-gray-400" : ""}`} className={`text-sm ${value.isZero() ? "text-gray-400" : ""}`}
title={`${formattedValue} Ether`} title={`${formattedValue} Ether`}
> >
<span className={`font-balance`}>{formattedValue}</span> Ether <span className={`font-balance`}>{formattedValue}</span>
{!hideUnit && " Ether"}
</span> </span>
); );
}; };