Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout option #1371

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading