Skip to content

Commit

Permalink
withCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Nov 5, 2024
1 parent 037bea2 commit cc35fbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 12 additions & 11 deletions packages/ui/src/contexts/ApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNetwork } from './NetworkContext'
import { ethereumChains } from '../utils/ethereumChains'
import { createClient, PolkadotClient, TypedApi } from 'polkadot-api'
import { getWsProvider } from 'polkadot-api/ws-provider/web'
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'
import {
acala,
bifrostDot,
Expand Down Expand Up @@ -77,35 +78,35 @@ const ApiContextProvider = ({ children }: ApiContextProps) => {

switch (selectedNetworkInfo?.chainId) {
case 'kusama':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(ksm)
break
case 'asset-hub-dot':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(dotAssetHub)
break
case 'asset-hub-ksm':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(ksmAssetHub)
break
case 'acala':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(acala)
break
case 'bifrost-dot':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(bifrostDot)
break
case 'phala':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(phala)
break
// case 'rhala':
// cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
// typedApi = cl.getTypedApi(rhala)
// break
case 'khala':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(khala)
break
// case 'rococo':
Expand All @@ -116,17 +117,17 @@ const ApiContextProvider = ({ children }: ApiContextProps) => {
// cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
// typedApi = cl.getTypedApi(rococoAssetHub)
// break
case 'hydration':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
case 'hydradx':
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(hydration)
break
case 'paseo':
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(paseo)
break

default:
cl = createClient(getWsProvider(selectedNetworkInfo.rpcUrl))
cl = createClient(withPolkadotSdkCompat(getWsProvider(selectedNetworkInfo.rpcUrl)))
typedApi = cl.getTypedApi(dot)
}
setClient(cl)
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/hooks/useWalletConnectNamespace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export const useGetWalletConnectNamespace = () => {
const [genesisHash, setGenesisHash] = useState('')

useEffect(() => {
if (!client) return

client
?.getChainSpecData()
.getChainSpecData()
.then((data) => setGenesisHash(data.genesisHash))
.catch(console.error)
}, [client])
Expand Down

0 comments on commit cc35fbd

Please sign in to comment.