Skip to content

Commit

Permalink
Merge pull request #1 from gamedaoco/darknebula/provider-update
Browse files Browse the repository at this point in the history
Darknebula/provider update
  • Loading branch information
2075 authored Nov 12, 2021
2 parents b2ac26a + cbe5cba commit 7afaf41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "substra-hooks",
"private": true,
"version": "0.0.17",
"engines": {
"node": ">=14",
"yarn": "^1.22.11"
Expand Down
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 7afaf41

Please sign in to comment.