diff --git a/src/pages/Storage/Storage.tsx b/src/pages/Storage/Storage.tsx
index f28e2c4..33a8d78 100644
--- a/src/pages/Storage/Storage.tsx
+++ b/src/pages/Storage/Storage.tsx
@@ -45,12 +45,19 @@ export const Storage = withSubscribe(() => {
}
if (storageEntry.tag === "plain") {
- return setSelectedEntry({ value: storageEntry.value, key: [] })
+ return setSelectedEntry({
+ value: storageEntry.value,
+ key: [],
+ pallet: pallet!,
+ entry: entry!,
+ })
}
if (storageEntry.value.hashers.length === 1) {
return setSelectedEntry({
value: storageEntry.value.value,
key: [storageEntry.value.key],
+ pallet: pallet!,
+ entry: entry!,
})
}
@@ -67,6 +74,8 @@ export const Storage = withSubscribe(() => {
setSelectedEntry({
key,
value: storageEntry.value.value,
+ pallet: pallet!,
+ entry: entry!,
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedPallet, entry])
diff --git a/src/pages/Storage/StorageQuery.tsx b/src/pages/Storage/StorageQuery.tsx
index ce2079d..01791eb 100644
--- a/src/pages/Storage/StorageQuery.tsx
+++ b/src/pages/Storage/StorageQuery.tsx
@@ -1,15 +1,25 @@
import SliderToggle from "@/components/Toggle"
-import { useStateObservable, withDefault } from "@react-rxjs/core"
-import { createSignal } from "@react-rxjs/utils"
+import { state, useStateObservable, withDefault } from "@react-rxjs/core"
+import { combineKeys, createSignal } from "@react-rxjs/utils"
import { FC } from "react"
-import { filter, map, scan, startWith, switchMap } from "rxjs"
+import { combineLatest, filter, map, scan, startWith, switchMap } from "rxjs"
import { selectedEntry$ } from "./storage.state"
+import { NOTIN } from "@codec-components"
+import { ActionButton } from "@/components/ActionButton"
+import { lookup$ } from "@/chain.state"
+import { getDynamicBuilder } from "@polkadot-api/metadata-builders"
+import { CopyText } from "@/components/Copy"
+import { twMerge } from "tailwind-merge"
export const StorageQuery: FC = () => {
+ const isReady = useStateObservable(isReady$)
+
return (
-
+ <>
-
+
+ Query
+ >
)
}
@@ -39,6 +49,36 @@ const keysEnabled$ = keys$.pipeState(
withDefault(0),
)
+const [keyValueChange$, setKeyValue] = createSignal<{
+ idx: number
+ value: unknown | NOTIN
+}>()
+const keyValues$ = keys$.pipeState(
+ switchMap((keys) => {
+ const values: unknown[] = keys.map(() => NOTIN)
+ return keyValueChange$.pipe(
+ scan((acc, change) => {
+ const newValue = [...acc]
+ newValue[change.idx] = change.value
+ return newValue
+ }, values),
+ startWith(values),
+ )
+ }),
+ withDefault([] as unknown[]),
+)
+
+const isReady$ = state(
+ combineLatest([keyValues$, keysEnabled$]).pipe(
+ map(
+ ([keyValues, keysEnabled]) =>
+ keyValues.length >= keysEnabled &&
+ keyValues.slice(0, keysEnabled).every((v) => v !== NOTIN),
+ ),
+ ),
+ false,
+)
+
const StorageKeysInput: FC = () => {
const keys = useStateObservable(keys$)
const keysEnabled = useStateObservable(keysEnabled$)
@@ -63,8 +103,48 @@ const StorageKeyInput: FC<{ type: number; disabled: boolean }> = ({
disabled,
}) => {
return (
-
+
Key type={type} enabled={String(!disabled)}
)
}
+
+const encodedKey$ = state(
+ combineLatest([lookup$, selectedEntry$, keyValues$, keysEnabled$]).pipe(
+ map(([lookup, selectedEntry, keyValues, keysEnabled]) => {
+ const args = keyValues.slice(0, keysEnabled)
+ if (
+ keyValues.length < keysEnabled ||
+ !args.every((v) => v !== NOTIN) ||
+ !selectedEntry
+ ) {
+ return null
+ }
+
+ const codec = getDynamicBuilder(lookup).buildStorage(
+ selectedEntry.pallet,
+ selectedEntry.entry,
+ )
+ return codec.enc(...args)
+ }),
+ ),
+ null,
+)
+const KeyDisplay: FC = () => {
+ const key = useStateObservable(encodedKey$)
+
+ return (
+
+
Encoded key:
+
+ {key ?? "Fill in all the storage keys to calculate the encoded key"}
+
+
+
+ )
+}
diff --git a/src/pages/Storage/storage.state.ts b/src/pages/Storage/storage.state.ts
index a67c929..986fcae 100644
--- a/src/pages/Storage/storage.state.ts
+++ b/src/pages/Storage/storage.state.ts
@@ -2,6 +2,8 @@ import { state } from "@react-rxjs/core"
import { createSignal } from "@react-rxjs/utils"
export type StorageMetadataEntry = {
+ pallet: string
+ entry: string
key: number[]
value: number
}