fix: honour selected block on storage queries (#144)
This commit is contained in:
@@ -199,6 +199,10 @@ export const workspaceEntryCtxOrAdd$ = <T>(
|
||||
pushWorkspaceEntry(entryData)
|
||||
}),
|
||||
map((data) => data.context!),
|
||||
catchError((ex) => {
|
||||
console.error(ex)
|
||||
return [null]
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}>
|
||||
>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user