Skip to content

Commit

Permalink
add ApiProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Mar 5, 2024
1 parent d7f7a43 commit 40b669b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TagsProvider } from 'contexts/Tags';
import { ChainFilterProvider } from 'contexts/ChainFilter';
import { SettingsProvider } from 'contexts/Settings';
import { TooltipProvider } from 'contexts/Tooltip';
import { ApiProvider } from 'contexts/Api';

export const Providers = () => {
// !! Provider order matters.
Expand All @@ -21,6 +22,7 @@ export const Providers = () => {
ChainFilterProvider,
MenuProvider,
TooltipProvider,
ApiProvider,
];

return withProviders(providers, App);
Expand Down
8 changes: 8 additions & 0 deletions src/contexts/Api/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2024 @rossbulat/console authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { ApiContextInterface } from './types';

export const defaultApiContext: ApiContextInterface = {
isReady: false,
};
21 changes: 21 additions & 0 deletions src/contexts/Api/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 @rossbulat/console authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { ReactNode } from 'react';
import { createContext, useContext } from 'react';
import { defaultApiContext } from './defaults';
import type { ApiContextInterface } from './types';

export const Api = createContext<ApiContextInterface>(defaultApiContext);

export const useApi = () => useContext(Api);

export const ApiProvider = ({ children }: { children: ReactNode }) => (
<Api.Provider
value={{
isReady: false,
}}
>
{children}
</Api.Provider>
);
6 changes: 6 additions & 0 deletions src/contexts/Api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 @rossbulat/console authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

export interface ApiContextInterface {
isReady: boolean;
}

0 comments on commit 40b669b

Please sign in to comment.