diff --git a/src/pages/Constants.tsx b/src/pages/Constants.tsx
index bea6fe1..7b9d249 100644
--- a/src/pages/Constants.tsx
+++ b/src/pages/Constants.tsx
@@ -12,27 +12,30 @@ import {
} from "@/components/ui/tooltip"
import { withSubscribe } from "@/components/withSuspense"
import { pushWorkspaceEntry, setWorkspaceOpen } from "@/components/Workspace"
-import { lookup$, runtimeCtx$ } from "@/state/chains/chain.state"
import { getTypeComplexity } from "@/utils/shape"
+import type { RuntimeContext } from "@polkadot-api/observable-client"
import { CodecComponentType } from "@polkadot-api/react-builder"
-import { state, useStateObservable, withDefault } from "@react-rxjs/core"
+import { state, useStateObservable } from "@react-rxjs/core"
import { Dot, SquareEqual } from "lucide-react"
import { HexString } from "polkadot-api"
import { FC, useState } from "react"
import { firstValueFrom, map } from "rxjs"
import { twMerge } from "tailwind-merge"
import { v4 } from "uuid"
+import { BlockPicker, selectedBlock$ } from "./Storage/BlockPicker"
import { ValueDisplay } from "./Storage/StorageSubscriptions"
const metadataConstants$ = state(
- lookup$.pipe(
- map((lookup) =>
- lookup.metadata.pallets
+ selectedBlock$.pipe(
+ map(({ ctx }) =>
+ [...ctx.lookup.metadata.pallets]
.filter((p) => p.constants.length > 0)
.sort((a, b) => a.name.localeCompare(b.name))
.map((p) => ({
name: p.name,
- constants: p.constants.sort((a, b) => a.name.localeCompare(b.name)),
+ constants: [...p.constants].sort((a, b) =>
+ a.name.localeCompare(b.name),
+ ),
})),
),
),
@@ -43,8 +46,14 @@ export const Constants = withSubscribe(
const entries = useStateObservable(metadataConstants$)
return (
-
-
+
+
+
+
+
{entries.map(({ name, constants }) => (
))}
@@ -66,21 +75,13 @@ const PalletConstants: FC<{
docs: string[]
}>
}> = ({ pallet, entries }) => {
- const [expanded, setExpanded] = useState(false)
-
return (
- -
-
setExpanded((e) => !e)}
- >
-
-
{pallet}
+
-
+
+
{pallet}
{
- evt.stopPropagation()
- const ctx = await firstValueFrom(runtimeCtx$)
+ onClick={async () => {
+ const { ctx } = await firstValueFrom(selectedBlock$)
addPalletConstantsToWorkspace(
pallet,
@@ -97,13 +98,11 @@ const PalletConstants: FC<{
}}
/>
- {expanded && (
-
- {entries.map((props) => (
-
- ))}
-
- )}
+
+ {entries.map((props) => (
+
+ ))}
+
)
}
@@ -137,10 +136,11 @@ const ConstantsWorkspaceEntry: FC<{ context: ConstantsWorkspaceContext }> = ({
}
const constantValueProps$ = state(
- runtimeCtx$.pipe(
- map(({ dynamicBuilder, lookup }) => ({
- builder: dynamicBuilder,
- lookup,
+ selectedBlock$.pipe(
+ map(({ ctx }) => ({
+ ctx,
+ builder: ctx.dynamicBuilder,
+ lookup: ctx.lookup,
})),
),
null,
@@ -162,15 +162,22 @@ const ConstantEntry: FC<{
const titleElement = (
setExpanded((e) => !e)}
>
- {isInline ?
:
}
+
+ {isInline ? : }
+
-
-
+
+
{name + (isInline ? ":" : "")}
@@ -181,23 +188,26 @@ const ConstantEntry: FC<{
) : null}
{isInline ? (
-
+
+
+
) : null}
)
return (
- -
+
-
{titleElement}
{!isInline && expanded && (
@@ -206,17 +216,15 @@ const ConstantEntry: FC<{
)
}
-const defaultedCtx$ = runtimeCtx$.pipeState(withDefault(null))
-const ConstantValue: FC<{ type: number; decoded: unknown }> = ({
- type,
- decoded,
-}) => {
+const ConstantValue: FC<{
+ ctx: Pick
+ type: number
+ decoded: unknown
+}> = ({ ctx, type, decoded }) => {
const [mode, setMode] = useState<"json" | "decoded">("decoded")
- const ctx = useStateObservable(defaultedCtx$)
- if (!ctx) return null
return (
-