Add block/uncles rewards

This commit is contained in:
Willian Mitsuda 2021-07-03 18:51:57 -03:00
parent 3fdc438d85
commit a62fa1df56
1 changed files with 20 additions and 5 deletions

View File

@ -9,12 +9,16 @@ 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";
import AddressLink from "./components/AddressLink"; import AddressLink from "./components/AddressLink";
import TransactionValue from "./components/TransactionValue";
type BlockParams = { type BlockParams = {
blockNumberOrHash: string; blockNumberOrHash: string;
}; };
interface ExtendedBlock extends ethers.providers.Block { interface ExtendedBlock extends ethers.providers.Block {
blockReward: BigNumber;
unclesReward: BigNumber;
feeReward: BigNumber;
size: number; size: number;
sha3Uncles: string; sha3Uncles: string;
stateRoot: string; stateRoot: string;
@ -27,21 +31,28 @@ const Block: React.FC = () => {
const [block, setBlock] = useState<ExtendedBlock>(); const [block, setBlock] = useState<ExtendedBlock>();
useEffect(() => { useEffect(() => {
const readBlock = async () => { const readBlock = async () => {
let _rawBlock: any; let blockPromise: Promise<any>;
if (ethers.utils.isHexString(params.blockNumberOrHash, 32)) { if (ethers.utils.isHexString(params.blockNumberOrHash, 32)) {
_rawBlock = await provider.send("eth_getBlockByHash", [ blockPromise = provider.send("eth_getBlockByHash", [
params.blockNumberOrHash, params.blockNumberOrHash,
false, false,
]); ]);
} else { } else {
_rawBlock = await provider.send("eth_getBlockByNumber", [ blockPromise = provider.send("eth_getBlockByNumber", [
params.blockNumberOrHash, params.blockNumberOrHash,
false, false,
]); ]);
} }
const [_rawBlock, _rawIssuance] = await Promise.all([
blockPromise,
provider.send("erigon_issuance", [params.blockNumberOrHash]),
]);
const _block = provider.formatter.block(_rawBlock); const _block = provider.formatter.block(_rawBlock);
const extBlock: ExtendedBlock = { const extBlock: ExtendedBlock = {
blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward),
unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward),
feeReward: provider.formatter.bigNumber("0"),
size: provider.formatter.number(_rawBlock.size), size: provider.formatter.number(_rawBlock.size),
sha3Uncles: _rawBlock.sha3Uncles, sha3Uncles: _rawBlock.sha3Uncles,
stateRoot: _rawBlock.stateRoot, stateRoot: _rawBlock.stateRoot,
@ -101,8 +112,12 @@ const Block: React.FC = () => {
<AddressLink address={block.miner} /> <AddressLink address={block.miner} />
</div> </div>
</InfoRow> </InfoRow>
<InfoRow title="Block Reward">N/A</InfoRow> <InfoRow title="Block Reward">
<InfoRow title="Uncles Reward">N/A</InfoRow> <TransactionValue value={block.blockReward} />
</InfoRow>
<InfoRow title="Uncles Reward">
<TransactionValue value={block.unclesReward} />
</InfoRow>
<InfoRow title="Difficult"> <InfoRow title="Difficult">
{ethers.utils.commify(block.difficulty)} {ethers.utils.commify(block.difficulty)}
</InfoRow> </InfoRow>