fix: honour selected block on storage queries (#144)

This commit is contained in:
Victor Oliva
2026-05-22 11:09:43 +02:00
committed by GitHub
parent 60e6ff77f0
commit 7eece919d3
4 changed files with 47 additions and 9 deletions

View File

@@ -199,6 +199,10 @@ export const workspaceEntryCtxOrAdd$ = <T>(
pushWorkspaceEntry(entryData)
}),
map((data) => data.context!),
catchError((ex) => {
console.error(ex)
return [null]
}),
)
}),
)

View File

@@ -81,6 +81,8 @@ const StorageSubscriptionBox: FC<{ id: string }> = ({ id }) => {
return <ValueSubscriptionBox subscription={id} />
case "values":
return <ValuesSubscriptionBox subscription={id} />
case "error":
return <div>Error: {status.value}</div>
}
}

View File

@@ -24,6 +24,10 @@ export const StorageWorkspaceEntry: FC<{
)
}
if (status.type === "error") {
return <p className="text-red-950 p-2">Error: {status.value}</p>
}
if (!status.value.length) return null
const result = status.value[status.value.length - 1].result

View File

@@ -312,17 +312,44 @@ export const storageSubscriptionToWorkspaceEntry = async ({
.buildStorage(pallet, item)
.value.dec(value.value),
}),
)
: getValues$(at, isEntries, keyCodec).pipe(
map((v) => Enum("values", v)),
takeUntil(selectedChainChanged$),
shareReplay({
bufferSize: 1,
refCount: true,
).pipe(
catchError((ex) => {
console.error(ex)
return [Enum("error", String(ex))]
}),
)
const status$: StorageEntryContext["status$"] = state(value$, Enum("loading"))
const completed$ = state(value$.pipe(ignoreElements(), endWith(true)), false)
: blockHash
? at(blockHash).pipe(
map((v) =>
Enum("value", {
blockHash,
...v,
}),
),
catchError((ex) => {
console.error(ex)
return [Enum("error", String(ex))]
}),
)
: getValues$(at, isEntries, keyCodec).pipe(
map((v) => Enum("values", v)),
)
const sharedValue$ = value$.pipe(
takeUntil(selectedChainChanged$),
shareReplay({
bufferSize: 1,
refCount: true,
}),
)
const status$: StorageEntryContext["status$"] = state(
sharedValue$,
Enum("loading"),
)
const completed$ = state(
sharedValue$.pipe(ignoreElements(), endWith(true)),
false,
)
const context: StorageEntryContext = {
id,
@@ -387,6 +414,7 @@ export type StorageEntryContext = {
}
// For subscriptions, adds one new value on every change
values: Array<StorageSubscriptionValue>
error: string
}>
>
}