From 6f151aecf685de66332f4da239735f5e2fabffcf Mon Sep 17 00:00:00 2001 From: Jaco Date: Sun, 2 May 2021 18:42:09 +0300 Subject: [PATCH] Expand block summary (#5189) --- .../page-explorer/src/BlockInfo/ByHash.tsx | 5 + .../page-explorer/src/BlockInfo/Summary.tsx | 100 ++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 packages/page-explorer/src/BlockInfo/Summary.tsx diff --git a/packages/page-explorer/src/BlockInfo/ByHash.tsx b/packages/page-explorer/src/BlockInfo/ByHash.tsx index b6d6f0112c..d2bb03b535 100644 --- a/packages/page-explorer/src/BlockInfo/ByHash.tsx +++ b/packages/page-explorer/src/BlockInfo/ByHash.tsx @@ -17,6 +17,7 @@ import { useTranslation } from '../translate'; import Extrinsics from './Extrinsics'; import Justifications from './Justifications'; import Logs from './Logs'; +import Summary from './Summary'; interface Props { className?: string; @@ -80,6 +81,10 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme return (
+ | null { + const { t } = useTranslation(); + + const totalWeight = useMemo( + () => events + ?.filter(({ record: { event: { method, section } } }) => + section === 'system' && + ['ExtrinsicFailed', 'ExtrinsicSuccess'].includes(method) + ) + .reduce((weight: BN, { record: { event: { data, method } } }) => + weight.iadd( + (method === 'ExtrinsicSuccess' + ? data[0] as DispatchInfo + : data[1] as DispatchInfo + ).weight + ), new BN(0) + ), + [events] + ); + + const deposits = useMemo( + () => events + ?.filter(({ record: { event: { method, section } } }) => + section === 'balances' && + ['Deposit'].includes(method) + ) + .reduce((deposits: BN, { record: { event: { data } } }) => + deposits.iadd( + data[1] as Balance + ), new BN(0) + ), + [events] + ); + + const transfers = useMemo( + () => events + ?.filter(({ record: { event: { method, section } } }) => + section === 'balances' && + ['Transfer'].includes(method) + ) + .reduce((deposits: BN, { record: { event: { data } } }) => + deposits.iadd( + data[2] as Balance + ), new BN(0) + ), + [events] + ); + + if (!events || !signedBlock) { + return null; + } + + return ( + +
+ ('deposits')}> + + + ('transfers')}> + + +
+
+ ('block weight')}> + {formatNumber(totalWeight)} + +
+
+ ('event count')}> + {formatNumber(events.length)} + + ('extrinsic count')}> + {formatNumber(signedBlock.block.extrinsics.length)} + +
+
+ ); +} + +export default React.memo(Summary);