wagmi 0.2.24 → 0.3.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +54 -35
  2. package/connectors/coinbaseWallet/dist/wagmi-connectors-coinbaseWallet.cjs.d.ts +1 -0
  3. package/connectors/coinbaseWallet/dist/wagmi-connectors-coinbaseWallet.cjs.dev.js +12 -0
  4. package/connectors/coinbaseWallet/dist/wagmi-connectors-coinbaseWallet.cjs.js +7 -0
  5. package/connectors/coinbaseWallet/dist/wagmi-connectors-coinbaseWallet.cjs.prod.js +12 -0
  6. package/connectors/coinbaseWallet/dist/wagmi-connectors-coinbaseWallet.esm.js +1 -0
  7. package/connectors/coinbaseWallet/package.json +4 -0
  8. package/connectors/injected/dist/wagmi-connectors-injected.cjs.dev.js +2 -2
  9. package/connectors/injected/dist/wagmi-connectors-injected.cjs.prod.js +2 -2
  10. package/connectors/injected/dist/wagmi-connectors-injected.esm.js +1 -1
  11. package/connectors/walletConnect/dist/wagmi-connectors-walletConnect.cjs.dev.js +1 -1
  12. package/connectors/walletConnect/dist/wagmi-connectors-walletConnect.cjs.prod.js +1 -1
  13. package/connectors/walletConnect/dist/wagmi-connectors-walletConnect.esm.js +1 -1
  14. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +1 -0
  15. package/dist/declarations/src/connectors/injected.d.ts +1 -1
  16. package/dist/declarations/src/connectors/walletConnect.d.ts +1 -1
  17. package/dist/declarations/src/context.d.ts +12 -59
  18. package/dist/declarations/src/hooks/accounts/index.d.ts +1 -0
  19. package/dist/declarations/src/hooks/accounts/useAccount.d.ts +30 -11
  20. package/dist/declarations/src/hooks/accounts/useBalance.d.ts +15 -26
  21. package/dist/declarations/src/hooks/accounts/useConnect.d.ts +38 -13
  22. package/dist/declarations/src/hooks/accounts/useDisconnect.d.ts +26 -0
  23. package/dist/declarations/src/hooks/accounts/useNetwork.d.ts +91 -29
  24. package/dist/declarations/src/hooks/accounts/useSignMessage.d.ts +66 -15
  25. package/dist/declarations/src/hooks/accounts/useSignTypedData.d.ts +68 -30
  26. package/dist/declarations/src/hooks/accounts/useSigner.d.ts +117 -11
  27. package/dist/declarations/src/hooks/contracts/index.d.ts +1 -1
  28. package/dist/declarations/src/hooks/contracts/useContract.d.ts +3 -11
  29. package/dist/declarations/src/hooks/contracts/useContractEvent.d.ts +3 -4
  30. package/dist/declarations/src/hooks/contracts/useContractRead.d.ts +17 -22
  31. package/dist/declarations/src/hooks/contracts/useContractWrite.d.ts +69 -19
  32. package/dist/declarations/src/hooks/contracts/useToken.d.ts +14 -42
  33. package/dist/declarations/src/hooks/ens/index.d.ts +2 -2
  34. package/dist/declarations/src/hooks/ens/useEnsAddress.d.ts +17 -0
  35. package/dist/declarations/src/hooks/ens/useEnsAvatar.d.ts +15 -12
  36. package/dist/declarations/src/hooks/ens/useEnsName.d.ts +17 -0
  37. package/dist/declarations/src/hooks/ens/useEnsResolver.d.ts +15 -19
  38. package/dist/declarations/src/hooks/index.d.ts +4 -4
  39. package/dist/declarations/src/hooks/network-status/useBlockNumber.d.ts +10 -15
  40. package/dist/declarations/src/hooks/network-status/useFeeData.d.ts +12 -27
  41. package/dist/declarations/src/hooks/providers/useProvider.d.ts +1 -1
  42. package/dist/declarations/src/hooks/providers/useWebSocketProvider.d.ts +1 -1
  43. package/dist/declarations/src/hooks/transactions/index.d.ts +1 -1
  44. package/dist/declarations/src/hooks/transactions/useSendTransaction.d.ts +69 -0
  45. package/dist/declarations/src/hooks/transactions/useWaitForTransaction.d.ts +15 -31
  46. package/dist/declarations/src/hooks/utils/index.d.ts +1 -3
  47. package/dist/declarations/src/hooks/utils/useChainId.d.ts +1 -0
  48. package/dist/declarations/src/index.d.ts +5 -5
  49. package/dist/declarations/src/types/index.d.ts +40 -0
  50. package/dist/declarations/src/utils/deserialize.d.ts +2 -0
  51. package/dist/declarations/src/utils/index.d.ts +2 -0
  52. package/dist/declarations/src/utils/serialize.d.ts +7 -0
  53. package/dist/wagmi.cjs.dev.js +1217 -1478
  54. package/dist/wagmi.cjs.prod.js +1217 -1478
  55. package/dist/wagmi.esm.js +1194 -1442
  56. package/package.json +15 -17
  57. package/connectors/walletLink/package.json +0 -4
  58. package/dist/declarations/src/connectors/walletLink.d.ts +0 -1
  59. package/dist/declarations/src/hooks/ens/useEnsLookup.d.ts +0 -20
  60. package/dist/declarations/src/hooks/ens/useEnsResolveName.d.ts +0 -20
  61. package/dist/declarations/src/hooks/transactions/useTransaction.d.ts +0 -18
  62. package/dist/declarations/src/hooks/utils/useCacheBuster.d.ts +0 -1
  63. package/dist/declarations/src/hooks/utils/useCancel.d.ts +0 -3
  64. package/dist/declarations/src/hooks/utils/useLocalStorage.d.ts +0 -1
package/README.md CHANGED
@@ -1,81 +1,100 @@
1
- # wagmi [![Version](https://img.shields.io/npm/v/wagmi)](https://www.npmjs.com/package/wagmi) [![Downloads](https://img.shields.io/npm/dm/wagmi)](https://www.npmjs.com/package/wagmi) [![Sponsors](https://img.shields.io/github/sponsors/tmm)](https://github.com/sponsors/tmm)
1
+ # wagmi
2
2
 
3
- React Hooks library for Ethereum, built on [ethers.js](https://github.com/ethers-io/ethers.js).
3
+ React Hooks for Ethereum
4
+
5
+ [![Version](https://img.shields.io/npm/v/wagmi?label=&colorB=3fba11)](https://www.npmjs.com/package/wagmi) [![License](https://img.shields.io/npm/l/wagmi?label=&colorB=3fba11)](/LICENSE) [![Downloads](https://img.shields.io/npm/dm/wagmi?colorA=161b22&colorB=3fba11&label=Downloads)](https://www.npmjs.com/package/wagmi) [![Sponsors](https://img.shields.io/github/sponsors/tmm?colorA=161b22&colorB=3fba11&label=Sponsors)](https://github.com/sponsors/tmm)
4
6
 
5
7
  ## Features
6
8
 
7
9
  - 🚀 20+ hooks for working with wallets, ENS, contracts, transactions, signing, etc.
8
10
  - 💼 Built-in wallet connectors for MetaMask, WalletConnect, and Coinbase Wallet
9
- - 🌀 Auto-refresh data on wallet and network changes
11
+ - 👟 Caching, request deduplication, and persistence
12
+ - 🌀 Auto-refresh data on wallet, block, and network changes
10
13
  - 🦄 TypeScript ready
11
- - 💨 Zero-dependencies (besides ethers.js peer dependency)
12
- - 🌳 Test suite and documentation
13
- - 📖 MIT License
14
+ - 🌳 Test suite running against forked Ethereum network
15
+
16
+ ...and a lot more.
14
17
 
15
18
  ## Documentation
16
19
 
17
- Visit https://wagmi.sh to view the full documentation.
20
+ For full documentation and examples, visit [wagmi.sh](https://wagmi.sh).
18
21
 
19
- ## Usage
22
+ ## Installation
20
23
 
21
- 1. Install the dependencies.
24
+ Install wagmi and its ethers peer dependency.
22
25
 
23
26
  ```bash
24
- npm add wagmi ethers
27
+ npm install wagmi ethers
25
28
  ```
26
29
 
27
- 2. Wrap your app with the `Provider` component.
30
+ ## Quick Start
31
+
32
+ Connect a wallet in under 60 seconds. LFG.
28
33
 
29
34
  ```tsx
30
- import { Provider } from 'wagmi'
35
+ import { Provider, createClient } from 'wagmi'
31
36
 
32
- const App = () => (
33
- <Provider>
34
- <YourRoutes />
35
- </Provider>
36
- )
37
- ```
37
+ const client = createClient()
38
38
 
39
- 3. Use hooks.
39
+ function App() {
40
+ return (
41
+ <Provider client={client}>
42
+ <Profile />
43
+ </Provider>
44
+ )
45
+ }
40
46
 
41
- ```tsx
42
- import { useAccount } from 'wagmi'
47
+ import { useAccount, useConnect, useDisconnect } from 'wagmi'
48
+ import { InjectedConnector } from 'wagmi/connectors/injected'
43
49
 
44
- const Page = () => {
45
- const [{ data, error, loading }, disconnect] = useAccount({
46
- fetchEns: true,
50
+ function Profile() {
51
+ const { data } = useAccount()
52
+ const { connectors, connect } = useConnect({
53
+ connector: new InjectedConnector(),
47
54
  })
48
-
49
- return ...
55
+ const { disconnect } = useDisconnect()
56
+
57
+ if (data?.address)
58
+ return (
59
+ <div>
60
+ Connected to {data.address}
61
+ <button onClick={disconnect}>Disconnect</button>
62
+ </div>
63
+ )
64
+ return <button onClick={connect}>Connect Wallet</button>
50
65
  }
51
66
  ```
52
67
 
53
- Every component inside the `Provider` is set up with the default `InjectedConnector` for connecting wallets and ethers.js [Default Provider](https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider) for fetching data.
68
+ In this example, we create a wagmi `Client` (using the default configuration) and pass it to the React Context `Provider`. Next, we use the `useConnect` hook to connect an injected wallet (i.e. MetaMask) to the app. Finally, we show the connected account's address with `useAccount` and allow them to disconnect with `useDisconnect`.
54
69
 
55
- Want to learn more? Check out the [guides](https://wagmi-xyz.vercel.app/guides/connect-wallet) or browse the [API docs](https://wagmi-xyz.vercel.app/docs/provider).
70
+ We've only scratched the surface for what you can do with wagmi!
56
71
 
57
72
  ## Community
58
73
 
74
+ Check out the following places for more wagmi-related content:
75
+
59
76
  - Join the [discussions on GitHub](https://github.com/tmm/wagmi/discussions)
60
77
  - Follow [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
61
78
  - Sign the [guestbook](https://github.com/tmm/wagmi/discussions/2)
62
- - Share [your project/organization](https://github.com/tmm/wagmi/discussions/201) that uses wagmi
79
+ - Share [your project/organization](https://github.com/tmm/wagmi/discussions/201) using wagmi
63
80
 
64
81
  ## Support
65
82
 
66
- - awkweb.eth
83
+ Help support future development and make wagmi a sustainable open-source project:
84
+
85
+ - [awkweb.eth](https://etherscan.io/enslookup-search?search=awkweb.eth)
67
86
  - [GitHub Sponsors](https://github.com/sponsors/tmm)
68
87
  - [Gitcoin Grant](https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum)
69
88
 
70
- ## Thanks
89
+ ## Contributing
71
90
 
72
- - [ricmoo.eth](https://twitter.com/ricmoo) for creating and continued work on [ethers.js](https://github.com/ethers-io/ethers.js)
73
- - [Mirror](https://mirror.xyz) for creating space to do good work
91
+ If you're interested in contributing to wagmi, please read the [contributing docs](/.github/CONTRIBUTING.md) **before submitting a pull request**.
74
92
 
75
93
  ## License
76
94
 
77
- MIT.
95
+ The MIT License.
78
96
 
97
+ <br />
79
98
  <br />
80
99
 
81
- wagmi
100
+ wagmi frens
@@ -0,0 +1 @@
1
+ export * from "../../../dist/declarations/src/connectors/coinbaseWallet";
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var coinbaseWallet = require('@wagmi/core/connectors/coinbaseWallet');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'CoinbaseWalletConnector', {
10
+ enumerable: true,
11
+ get: function () { return coinbaseWallet.CoinbaseWalletConnector; }
12
+ });
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./wagmi-connectors-coinbaseWallet.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./wagmi-connectors-coinbaseWallet.cjs.dev.js");
7
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var coinbaseWallet = require('@wagmi/core/connectors/coinbaseWallet');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'CoinbaseWalletConnector', {
10
+ enumerable: true,
11
+ get: function () { return coinbaseWallet.CoinbaseWalletConnector; }
12
+ });
@@ -0,0 +1 @@
1
+ export { CoinbaseWalletConnector } from '@wagmi/core/connectors/coinbaseWallet';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/wagmi-connectors-coinbaseWallet.cjs.js",
3
+ "module": "dist/wagmi-connectors-coinbaseWallet.esm.js"
4
+ }
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var wagmiCore = require('wagmi-core');
5
+ var core = require('@wagmi/core');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'InjectedConnector', {
10
10
  enumerable: true,
11
- get: function () { return wagmiCore.InjectedConnector; }
11
+ get: function () { return core.InjectedConnector; }
12
12
  });
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var wagmiCore = require('wagmi-core');
5
+ var core = require('@wagmi/core');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'InjectedConnector', {
10
10
  enumerable: true,
11
- get: function () { return wagmiCore.InjectedConnector; }
11
+ get: function () { return core.InjectedConnector; }
12
12
  });
@@ -1 +1 @@
1
- export { InjectedConnector } from 'wagmi-core';
1
+ export { InjectedConnector } from '@wagmi/core';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var walletConnect = require('wagmi-core/connectors/walletConnect');
5
+ var walletConnect = require('@wagmi/core/connectors/walletConnect');
6
6
 
7
7
 
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var walletConnect = require('wagmi-core/connectors/walletConnect');
5
+ var walletConnect = require('@wagmi/core/connectors/walletConnect');
6
6
 
7
7
 
8
8
 
@@ -1 +1 @@
1
- export { WalletConnectConnector } from 'wagmi-core/connectors/walletConnect';
1
+ export { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';
@@ -0,0 +1 @@
1
+ export { CoinbaseWalletConnector } from '@wagmi/core/connectors/coinbaseWallet';
@@ -1 +1 @@
1
- export { InjectedConnector } from 'wagmi-core';
1
+ export { InjectedConnector } from '@wagmi/core';
@@ -1 +1 @@
1
- export { WalletConnectConnector } from 'wagmi-core/connectors/walletConnect';
1
+ export { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';
@@ -1,63 +1,16 @@
1
1
  import * as React from 'react';
2
- import { BaseProvider, Web3Provider, WebSocketProvider } from '@ethersproject/providers';
3
- import { Connector, ConnectorData } from 'wagmi-core';
4
- declare type State = {
5
- cacheBuster: number;
6
- connecting?: boolean;
7
- connector?: Connector;
8
- data?: ConnectorData<Web3Provider>;
9
- error?: Error;
2
+ import { WagmiClient, ClientConfig as WagmiClientConfig } from '@wagmi/core';
3
+ import { QueryClient } from 'react-query';
4
+ export declare const Context: React.Context<WagmiClient | undefined>;
5
+ export declare type ClientConfig = WagmiClientConfig & {
6
+ queryClient?: QueryClient;
10
7
  };
11
- declare type ContextValue = {
12
- state: {
13
- /** Flag for triggering refetch */
14
- cacheBuster: State['cacheBuster'];
15
- /** Flag for when connection is in progress */
16
- connecting?: State['connecting'];
17
- /** Active connector */
18
- connector?: State['connector'];
19
- /** Connectors used for linking accounts */
20
- connectors: Connector[];
21
- /** Active data */
22
- data?: State['data'];
23
- /** Interface for connecting to network */
24
- provider: BaseProvider;
25
- /** Interface for connecting to network */
26
- webSocketProvider?: WebSocketProvider;
27
- };
28
- setState: React.Dispatch<React.SetStateAction<State>>;
29
- setLastUsedConnector: (newValue: string | null) => void;
8
+ export declare function createClient({ queryClient, ...config }?: ClientConfig): WagmiClient & {
9
+ queryClient: QueryClient;
30
10
  };
31
- export declare const Context: React.Context<ContextValue | null>;
32
- export declare type Props = {
33
- /** Enables reconnecting to last used connector on mount */
34
- autoConnect?: boolean;
35
- /**
36
- * Key for saving connector preference to browser
37
- * @default 'wagmi.wallet'
38
- */
39
- connectorStorageKey?: string;
40
- /**
41
- * Connectors used for linking accounts
42
- * @default [new InjectedConnector()]
43
- */
44
- connectors?: Connector[] | ((config: {
45
- chainId?: number;
46
- }) => Connector[]);
47
- /**
48
- * Interface for connecting to network
49
- * @default getDefaultProvider()
50
- */
51
- provider?: BaseProvider | ((config: {
52
- chainId?: number;
53
- connector?: Connector;
54
- }) => BaseProvider);
55
- /** WebSocket interface for connecting to network */
56
- webSocketProvider?: WebSocketProvider | ((config: {
57
- chainId?: number;
58
- connector?: Connector;
59
- }) => WebSocketProvider | undefined);
11
+ export declare type ProviderProps = {
12
+ /** React-decorated WagmiClient instance */
13
+ client?: ReturnType<typeof createClient>;
60
14
  };
61
- export declare const Provider: ({ autoConnect, children, connectors: connectors_, connectorStorageKey, provider: provider_, webSocketProvider: webSocketProvider_, }: React.PropsWithChildren<Props>) => React.FunctionComponentElement<React.ProviderProps<ContextValue | null>>;
62
- export declare const useContext: () => ContextValue;
63
- export {};
15
+ export declare function Provider({ children, client, }: React.PropsWithChildren<ProviderProps>): JSX.Element;
16
+ export declare function useClient(): WagmiClient;
@@ -1,6 +1,7 @@
1
1
  export { useAccount } from './useAccount';
2
2
  export { useBalance } from './useBalance';
3
3
  export { useConnect } from './useConnect';
4
+ export { useDisconnect } from './useDisconnect';
4
5
  export { useNetwork } from './useNetwork';
5
6
  export { useSigner } from './useSigner';
6
7
  export { useSignMessage } from './useSignMessage';
@@ -1,16 +1,35 @@
1
- export declare type Config = {
1
+ import { GetAccountResult } from '@wagmi/core';
2
+ import { QueryConfig } from '../../types';
3
+ export declare type UseAccountArgs = {
2
4
  /** Fetches ENS for connected account */
3
- fetchEns?: boolean;
5
+ ens?: boolean | {
6
+ avatar?: boolean;
7
+ name?: boolean;
8
+ };
4
9
  };
5
- export declare const useAccount: ({ fetchEns }?: Config) => readonly [{
10
+ export declare type UseAccountConfig = Pick<QueryConfig<GetAccountResult, Error>, 'suspense' | 'onError' | 'onSettled' | 'onSuccess'>;
11
+ export declare const queryKey: () => readonly [{
12
+ readonly entity: "account";
13
+ }];
14
+ export declare function useAccount({ ens, suspense, onError, onSettled, onSuccess, }?: UseAccountArgs & UseAccountConfig): {
6
15
  readonly data: {
7
- address: string;
8
- connector: import("wagmi-core").Connector<any, any> | undefined;
9
16
  ens: {
10
- avatar: string | null | undefined;
11
- name: string;
12
- } | undefined;
17
+ avatar: import("@wagmi/core").FetchEnsAvatarResult | undefined;
18
+ name: import("@wagmi/core").FetchEnsNameResult | undefined;
19
+ };
20
+ address: string;
21
+ connector?: import("@wagmi/core").Connector<any, any> | undefined;
22
+ } | {
23
+ ens?: undefined;
24
+ address: string;
25
+ connector?: import("@wagmi/core").Connector<any, any> | undefined;
13
26
  } | undefined;
14
- readonly error: Error | undefined;
15
- readonly loading: boolean;
16
- }, () => void];
27
+ readonly error: Error | null;
28
+ readonly isError: boolean;
29
+ readonly isFetching: boolean;
30
+ readonly isFetched: boolean;
31
+ readonly isIdle: boolean;
32
+ readonly isLoading: boolean;
33
+ readonly isSuccess: boolean;
34
+ readonly status: "error" | "idle" | "loading" | "success";
35
+ };
@@ -1,28 +1,17 @@
1
- import { BigNumber } from 'ethers';
2
- import { BalanceActionArgs } from 'wagmi-core';
3
- export declare type Config = {
4
- /** Disables fetching */
5
- skip?: boolean;
1
+ import { FetchBalanceArgs, FetchBalanceResult } from '@wagmi/core';
2
+ import { QueryConfig } from '../../types';
3
+ export declare type UseBalanceArgs = Partial<FetchBalanceArgs> & {
6
4
  /** Subscribe to changes */
7
5
  watch?: boolean;
8
- } & Partial<BalanceActionArgs['config']>;
9
- export declare const useBalance: ({ addressOrName, formatUnits, skip, token, watch, }?: Config) => readonly [{
10
- readonly data: {
11
- decimals: number;
12
- formatted: string;
13
- symbol: string;
14
- value: BigNumber;
15
- } | undefined;
16
- readonly error: Error | undefined;
17
- readonly loading: boolean | undefined;
18
- }, (config?: {
19
- addressOrName: string;
20
- formatUnits?: Config['formatUnits'];
21
- token?: Config['token'];
22
- } | undefined) => Promise<{
23
- data: import("wagmi-core").Balance;
24
- error: undefined;
25
- } | {
26
- data: undefined;
27
- error: Error;
28
- }>];
6
+ };
7
+ export declare type UseBalanceConfig = QueryConfig<FetchBalanceResult, Error>;
8
+ export declare const queryKey: ({ addressOrName, chainId, formatUnits, token, }: Partial<FetchBalanceArgs> & {
9
+ chainId?: number | undefined;
10
+ }) => readonly [{
11
+ readonly entity: "balance";
12
+ readonly addressOrName: string | undefined;
13
+ readonly chainId: number | undefined;
14
+ readonly formatUnits: number | "wei" | "kwei" | "mwei" | "gwei" | "szabo" | "finney" | "ether" | undefined;
15
+ readonly token: string | undefined;
16
+ }];
17
+ export declare function useBalance({ addressOrName, cacheTime, enabled, formatUnits, staleTime, suspense, token, watch, onError, onSettled, onSuccess, }?: UseBalanceArgs & UseBalanceConfig): import("react-query").UseQueryResult<FetchBalanceResult, Error>;
@@ -1,13 +1,38 @@
1
- import { Connector, ConnectorData } from 'wagmi-core';
2
- export declare const useConnect: () => readonly [{
3
- readonly data: {
4
- readonly connected: boolean;
5
- readonly connector: Connector<any, any> | undefined;
6
- readonly connectors: Connector<any, any>[];
7
- };
8
- readonly error: Error | undefined;
9
- readonly loading: boolean | undefined;
10
- }, (connector: Connector) => Promise<{
11
- data?: ConnectorData;
12
- error?: Error;
13
- }>];
1
+ import { ConnectArgs, ConnectResult } from '@wagmi/core';
2
+ import { UseMutationOptions } from 'react-query';
3
+ export declare type UseConnectArgs = Partial<ConnectArgs>;
4
+ declare type MutationOptions = UseMutationOptions<ConnectResult, Error, ConnectArgs>;
5
+ export declare type UseConnectConfig = {
6
+ /**
7
+ * Function to invoke before connect and is passed same variables connect function would receive.
8
+ * Value returned from this function will be passed to both onError and onSettled functions in event of a mutation failure.
9
+ */
10
+ onBeforeConnect?: MutationOptions['onMutate'];
11
+ /** Function to invoke when connect is successful. */
12
+ onConnect?: MutationOptions['onSuccess'];
13
+ /** Function to invoke when an error is thrown while connecting. */
14
+ onError?: MutationOptions['onError'];
15
+ /** Function to invoke when connect is settled (either successfully connected, or an error has thrown). */
16
+ onSettled?: MutationOptions['onSettled'];
17
+ };
18
+ export declare const mutationKey: (args: UseConnectArgs) => {
19
+ connector?: import("@wagmi/core").Connector<any, any> | undefined;
20
+ entity: string;
21
+ }[];
22
+ export declare function useConnect({ connector, onBeforeConnect, onConnect, onError, onSettled, }?: UseConnectArgs & UseConnectConfig): {
23
+ readonly activeConnector: import("@wagmi/core").Connector<any, any> | undefined;
24
+ readonly connect: (connector_?: import("@wagmi/core").Connector<any, any> | undefined) => void;
25
+ readonly connectAsync: (connector_?: import("@wagmi/core").Connector<any, any> | undefined) => Promise<ConnectResult>;
26
+ readonly connectors: import("@wagmi/core").Connector<any, any>[];
27
+ readonly data: ConnectResult | undefined;
28
+ readonly error: Error | null;
29
+ readonly isConnected: boolean;
30
+ readonly isConnecting: boolean;
31
+ readonly isDisconnected: boolean;
32
+ readonly isError: boolean;
33
+ readonly isIdle: boolean;
34
+ readonly isReconnecting: boolean;
35
+ readonly pendingConnector: import("@wagmi/core").Connector<any, any> | undefined;
36
+ readonly status: "error" | "connecting" | "connected" | "reconnecting" | "disconnected" | "idle";
37
+ };
38
+ export {};
@@ -0,0 +1,26 @@
1
+ export declare type UseDisconnectConfig = {
2
+ /** Function to invoke when an error is thrown while connecting. */
3
+ onError?: (error: Error, context: unknown) => void | Promise<unknown>;
4
+ /**
5
+ * Function fires before mutation function and is passed same variables mutation function would receive.
6
+ * Value returned from this function will be passed to both onError and onSettled functions in event of a mutation failure.
7
+ */
8
+ onMutate?: () => unknown;
9
+ /** Function to invoke when connect is settled (either successfully connected, or an error has thrown). */
10
+ onSettled?: (error: Error | null, context: unknown) => void | Promise<unknown>;
11
+ /** Function fires when mutation is successful and will be passed the mutation's result */
12
+ onSuccess?: (context: unknown) => void | Promise<unknown>;
13
+ };
14
+ export declare const mutationKey: {
15
+ entity: string;
16
+ }[];
17
+ export declare function useDisconnect({ onError, onMutate, onSettled, onSuccess, }?: UseDisconnectConfig): {
18
+ readonly disconnect: import("react-query").UseMutateFunction<void, Error, void, unknown>;
19
+ readonly disconnectAsync: import("react-query").UseMutateAsyncFunction<void, Error, void, unknown>;
20
+ readonly error: Error | null;
21
+ readonly isError: boolean;
22
+ readonly isIdle: boolean;
23
+ readonly isLoading: boolean;
24
+ readonly isSuccess: boolean;
25
+ readonly status: "error" | "idle" | "loading" | "success";
26
+ };
@@ -1,30 +1,92 @@
1
- import { Chain, SwitchChainError } from 'wagmi-core';
2
- export declare const useNetwork: () => readonly [{
3
- readonly data: {
4
- readonly chain: {
5
- id: number;
6
- unsupported: boolean | undefined;
7
- name?: string | undefined;
8
- nativeCurrency?: {
9
- name: string;
10
- symbol: string;
11
- decimals: 18;
12
- } | undefined;
13
- rpcUrls?: string[] | undefined;
14
- blockExplorers?: {
15
- name: string;
16
- url: string;
17
- }[] | undefined;
18
- testnet?: boolean | undefined;
19
- } | undefined;
20
- readonly chains: Chain[];
21
- };
22
- readonly error: Error | undefined;
23
- readonly loading: boolean | undefined;
24
- }, ((chainId: number) => Promise<{
25
- data: undefined;
26
- error: SwitchChainError;
1
+ import { SwitchNetworkArgs, SwitchNetworkResult } from '@wagmi/core';
2
+ import { MutationConfig } from '../../types';
3
+ export declare type UseNetworkArgs = Partial<SwitchNetworkArgs>;
4
+ export declare type UseNetworkConfig = MutationConfig<SwitchNetworkResult, Error, SwitchNetworkArgs>;
5
+ export declare const mutationKey: (args: UseNetworkArgs) => {
6
+ chainId?: number | undefined;
7
+ entity: string;
8
+ }[];
9
+ export declare const queryKey: () => readonly [{
10
+ readonly entity: "chain";
11
+ }];
12
+ export declare function useNetwork({ chainId, onError, onMutate, onSettled, onSuccess, }?: UseNetworkArgs & UseNetworkConfig): {
13
+ readonly activeChain: (import("@wagmi/core").Chain & {
14
+ id: number;
15
+ unsupported?: boolean | undefined;
16
+ }) | undefined;
17
+ readonly chains: import("@wagmi/core").Chain[];
18
+ readonly pendingChainId: number | undefined;
19
+ readonly switchNetwork: ((chainId_?: number | undefined) => void) | undefined;
20
+ readonly switchNetworkAsync: ((chainId_?: number | undefined) => Promise<import("@wagmi/core").Chain>) | undefined;
21
+ readonly data: undefined;
22
+ readonly error: null;
23
+ readonly isError: false;
24
+ readonly isIdle: true;
25
+ readonly isLoading: false;
26
+ readonly isSuccess: false;
27
+ readonly status: "idle";
28
+ readonly reset: () => void;
29
+ readonly context: unknown;
30
+ readonly failureCount: number;
31
+ readonly isPaused: boolean;
27
32
  } | {
28
- data: Chain | undefined;
29
- error: undefined;
30
- }>) | undefined];
33
+ readonly activeChain: (import("@wagmi/core").Chain & {
34
+ id: number;
35
+ unsupported?: boolean | undefined;
36
+ }) | undefined;
37
+ readonly chains: import("@wagmi/core").Chain[];
38
+ readonly pendingChainId: number | undefined;
39
+ readonly switchNetwork: ((chainId_?: number | undefined) => void) | undefined;
40
+ readonly switchNetworkAsync: ((chainId_?: number | undefined) => Promise<import("@wagmi/core").Chain>) | undefined;
41
+ readonly data: undefined;
42
+ readonly error: null;
43
+ readonly isError: false;
44
+ readonly isIdle: false;
45
+ readonly isLoading: true;
46
+ readonly isSuccess: false;
47
+ readonly status: "loading";
48
+ readonly reset: () => void;
49
+ readonly context: unknown;
50
+ readonly failureCount: number;
51
+ readonly isPaused: boolean;
52
+ } | {
53
+ readonly activeChain: (import("@wagmi/core").Chain & {
54
+ id: number;
55
+ unsupported?: boolean | undefined;
56
+ }) | undefined;
57
+ readonly chains: import("@wagmi/core").Chain[];
58
+ readonly pendingChainId: number | undefined;
59
+ readonly switchNetwork: ((chainId_?: number | undefined) => void) | undefined;
60
+ readonly switchNetworkAsync: ((chainId_?: number | undefined) => Promise<import("@wagmi/core").Chain>) | undefined;
61
+ readonly data: undefined;
62
+ readonly error: Error;
63
+ readonly isError: true;
64
+ readonly isIdle: false;
65
+ readonly isLoading: false;
66
+ readonly isSuccess: false;
67
+ readonly status: "error";
68
+ readonly reset: () => void;
69
+ readonly context: unknown;
70
+ readonly failureCount: number;
71
+ readonly isPaused: boolean;
72
+ } | {
73
+ readonly activeChain: (import("@wagmi/core").Chain & {
74
+ id: number;
75
+ unsupported?: boolean | undefined;
76
+ }) | undefined;
77
+ readonly chains: import("@wagmi/core").Chain[];
78
+ readonly pendingChainId: number | undefined;
79
+ readonly switchNetwork: ((chainId_?: number | undefined) => void) | undefined;
80
+ readonly switchNetworkAsync: ((chainId_?: number | undefined) => Promise<import("@wagmi/core").Chain>) | undefined;
81
+ readonly data: import("@wagmi/core").Chain;
82
+ readonly error: null;
83
+ readonly isError: false;
84
+ readonly isIdle: false;
85
+ readonly isLoading: false;
86
+ readonly isSuccess: true;
87
+ readonly status: "success";
88
+ readonly reset: () => void;
89
+ readonly context: unknown;
90
+ readonly failureCount: number;
91
+ readonly isPaused: boolean;
92
+ };