Skip to content

Commit

Permalink
remove QueryClientProvider initialization from graz
Browse files Browse the repository at this point in the history
  • Loading branch information
karancoder committed Dec 3, 2024
1 parent d31c02c commit 5619f52
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 67 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pnpm add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosm

## Quick start

Wrap your React app with `<GrazProvider />` and use available `graz` hooks anywhere:
Wrap your React app with `<QueryClientProvider />` and `<GrazProvider />`, and use available `graz` hooks anywhere:

```jsx
import { GrazProvider } from "graz";
Expand All @@ -65,11 +65,13 @@ const cosmoshub: ChainInfo = {

function App() {
return (
<GrazProvider grazOptions={{
chains: [cosmoshub]
}}>
<Wallet />
</GrazProvider>
<QueryClientProvider queryClient={queryClient}>
<GrazProvider grazOptions={{
chains: [cosmoshub]
}}>
<Wallet />
</GrazProvider>
</QueryClientProvider>
);
}
```
Expand Down
18 changes: 10 additions & 8 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pnpm add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosm

## Quick start

Wrap your React app with `<GrazProvider />` and use available `graz` hooks anywhere:
Wrap your React app with `<QueryClientProvider />` and `<GrazProvider />`, and use available `graz` hooks anywhere:

```tsx
import { GrazProvider } from "graz";
Expand All @@ -65,13 +65,15 @@ const cosmoshub: ChainInfo = {

function App() {
return (
<GrazProvider
grazOptions={{
chains: [cosmoshub],
}}
>
<Wallet />
</GrazProvider>
<QueryClientProvider queryClient={queryClient}>
<GrazProvider
grazOptions={{
chains: [cosmoshub],
}}
>
<Wallet />
</GrazProvider>
</QueryClientProvider>
);
}
```
Expand Down
63 changes: 34 additions & 29 deletions docs/docs/provider/grazProvider.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GrazProvider

Provider component which wraps @tanstack/react-query's `QueryClientProvider` and various graz side effects
Provider component which configures various graz side effects.
Graz uses `@tanstack/react-query`'s features under the hood, hence you need to wrap `GrazProvider` with `QueryClientProvider`.

#### Usage

Expand All @@ -11,44 +12,48 @@ const cosmoshub = {
chainId: "cosmoshub-4",
chainName: "Cosmos Hub",
// ... rest of cosmoshub ChainInfo
}
};

const sommelier = {
chainId: "sommelier-1",
chainName: "Sommelier",
// ... rest of sommelier ChainInfo
}
};

// example next.js application in _app.tsx
export default function CustomApp({ Component, pageProps }: AppProps) {
const onNotFound = () => {
console.log("not found");
};

return (
<GrazProvider
grazOptions={{
chains: [cosmoshub, sommelier],
chainsConfig: {
"cosmoshub-4": {
gas: {
price: "",
denom: ""
}
<QueryClientProvider queryClient={queryClient}>
<GrazProvider
grazOptions={{
chains: [cosmoshub, sommelier],
chainsConfig: {
"cosmoshub-4": {
gas: {
price: "",
denom: "",
},
},
"sommelier-1": {
gas: {
price: "",
denom: "",
},
},
},
"sommelier-1": {
gas: {
price: "",
denom: ""
}
}
}
defaultWallet: WalletType.LEAP,
onNotFound: () => {
console.log("not found")
},
multiChainFetchConcurrency: 6
// ...
}}
>
<Component {...pageProps} />
</GrazProvider>
defaultWallet: WalletType.LEAP,
onNotFound,
multiChainFetchConcurrency: 6,
// ...
}}
>
<Component {...pageProps} />
</GrazProvider>
</QueryClientProvider>
);
}
```
Expand Down
4 changes: 2 additions & 2 deletions packages/graz/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graz",
"description": "React hooks for Cosmos",
"version": "0.1.29",
"version": "0.2.0",
"author": "Griko Nibras <[email protected]>",
"repository": "https://github.com/graz-sh/graz.git",
"homepage": "https://github.com/graz-sh/graz",
Expand Down Expand Up @@ -49,6 +49,7 @@
"@cosmjs/stargate": "<=0.31.3",
"@cosmjs/tendermint-rpc": "<=0.31.3",
"@leapwallet/cosmos-social-login-capsule-provider": "^0.0.41",
"@tanstack/react-query": "5.62.0",
"react": ">=17"
},
"dependencies": {
Expand All @@ -57,7 +58,6 @@
"@dao-dao/cosmiframe": "0.1.0",
"@keplr-wallet/cosmos": "0.12.156",
"@metamask/providers": "12.0.0",
"@tanstack/react-query": "5.62.0",
"@terra-money/station-connector": "1.1.0",
"@vectis/extension-client": "^0.7.2",
"@walletconnect/sign-client": "2.17.2",
Expand Down
38 changes: 16 additions & 22 deletions packages/graz/src/provider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
import type { QueryClientProviderProps } from "@tanstack/react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { type FC, useEffect } from "react";
import { type FC, type ReactNode, useEffect } from "react";

import type { ConfigureGrazArgs } from "../actions/configure";
import { configureGraz } from "../actions/configure";
import { ClientOnly } from "./client-only";
import { GrazEvents } from "./events";

const queryClient = new QueryClient({
//
});

export type GrazProviderProps = Partial<QueryClientProviderProps> & {
export interface GrazProviderProps {
grazOptions: ConfigureGrazArgs;
};
children: ReactNode;
}

/**
* Provider component which extends `@tanstack/react-query`'s {@link QueryClientProvider} with built-in query client
* and various `graz` side effects
*
* Provider component configures various `graz` side effects.
* Graz uses `@tanstack/react-query`'s features under the hood, hence you need to wrap `GrazProvider` with `QueryClientProvider`.
* @example
* ```tsx
* // example next.js application in _app.tsx
* export default function CustomApp({ Component, pageProps }: AppProps) {
* return (
* <GrazProvider>
* <Component {...pageProps} />
* </GrazProvider>
* <QueryClientProvider queryClient={queryClient}>
* <GrazProvider grazOptions={grazOptions}>
* <Component {...pageProps} />
* </GrazProvider>
* </QueryClientProvider>
* );
* }
* ```
*
* @see https://tanstack.com/query
*/
export const GrazProvider: FC<GrazProviderProps> = ({ children, grazOptions, ...props }) => {
export const GrazProvider: FC<GrazProviderProps> = ({ children, grazOptions }) => {
useEffect(() => {
configureGraz(grazOptions);
}, [grazOptions]);

return (
<QueryClientProvider key="graz-provider" client={queryClient} {...props}>
<ClientOnly>
{children}
<GrazEvents />
</ClientOnly>
</QueryClientProvider>
<ClientOnly>
{children}
<GrazEvents />
</ClientOnly>
);
};

0 comments on commit 5619f52

Please sign in to comment.