Skip to content

Commit

Permalink
chore: update migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jun 17, 2023
1 parent cb1f506 commit 77cc416
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
8 changes: 4 additions & 4 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ function getSidebar() {
link: '/react/hooks/useContractReads',
},
{
text: 'useContractEventWatch 🚧',
link: '/react/hooks/useContractEventWatch',
text: 'useContractEvent 🚧',
link: '/react/hooks/useContractEvent',
},
{
text: 'useContractWrite 🚧',
Expand Down Expand Up @@ -282,8 +282,8 @@ function getSidebar() {
link: '/react/hooks/useToken',
},
{
text: 'useWaitForTransactionReceipt 🚧',
link: '/react/hooks/useWaitForTransactionReceipt',
text: 'useWaitForTransaction 🚧',
link: '/react/hooks/useWaitForTransaction',
},
{
text: 'useWalletClient 🚧',
Expand Down
54 changes: 21 additions & 33 deletions docs/react/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,21 @@

## 2.0.x Breaking Changes

- No longer publishing separate CJS tag

### createConfig

- Renamed `autoConnect` to `reconnectOnMount`
- Removed `logger` (TODO: should we keep this?)
- `publicClient`/`webSocketClient` versus `transports`/`webSocketTransports` (TODO: need to figure out exactly what this is going to look like)

### Config

- Removed `config.connector` (use `config.state.connections[config.state.current].connector` instead)
- Removed `config.data` (use `config.state.connections[config.state.current]` instead)
- Removed `config.error`
- Removed `config.lastUsedChainId` (use `config.state.connections[config.state.current].chainId` instead)
- Removed `config.publicClient` (use `config.getPublicClient()` instead)
- Removed `config.status` (use `config.state.status` instead)
- Removed `config.webSocketClient` (use `config.getWebSocketClient()` instead) (TODO: not implemented yet)
- Removed `config.clearState` (use `config.reset()` instead)
- Removed `config.autoConnect()` (use `reconnect` action instead)
- Renamed `config.setConnectors` (TODO: Was someone using this? Dynamic? Might want to figure out a better name/API)
- Removed `config.setLastUsedConnector`
- Removed `getConfig` (`config` should be passed explicitly to actions instead of using global `config`)

### WagmiConfig

- Renamed `config` to `value`
- Renamed `Context` to `WagmiContext`
- Renamed `autoConnect` to `reconnectOnMount` and defaulted to `true`.
- Removed `logger`
- `publicClient` versus `transports`

### Chains

- Removed `mainnet` and `sepolia` from main export (use `viem/chains` entrypoint instead)
- Removed `wagmi/chains` entrypoint (use `viem/chains` instead)
- Removed `Chain` type export (use `viem/chains` instead)

### Providers

- Removed `configureChains` (use `createConfig.transports` and `createConfig.webSocketTransports`)
- Removed `alchemy`, `infura`, `public`, `jsonRpc` providers (use `createConfig.transports` and `createConfig.webSocketTransports`)
- Removed `configureChains` (use `createConfig.transports`)
- Removed `alchemy`, `infura`, `public`, `jsonRpc` providers (use `createConfig.transports`)

### Connectors

Expand All @@ -57,15 +34,11 @@

- "Mutation" hooks (e.g. `useConnect`, `useContractWrite`, `useSendTransaction`) now pass through all TanStack Query parameters under the `mutation` key parameter
- "Query" hooks (e.g. `useBalance`, `useEnsName`, `useContractRead`) now pass through all TanStack Query parameters under the `query` key parameter
- Renamed `useContractEvent` to `useContractEventWatch`
- Removed `useNetwork` (use `useAccount.chainId` instead) (TODO: should we add `chain` to `useAccount`?)
- Renamed `useSwitchNetwork` to `useSwitchChain`
- Renamed `useWaitForTransaction` to `useWaitForTransactionReceipt`
- Removed `useInfiniteQuery`, `useMutation`, `useQuery`, `useQueryClient` (TODO: Should we export from wagmi? If TanStack Query was peer dependency, could tell folks to import from there instead.)
- Removed `usePublicClient` (use `config.getPublicClient` instead)
- Removed `useWebSocketClient` (use `config.getWebSocketClient` instead)
- Deprecated `useFeeData`?
- Deprecated `useToken`?

### Constants

Expand Down Expand Up @@ -98,4 +71,19 @@
- Renamed `waitForTransaction` to `waitForTransactionReceipt`
- Renamed `watchNetwork` to `watchChain`
- Removed `watchPublicClient` and `watchWebSocketClient` (TODO: Getters are coming from `config` now. Do we want to keep these?)
- Removed `watchWalletClient` (TODO: Keep this around?)
- Removed `watchWalletClient` (TODO: Keep this around?)

### Config

- Removed `config.connector` (use `config.state.connections[config.state.current].connector` instead)
- Removed `config.data` (use `config.state.connections[config.state.current]` instead)
- Removed `config.error`
- Removed `config.lastUsedChainId` (use `config.state.connections[config.state.current].chainId` instead)
- Removed `config.publicClient` (use `config.getPublicClient()` instead)
- Removed `config.status` (use `config.state.status` instead)
- Removed `config.webSocketClient` (use `config.getWebSocketClient()` instead) (TODO: not implemented yet)
- Removed `config.clearState` (use `config.reset()` instead)
- Removed `config.autoConnect()` (use `reconnect` action instead)
- Renamed `config.setConnectors` (TODO: Was someone using this? Dynamic? Might want to figure out a better name/API)
- Removed `config.setLastUsedConnector` (use `config.storage?.setItem('recentConnectorId', connectorId)` instead)
- Removed `getConfig` (`config` should be passed explicitly to actions instead of using global `config`)
1 change: 1 addition & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function createConfig<
return connector
}

// TODO: WebSocket support
const publicClients = new Map<number, PublicClient | undefined>()
function getPublicClient({
chainId: chainId_,
Expand Down
16 changes: 12 additions & 4 deletions packages/react/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { QueryClientProvider } from '@tanstack/react-query'
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
import { type Config, type ResolvedRegister, reconnect } from '@wagmi/core'
import { type OneOf } from '@wagmi/core/internal'
import * as React from 'react'

export const WagmiContext = React.createContext<
ResolvedRegister['config'] | undefined
>(undefined)

export type WagmiConfigProps = {
value: Config
}
export type WagmiConfigProps = OneOf<
| {
/** @deprecated Use `value` instead */
config: Config
}
| {
value: Config
}
>

export function WagmiConfig({
children,
value,
...props
}: React.PropsWithChildren<WagmiConfigProps>) {
const value = props.config ?? props.value
React.useEffect(() => {
if (typeof window !== 'undefined' && value._internal.reconnectOnMount)
reconnect(value)
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export {
type WagmiConfigProps,
WagmiConfig,
WagmiContext,
/** @deprecated Use `WagmiContext` instead */
WagmiContext as Context,
} from './context.js'

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types/query.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type OmittedUseQueryOptions = 'enabled' | 'suspense'
export type OmittedUseQueryOptions = 'enabled' | 'suspense' | 'throwOnError'

export type OmittedUseMutationResult = 'mutate' | 'mutateAsync'

0 comments on commit 77cc416

Please sign in to comment.