diff --git a/src/components/CircularProgress.tsx b/src/components/CircularProgress.tsx
new file mode 100644
index 0000000..84ae2e4
--- /dev/null
+++ b/src/components/CircularProgress.tsx
@@ -0,0 +1,65 @@
+import { FC } from "react"
+
+const SIZE = 50
+const STROKE_W = 4
+const CENTER = SIZE / 2
+const RADIUS = CENTER - STROKE_W
+const PERIMTER = Math.PI * 2 * RADIUS
+export const CircularProgress: FC<{
+ text: string
+ progress: number | null
+}> = ({ text, progress }) => {
+ return (
+
+ )
+}
diff --git a/src/pages/Explorer/BlockPopover.tsx b/src/pages/Explorer/BlockPopover.tsx
new file mode 100644
index 0000000..588e3f9
--- /dev/null
+++ b/src/pages/Explorer/BlockPopover.tsx
@@ -0,0 +1,161 @@
+import { lookup$ } from "@/chain.state"
+import { groupBy } from "@/lib/groupBy"
+import { getDynamicBuilder } from "@polkadot-api/metadata-builders"
+import { state, useStateObservable } from "@react-rxjs/core"
+import { FC, ReactNode } from "react"
+import { map } from "rxjs"
+import { blockInfo$, BlockState } from "./block.state"
+import { filterEvt } from "./Events"
+import { CircularProgress } from "@/components/CircularProgress"
+import { CircleAlert, CircleCheck, CircleX, Clock } from "lucide-react"
+
+const blockInfoState$ = state((hash: string) => blockInfo$(hash), null)
+const maxBlockWeight$ = state(
+ lookup$.pipe(
+ map((lookup) => {
+ const ct = lookup.metadata.pallets
+ .find((p) => p.name === "System")
+ ?.constants.find((ct) => ct.name === "BlockWeights")
+ if (!ct) return null
+ return getDynamicBuilder(lookup).buildDefinition(ct.type).dec(ct.value)
+ .max_block as Weight
+ }),
+ ),
+ null,
+)
+export const BlockPopover: FC<{ hash: string }> = ({ hash }) => {
+ const block = useStateObservable(blockInfoState$(hash))
+ if (!block) return null
+
+ const eventGroups = block.events
+ ? groupBy(block.events, (evt) => evt.phase.type)
+ : null
+ const filteredEvents =
+ eventGroups?.["ApplyExtrinsic"]?.filter(filterEvt).length ?? 0
+
+ const extrinsicEvents = block.events?.filter(
+ (evt) =>
+ evt.event.type === "System" &&
+ ["ExtrinsicFailed", "ExtrinsicSuccess"].includes(evt.event.value.type),
+ )
+ const weight =
+ extrinsicEvents
+ ?.map(
+ (evt) =>
+ (evt.event.value.value.dispatch_info?.weight ??
+ null) as Weight | null,
+ )
+ .reduce(addWeight, {
+ proof_size: 0n,
+ ref_time: 0n,
+ }) ?? null
+
+ return (
+
+
+ Block{" "}
+
+ {hash}
+
+
+
Status: {statusRep[block.status]}
+
+ {eventGroups && (
+
+
Events
+
+
+
+ | Initialization |
+
+ {eventGroups["Initialization"]?.length ?? 0}
+ |
+
+
+ | Extrinsic |
+
+ {filteredEvents}/
+ {eventGroups["ApplyExtrinsic"]?.length ?? 0}
+ (filtered/total)
+ |
+
+
+ | Finalization |
+
+ {eventGroups["Finalization"]?.length ?? 0}
+ |
+
+
+
+
+ )}
+
+
+
+ )
+}
+
+const WeightLimits: FC<{ weight: Weight | null }> = ({ weight }) => {
+ const maxBlockWeight = useStateObservable(maxBlockWeight$)
+ if (!weight || !maxBlockWeight) return null
+
+ const refTimeP = Number(weight.ref_time) / Number(maxBlockWeight.ref_time)
+ const proofSizeP =
+ Number(weight.proof_size) / Number(maxBlockWeight.proof_size)
+ const pct = (progress: number) => Math.round(progress * 100) + "%"
+
+ return (
+
+
+ Ref Time
+
+
+
+ Proof Size
+
+
+
+ )
+}
+
+type Weight = {
+ ref_time: bigint
+ proof_size: bigint
+}
+function addWeight(a: Weight, b: Weight | null): Weight {
+ if (!b) {
+ console.warn("some weight is undefined", { a, b })
+ return a
+ }
+ return {
+ proof_size: a.proof_size + b.proof_size,
+ ref_time: a.ref_time + b.ref_time,
+ }
+}
+
+const statusRep: Record = {
+ [BlockState.Best]: (
+
+
+ Pending
+
+ ),
+ [BlockState.Fork]: (
+
+
+ Fork
+
+ ),
+ [BlockState.Finalized]: (
+
+
+ Finalized
+
+ ),
+ [BlockState.Pruned]: (
+
+
+ Pruned
+
+ ),
+}
diff --git a/src/pages/Explorer/BlockTable.tsx b/src/pages/Explorer/BlockTable.tsx
index 9712fe4..587f154 100644
--- a/src/pages/Explorer/BlockTable.tsx
+++ b/src/pages/Explorer/BlockTable.tsx
@@ -1,4 +1,5 @@
import { CopyText } from "@/components/Copy"
+import { Popover } from "@/components/Popover"
import { state, useStateObservable } from "@react-rxjs/core"
import { FC } from "react"
import { combineLatest, debounceTime, map, switchMap } from "rxjs"
@@ -9,6 +10,7 @@ import {
chainHead$,
finalized$,
} from "./block.state"
+import { BlockPopover } from "./BlockPopover"
const best$ = chainHead$.pipeState(switchMap((chainHead) => chainHead.best$))
@@ -147,18 +149,21 @@ export const BlockTable = () => {
- finalized.number
- ? "opacity-80"
- : "opacity-50",
- )}
- >
- {row.block.hash}
-
+ }>
+
+
|
diff --git a/src/pages/Explorer/BlockTime.tsx b/src/pages/Explorer/BlockTime.tsx
index 0b5cc9e..195c66d 100644
--- a/src/pages/Explorer/BlockTime.tsx
+++ b/src/pages/Explorer/BlockTime.tsx
@@ -1,4 +1,5 @@
import { lookup$ } from "@/chain.state"
+import { CircularProgress } from "@/components/CircularProgress"
import { getDynamicBuilder } from "@polkadot-api/metadata-builders"
import { state, useStateObservable } from "@react-rxjs/core"
import {
@@ -57,65 +58,8 @@ const timeProps$ = state(
},
)
-const SIZE = 50
-const STROKE_W = 4
-const CENTER = SIZE / 2
-const RADIUS = CENTER - STROKE_W
-const PERIMTER = Math.PI * 2 * RADIUS
export const BlockTime = () => {
const { time, progress } = useStateObservable(timeProps$)
- return (
-
- )
+ return
}
diff --git a/src/pages/Explorer/Events.tsx b/src/pages/Explorer/Events.tsx
index 66804d9..8908f36 100644
--- a/src/pages/Explorer/Events.tsx
+++ b/src/pages/Explorer/Events.tsx
@@ -45,7 +45,7 @@ export const Events = () => {
return (
+ !blackList.has(`${evt.event.type}.*`) &&
+ !blackList.has(`${evt.event.type}.${evt.event.value.type}`)
interface EventInfo {
status: BlockState
@@ -149,11 +152,7 @@ const recentEvents$ = state(
number: block.number,
events: block.events
?.filter((evt) => evt.phase.type === "ApplyExtrinsic")
- .filter(
- (evt) =>
- !blackList.has(`${evt.event.type}.*`) &&
- !blackList.has(`${evt.event.type}.${evt.event.value.type}`),
- )
+ .filter(filterEvt)
.map((evt) => ({
event: evt.event,
extrinsicNumber: (evt.phase as any).value as number,