Merge branch 'feature/issuance' into develop

This commit is contained in:
Willian Mitsuda 2021-07-03 19:18:10 -03:00
commit 7ec4a4d79e
2 changed files with 40 additions and 6 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,36 @@ 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, _rawReceipts] = await Promise.all([
blockPromise,
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),
unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward),
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,
@ -65,6 +84,7 @@ const Block: React.FC = () => {
try { try {
return block && ethers.utils.toUtf8String(block.extraData); return block && ethers.utils.toUtf8String(block.extraData);
} catch (err) { } catch (err) {
console.error("Error while converting block extra data to string");
console.error(err); console.error(err);
} }
}, [block]); }, [block]);
@ -101,8 +121,19 @@ 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.add(block.feeReward)} />
{!block.feeReward.isZero() && (
<>
{" "}
(<TransactionValue value={block.blockReward} hideUnit /> +{" "}
<TransactionValue value={block.feeReward} hideUnit />)
</>
)}
</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>

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>
); );
}; };