Skip to content

Commit

Permalink
[Breaking Change]: Update react-query to v5.62.0 (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki authored Dec 10, 2024
2 parents 1cbf5a7 + 3453cec commit f6ff768
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 248 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ 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 { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider } from "graz";

const queryClient = new QueryClient();

const cosmoshub: ChainInfo = {
chainId: "cosmoshub-4",
chainName: "Cosmos Hub",
Expand All @@ -65,11 +68,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
21 changes: 13 additions & 8 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ 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 { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider } from "graz";

const queryClient = new QueryClient();

const cosmoshub: ChainInfo = {
chainId: "cosmoshub-4",
chainName: "Cosmos Hub",
Expand All @@ -65,13 +68,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
19 changes: 19 additions & 0 deletions docs/docs/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ sidebar_position: 3

# Migration Guide

## 0.2.0 Breaking Changes

We updates the react-query version to 5.62.0 and removes QueryClientProvider initialisation from Graz Provider. As a results, dApps must now wrap Graz provider with QueryClientProvider on their end. Also note that react-query has been added as peer dependency now.

```diff
+ import { QueryClient, QueryClientProvider } from 'react-query';
import { GrazProvider } from 'graz';

+ const queryClient = new QueryClient();

+ <QueryClientProvider client={queryClient}>
<GrazProvider grazOptions={{
// ... Your options
}}>
// children
</GrazProvider>
+ </QueryClientProvider>
```

## 0.1.26 Breaking Changes

### WalletConnect
Expand Down
66 changes: 37 additions & 29 deletions docs/docs/provider/grazProvider.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
# 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

```tsx
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider, WalletType } from "graz";

const queryClient = new QueryClient();

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
1 change: 1 addition & 0 deletions example/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@leapwallet/cosmos-social-login-capsule-provider-ui": "^0.0.58",
"@tanstack/react-query": "5.62.0",
"framer-motion": "^10.16.4",
"graz": "workspace:*",
"next": "^13.4.19",
Expand Down
49 changes: 27 additions & 22 deletions example/next/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider } from "graz";
import type { NextPage } from "next";
import type { AppProps } from "next/app";
import { chains } from "utils/graz";

const queryClient = new QueryClient();

const theme = extendTheme();

const CustomApp: NextPage<AppProps> = ({ Component, pageProps }) => {
return (
<ChakraProvider resetCSS theme={theme}>
<GrazProvider
grazOptions={{
chains,
onReconnectFailed: () => {
console.log("reconnect failed");
},
autoReconnect: false,
walletConnect: {
options: {
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
<QueryClientProvider client={queryClient}>
<GrazProvider
grazOptions={{
chains,
onReconnectFailed: () => {
console.log("reconnect failed");
},
autoReconnect: false,
walletConnect: {
options: {
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
},
},
capsuleConfig: {
apiKey: process.env.NEXT_PUBLIC_CAPSULE_API_KEY,
env: process.env.NEXT_PUBLIC_CAPSULE_ENV,
},
iframeOptions: {
allowedIframeParentOrigins: ["https://daodao.zone", "https://dao.daodao.zone", "http://localhost:3000"],
},
},
capsuleConfig: {
apiKey: process.env.NEXT_PUBLIC_CAPSULE_API_KEY,
env: process.env.NEXT_PUBLIC_CAPSULE_ENV,
},
iframeOptions: {
allowedIframeParentOrigins: ["https://daodao.zone", "https://dao.daodao.zone", "http://localhost:3000"],
},
}}
>
<Component {...pageProps} />
</GrazProvider>
}}
>
<Component {...pageProps} />
</GrazProvider>
</QueryClientProvider>
</ChakraProvider>
);
};
Expand Down
1 change: 1 addition & 0 deletions example/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@emotion/styled": "11.11.0",
"@graz-sh/types": "^0.0.4",
"@leapwallet/cosmos-social-login-capsule-provider-ui": "^0.0.58",
"@tanstack/react-query": "5.62.0",
"bignumber.js": "^9.1.2",
"framer-motion": "^10.16.4",
"graz": "workspace:*",
Expand Down
57 changes: 31 additions & 26 deletions example/starter/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider } from "graz";
import type { AppProps } from "next/app";
import { Layout } from "src/ui/layout";
import { mainnetChains } from "src/utils/graz";

const queryClient = new QueryClient();

const theme = extendTheme({
semanticTokens: {
colors: {
Expand All @@ -21,34 +24,36 @@ const theme = extendTheme({

const MyApp = ({ Component, pageProps }: AppProps) => {
return (
<GrazProvider
grazOptions={{
chains: mainnetChains,
walletConnect: {
options: {
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
<QueryClientProvider client={queryClient}>
<GrazProvider
grazOptions={{
chains: mainnetChains,
walletConnect: {
options: {
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID,
},
},
capsuleConfig: {
apiKey: process.env.NEXT_PUBLIC_CAPSULE_API_KEY,
env: process.env.NEXT_PUBLIC_CAPSULE_ENV,
},
walletDefaultOptions: {
sign: {
preferNoSetFee: true,
},
},
},
capsuleConfig: {
apiKey: process.env.NEXT_PUBLIC_CAPSULE_API_KEY,
env: process.env.NEXT_PUBLIC_CAPSULE_ENV,
},
walletDefaultOptions: {
sign: {
preferNoSetFee: true,
iframeOptions: {
allowedIframeParentOrigins: ["https://daodao.zone", "https://dao.daodao.zone"],
},
},
iframeOptions: {
allowedIframeParentOrigins: ["https://daodao.zone", "https://dao.daodao.zone"],
},
}}
>
<ChakraProvider resetCSS theme={theme}>
<Layout>
<Component {...pageProps} />
</Layout>
</ChakraProvider>
</GrazProvider>
}}
>
<ChakraProvider resetCSS theme={theme}>
<Layout>
<Component {...pageProps} />
</Layout>
</ChakraProvider>
</GrazProvider>
</QueryClientProvider>
);
};

Expand Down
1 change: 1 addition & 0 deletions example/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "5.62.0",
"graz": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
24 changes: 17 additions & 7 deletions example/vite/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import "./index.css";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GrazProvider } from "graz";
import { cosmoshub } from "graz/chains";
import * as React from "react";
import * as ReactDOM from "react-dom/client";

import App from "./App";

const queryClient = new QueryClient();

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<GrazProvider
grazOptions={{
chains: [cosmoshub],
}}
>
<App />
</GrazProvider>
<QueryClientProvider client={queryClient}>
<GrazProvider
grazOptions={{
chains: [cosmoshub],
capsuleConfig: {
apiKey: import.meta.env.VITE_CAPSULE_API_KEY as string,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
env: (import.meta.env.VITE_CAPSULE_ENV as "DEV" | "SANDBOX" | "BETA" | "PROD") || "DEV",
},
}}
>
<App />
</GrazProvider>
</QueryClientProvider>
</React.StrictMode>,
);
Loading

0 comments on commit f6ff768

Please sign in to comment.