Skip to content

Commit

Permalink
Add timeout option (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov authored Sep 2, 2023
1 parent a8283a7 commit a3e1ebe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion utils/gear-hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gear-js/react-hooks",
"version": "0.6.0",
"version": "0.6.1",
"description": "React hooks used across Gear applications",
"author": "Gear Technologies",
"license": "GPL-3.0",
Expand Down
8 changes: 6 additions & 2 deletions utils/gear-hooks/src/context/Api.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, useEffect, useState } from 'react';
import { GearApi } from '@gear-js/api';
import { ProviderProps } from 'types';
import { WsProvider } from '@polkadot/api';

type Value = {
api: GearApi;
Expand All @@ -9,18 +10,21 @@ type Value = {

type Props = ProviderProps & {
providerAddress: string;
timeout?: number;
};

const ApiContext = createContext({} as Value);

function ApiProvider({ providerAddress, children }: Props) {
function ApiProvider({ providerAddress, timeout, children }: Props) {
const [api, setApi] = useState<GearApi>();

const { Provider } = ApiContext;
const value = { api: api as GearApi, isApiReady: !!api };

useEffect(() => {
GearApi.create({ providerAddress }).then(setApi);
const provider = new WsProvider(providerAddress, undefined, undefined, timeout);

GearApi.create({ provider }).then(setApi);
}, []);

return <Provider value={value}>{children}</Provider>;
Expand Down

0 comments on commit a3e1ebe

Please sign in to comment.