fix uncaught SUSPENSE errors, reset selected entry if it doesn't exist

This commit is contained in:
Victor Oliva
2025-11-14 12:06:02 -03:00
parent 1ffc6c6c23
commit 4820e93017
5 changed files with 32 additions and 18 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
import { chopsticksInstance$ } from "@/chopsticks/chopsticks"
import { chainClient$, client$ } from "@/state/chains/chain.state"
import { SystemEvent } from "@polkadot-api/observable-client"
import { state } from "@react-rxjs/core"
import { liftSuspense, state } from "@react-rxjs/core"
import { combineKeys, partitionByKey } from "@react-rxjs/utils"
import { FixedSizeBinary, HexString, PolkadotClient } from "polkadot-api"
import {
@@ -77,7 +77,7 @@ const finalizedBlocks$ = state(
}),
),
)
finalizedBlocks$.subscribe()
finalizedBlocks$.pipe(liftSuspense()).subscribe()
export const [blockInfo$, recordedBlocks$] = partitionByKey(
client$.pipe(switchMap((client) => client.blocks$)),
@@ -242,7 +242,7 @@ export const inMemoryBlocks$ = state(
blockInfo$(key).pipe(startWith(null)),
).pipe(repeat()),
)
inMemoryBlocks$.subscribe()
inMemoryBlocks$.pipe(liftSuspense()).subscribe()
export const blockHash$ = (hashOrHeight: string) =>
hashOrHeight.length > 63
+17 -5
View File
@@ -2,7 +2,12 @@ import { Spinner } from "@/components/Icons"
import { runtimeCtx$, runtimeCtxAt$ } from "@/state/chains/chain.state"
import { RuntimeContext } from "@polkadot-api/observable-client"
import { Input } from "@polkahub/ui-components"
import { state, useStateObservable } from "@react-rxjs/core"
import {
liftSuspense,
state,
SUSPENSE,
useStateObservable,
} from "@react-rxjs/core"
import { createSignal } from "@react-rxjs/utils"
import { Check, X } from "lucide-react"
import {
@@ -36,10 +41,17 @@ const loadedCtx$ = state(
)
return inner$.pipe(
map((value) => ({
type: "success" as const,
value,
})),
liftSuspense(),
map((value) =>
value === SUSPENSE
? {
type: "loading" as const,
}
: {
type: "success" as const,
value,
},
),
catchError((value) => [
{
type: "error" as const,
+1 -1
View File
@@ -57,7 +57,7 @@ export const Storage = withSubscribe(
}))}
/>
</label>
{partialEntry.pallet && (
{partialEntry.pallet && entries[partialEntry.pallet] && (
<label>
Entry
<SearchableSelect
+9 -9
View File
@@ -1,11 +1,7 @@
import { bytesToString } from "@/components/BinaryInput"
import { getHashParams } from "@/hashParams"
import { client$, selectedChainChanged$ } from "@/state/chains/chain.state"
import {
BlockInfo,
concatMapEager,
RuntimeContext,
} from "@polkadot-api/observable-client"
import { BlockInfo, RuntimeContext } from "@polkadot-api/observable-client"
import { state } from "@react-rxjs/core"
import {
createKeyedSignal,
@@ -18,6 +14,7 @@ import { Binary, Enum, HexString } from "polkadot-api"
import {
catchError,
combineLatest,
combineLatestWith,
concat,
EMPTY,
filter,
@@ -71,7 +68,7 @@ const initialValue$ = palletEntries$.pipe(
export const partialEntry$ = state(
mergeWithKey({ entryChange$, initialValue$ }).pipe(
withLatestFrom(palletEntries$),
combineLatestWith(palletEntries$),
scan(
(acc, [evt, pallets]) => {
const newValue =
@@ -81,7 +78,11 @@ export const partialEntry$ = state(
pallet: acc.pallet ?? evt.payload.pallet,
entry: acc.entry ?? evt.payload.entry,
}
const selectedPallet = newValue.pallet ? pallets[newValue.pallet] : null
let selectedPallet = newValue.pallet ? pallets[newValue.pallet] : null
if (!selectedPallet) {
newValue.pallet = Object.keys(pallets)[0] ?? null
selectedPallet = pallets[newValue.pallet] ?? null
}
if (!selectedPallet?.find((it) => it.name === newValue.entry)) {
newValue.entry = selectedPallet?.[0]?.name ?? null
}
@@ -264,8 +265,7 @@ const getStatus$ = (
switchMap((client) => client.bestBlocks$),
filter((v) => v.length > 1),
map((blocks) => blocks[0]),
// We need a concatMapEager here to make sure that overrides work properly
concatMapEager((block) => queryAt$(block, false)),
switchMap((block) => queryAt$(block, false)),
)
: EMPTY
+2
View File
@@ -35,6 +35,8 @@ const selectedAccountPlugin = createSelectedAccountPlugin()
const pjsWalletProvider = createPjsWalletProvider()
const polkadotVaultProvider = createPolkadotVaultProvider()
const readOnlyProvider$ = canSetStorage$.pipe(
liftSuspense(),
filter((v) => v !== SUSPENSE),
map((fakeSigner) =>
createReadOnlyProvider({
fakeSigner,