Skip to content

Commit

Permalink
Add optional types to ApiPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkNebula0 committed Nov 12, 2021
1 parent 5d3f6d7 commit cbe5cba
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/core/src/providers/substrahooks-provider/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { ApiProviders, SubstraHooksContext } from './context';
import { fetchSystemProperties } from '../../helpers/fetch-system-properties';
import { ExtensionProvider } from '../extension';
import { useIsMountedRef } from '../../helpers/use-is-mounted-ref';
import { RegistryTypes } from '@polkadot/types/types';

const apiProviders: ApiProviders = {};

export type ApiProviderConfig = Record<string, { id: string; wsProviderUrl: string }>;
export type ApiProviderConfig = Record<
string,
{ id: string; wsProviderUrl: string; types?: RegistryTypes }
>;

interface ISubstraHooksProviderProps {
apiProviderConfig: ApiProviderConfig | null;
Expand All @@ -16,10 +20,14 @@ interface ISubstraHooksProviderProps {
children: ReactNode;
}

export const initPolkadotPromise = async (id: string, wsProviderUrl: string) => {
export const initPolkadotPromise = async (
id: string,
wsProviderUrl: string,
types?: RegistryTypes,
) => {
if (apiProviders[id]) return apiProviders[id];
const wsProvider = new WsProvider(wsProviderUrl);
const polkadotApi = await ApiPromise.create({ provider: wsProvider });
const polkadotApi = await ApiPromise.create({ provider: wsProvider, types: types });
await polkadotApi.isReady;
const systemProperties = await fetchSystemProperties(polkadotApi);
apiProviders[id] = {
Expand All @@ -35,6 +43,7 @@ const initAllApis = async (apiProviderConfig: ApiProviderConfig) => {
initPolkadotPromise(
apiProviderConfig[configId].id,
apiProviderConfig[configId].wsProviderUrl,
apiProviderConfig[configId].types,
),
),
);
Expand Down

0 comments on commit cbe5cba

Please sign in to comment.