Skip to content

Commit

Permalink
needs type guards
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Jan 16, 2025
1 parent 1c676dd commit f774003
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/ui/src/contexts/ApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export const DESCRIPTORS = {
export type ApiDescriptors = keyof typeof DESCRIPTORS
export type Descriptors<Id extends ApiDescriptors> = (typeof DESCRIPTORS)[Id]

export const getDescriptor = (id: ApiDescriptors): Descriptors<ApiDescriptors> => DESCRIPTORS[id]

type ApiContextProps = {
children: React.ReactNode | React.ReactNode[]
}
Expand Down Expand Up @@ -83,11 +81,14 @@ const ApiContextProvider = <Id extends ApiDescriptors>({ children }: ApiContextP
if (!selectedNetworkInfo?.chainId || !selectedNetworkInfo?.descriptor) return

const cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrls)))

const typedApi = cl.getTypedApi(DESCRIPTORS[selectedNetworkInfo.descriptor])
setClient(cl)
const desc = DESCRIPTORS[selectedNetworkInfo.descriptor]
setApi(typedApi as TypedApi<typeof desc>)
const id = selectedNetworkInfo.descriptor as Id
const typedApi = cl.getTypedApi(DESCRIPTORS[id])
setApi(typedApi as TypedApi<Descriptors<Id>>)

// const typedApi = cl.getTypedApi(DESCRIPTORS[selectedNetworkInfo.descriptor])
// setClient(cl)
// setApi(typedApi as TypedApi<Descriptors<Id>>)
setApiDescriptor(selectedNetworkInfo.descriptor)
}, [selectedNetworkInfo])

Expand Down
3 changes: 2 additions & 1 deletion packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["vite/client", "vite-plugin-svgr/client", "cypress", "node", "cypress-wait-until"]
"types": ["vite/client", "vite-plugin-svgr/client", "cypress", "node", "cypress-wait-until"],
"disableSizeLimit": true
},
"include": [
"src/**/*",
Expand Down

0 comments on commit f774003

Please sign in to comment.