wagmi-extended 0.5.0 → 1.0.0

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 (32) hide show
  1. package/README.md +220 -1
  2. package/dist/config/defaults.d.ts +40 -0
  3. package/dist/fetch-functions/fetchAllowanceX.d.ts +2 -0
  4. package/dist/fetch-functions/fetchTokenX.d.ts +24 -0
  5. package/dist/hooks/{useContractWriteExtended.d.ts → useContractWriteX.d.ts} +43 -3
  6. package/dist/hooks/useERC20ApproveX.d.ts +40 -0
  7. package/dist/hooks/useFetchAssetAllowanceX.d.ts +192 -0
  8. package/dist/hooks/{useHandleTransactionMutation.d.ts → useHandleTransactionMutationX.d.ts} +1 -1
  9. package/dist/hooks/{useSendTransactionExtended.d.ts → useSendTransactionX.d.ts} +31 -10
  10. package/dist/hooks/useTokenX.d.ts +204 -0
  11. package/dist/index.cjs.js +456 -27
  12. package/dist/index.cjs.js.map +1 -1
  13. package/dist/index.d.ts +8 -3
  14. package/dist/index.esm.js +446 -28
  15. package/dist/index.esm.js.map +1 -1
  16. package/dist/query-config/index.d.ts +8 -0
  17. package/dist/utils/{errorParser.d.ts → errorParserX.d.ts} +1 -1
  18. package/package.json +2 -2
  19. package/src/config/defaults.ts +60 -0
  20. package/src/fetch-functions/fetchAllowanceX.ts +22 -0
  21. package/src/fetch-functions/fetchTokenX.ts +134 -0
  22. package/src/hooks/useContractWriteX.ts +84 -0
  23. package/src/hooks/useERC20ApproveX.ts +108 -0
  24. package/src/hooks/useFetchAssetAllowanceX.ts +60 -0
  25. package/src/hooks/{useHandleTransactionMutation.ts → useHandleTransactionMutationX.ts} +4 -4
  26. package/src/hooks/{useSendTransactionExtended.ts → useSendTransactionX.ts} +35 -13
  27. package/src/hooks/useTokenX.ts +65 -0
  28. package/src/index.ts +27 -3
  29. package/src/query-config/index.ts +8 -0
  30. package/src/utils/{errorParser.ts → errorParserX.ts} +1 -1
  31. package/tsconfig.json +9 -1
  32. package/src/hooks/useContractWriteExtended.ts +0 -44
package/README.md CHANGED
@@ -1,7 +1,226 @@
1
1
  # wagmi-extended
2
2
 
3
- ## Installation
3
+ `wagmi-extended` is a library that provides extended hooks and helper functions on top of [Wagmi](https://wagmi.sh/), [Viem](https://viem.sh/), and [TanStack Query](https://tanstack.com/query/v5) for Ethereum and blockchain development with React. It simplifies common tasks such as fetching token metadata, approving ERC20 token transfers, sending transactions, writing contracts, waiting for receipt and more—with configurable behavior via global defaults.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Requirements](#requirements)
9
+ - [API](#api)
10
+ - [Setup](#setup)
11
+ - [Usage](#usage)
12
+ - [useERC20ApproveX Hook](#useerc20approvex-hook)
13
+ - [useContractWriteX Hook](#usecontractwritex-hook)
14
+ - [useSendTransactionX Hook](#usesendtransactionx-hook)
15
+ - [useTokenX Hook](#usetokenx-hook)
16
+ - [License](#license)
17
+
18
+ ### Installation
19
+
20
+ Install via npm:
4
21
 
5
22
  ```bash
6
23
  npm install wagmi-extended
7
24
  ```
25
+
26
+ Or with Yarn:
27
+
28
+ ```bash
29
+ yarn add wagmi-extended
30
+ ```
31
+
32
+ ### Requirements
33
+
34
+ Your project must include the following peer dependencies:
35
+
36
+ - **React**: ^17.0.0 || ^18.0.0
37
+ - **Wagmi**: ^2.0.0
38
+ - **Viem**: ^2.0.0
39
+ - **@tanstack/react-query**: ^5.0.0
40
+
41
+ Note: You must wrap your application with necessary providers (e.g. QueryClientProvider from TanStack Query).
42
+
43
+ ### API
44
+
45
+ You can import all the functions and hooks directly from `wagmi-extended`. For example:
46
+
47
+ ```bash
48
+ import {
49
+ useTokenX,
50
+ useERC20ApproveX,
51
+ useSendTransactionX,
52
+ setDefaults,
53
+ getDefaults,
54
+ } from "wagmi-extended";
55
+ ```
56
+
57
+ Each hook is documented with detailed JSDoc comments (including usage examples) in the source code. Refer to that documentation for additional details.
58
+
59
+ ## Setup
60
+
61
+ For easier use of fetch (non hook) functions setup the default configuration.
62
+ <br />
63
+ This is done by calling `setDefaults` in your application initialization (e.g., in index.tsx or App.tsx).
64
+
65
+ Example:
66
+
67
+ ```bash
68
+ // index.tsx (or App.tsx)
69
+ import React from "react";
70
+ import ReactDOM from "react-dom/client";
71
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
72
+ import { useConfig } from "wagmi";
73
+ import { setDefaults } from "wagmi-extended";
74
+
75
+ const queryClient = new QueryClient();
76
+ // Obtain your Wagmi configuration from your initialization or provider
77
+ const wagmiConfig = /* your wagmi config here */;
78
+
79
+ // Set defaults for the extended library functions.
80
+ setDefaults(queryClient, wagmiConfig);
81
+
82
+ ReactDOM.createRoot(document.getElementById("root")!).render(
83
+ <React.StrictMode>
84
+ <QueryClientProvider client={queryClient}>
85
+ <App />
86
+ </QueryClientProvider>
87
+ </React.StrictMode>
88
+ );
89
+ ```
90
+
91
+ ## Hooks explanations and examples
92
+
93
+ ### useERC20ApproveX Hook
94
+
95
+ The `useERC20ApproveX` hook simplifies ERC20 token approvals by checking the allowance and handling the transaction to approve transfers.
96
+
97
+ Example:
98
+
99
+ ```bash
100
+ import { useERC20ApproveX } from "wagmi-extended";
101
+
102
+ function ApproveButton(amountToApprove: number) {
103
+ const tokenAddress = "0xTokenAddress"; // Replace with your token address
104
+ const spenderAddress = "0xSpenderAddress"; // Replace with the spender address
105
+
106
+ const { isApproved, isApproving, approveAsync } = useERC20ApproveX(
107
+ tokenAddress,
108
+ spenderAddress,
109
+ parseUnits(amountToApprove.toString(), 18),
110
+ );
111
+
112
+ return (
113
+ <button onClick={approveAsync} disabled={isApproving || isApproved}>
114
+ {isApproving ? "Approving..." : isApproved ? "Approved" : "Approve Token"}
115
+ </button>
116
+ );
117
+ }
118
+ ```
119
+
120
+ ### useContractWriteX hook
121
+
122
+ The `useContractWriteX` hook wraps the contract-writing functionality from Wagmi with additional features like `receipt` waiting, `logging` control, and `query invalidation` after receipt is successfully fetched.
123
+
124
+ Example:
125
+
126
+ ```bash
127
+ function MyTransactionComponent() {
128
+ const { writeContractAsync, isPending, errorMessage } = useContractWriteX({
129
+ onSuccess: (txHash) => console.log("Transaction successful:", txHash),
130
+ onError: (error) => console.error("Transaction error:", error),
131
+ queriesToInvalidate: [["userBalance"], ["userActivity"]],
132
+ });
133
+
134
+ const handleWrite = async () => {
135
+ try {
136
+ const txHash = await writeContractAsync({ transaction params here.. });
137
+ console.log("Received txHash:", txHash);
138
+ } catch (err) {
139
+ console.error("Failed writing transaction:", err);`
140
+ }
141
+ };
142
+
143
+ return (
144
+ <div>
145
+ <button onClick={handleWrite} disabled={isPending}>
146
+ {isPending ? "Processing..." : "Write Transaction"}
147
+ </button>
148
+ {errorMessage && <p>Error: {errorMessage}</p>}
149
+ </div>
150
+ );
151
+ }
152
+ ```
153
+
154
+ ### useSendTransactionX Hook
155
+
156
+ The `useSendTransactionX` hook wraps the transaction-sending functionality from Wagmi with additional features like `receipt` waiting, `logging` control, and `query invalidation` after receipt is successfully fetched.
157
+
158
+ Example:
159
+
160
+ ```bash
161
+ import { useSendTransactionX } from "wagmi-extended";
162
+
163
+ function TransactionButton() {
164
+ const { sendTransactionAsync, isPending, errorMessage } = useSendTransactionX({
165
+ onSuccess: (txHash) => console.log("Transaction successful:", txHash),
166
+ onError: (error) => console.error("Transaction failed:", error),
167
+ queriesToInvalidate: [["someQueryKey"]],
168
+ });
169
+
170
+ const handleTransaction = async () => {
171
+ try {
172
+ // Replace with actual transaction parameters
173
+ const txHash = await sendTransactionAsync({
174
+ address: "0xContractAddress",
175
+ abi: [], // Provide your contract ABI
176
+ functionName: "executeFunction",
177
+ args: [/* function arguments */],
178
+ });
179
+ console.log("Transaction hash:", txHash);
180
+ } catch (error) {
181
+ console.error(error);
182
+ }
183
+ };
184
+
185
+ return (
186
+ <button onClick={handleTransaction} disabled={isPending}>
187
+ {isPending ? "Processing..." : "Send Transaction"}
188
+ {errorMessage && <span>Error: {errorMessage}</span>}
189
+ </button>
190
+ );
191
+ }
192
+ ```
193
+
194
+ ### useTokenX Hook
195
+
196
+ The useTokenX hook fetches token metadata (symbol, decimals, name and symbol) for a given token address using React Query and your Wagmi configuration.
197
+
198
+ ```bash
199
+ import { useTokenX } from "wagmi-extended";
200
+ import { Address } from "viem";
201
+
202
+ function TokenDisplay({ tokenAddress }: { tokenAddress: Address }) {
203
+ const { data, isLoading, error } = useTokenX(tokenAddress);
204
+
205
+ if (isLoading) return <div>Loading token data...</div>;
206
+ if (error) return <div>Error: {error.message}</div>;
207
+
208
+ return (
209
+ <div>
210
+ <p>Symbol: {data.symbol}</p>
211
+ <p>Decimals: {data.decimals}</p>
212
+ <p>Name: {data.name}</p>
213
+ </div>
214
+ );
215
+ }
216
+ ```
217
+
218
+ ### License
219
+
220
+ This is free and unencumbered software released into the public domain.
221
+
222
+ Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
223
+
224
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
225
+
226
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,40 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ import { Config } from "wagmi";
3
+ /**
4
+ * Sets the default configuration values.
5
+ *
6
+ * @param queryClient - The default QueryClient instance.
7
+ * @param wagmiConfig - The default Wagmi configuration.
8
+ * @example
9
+ * //In your application initialization (e.g., index.tsx or App.tsx):
10
+ * import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
11
+ * import { wagmiConfig } from "/path/to/wagmi-config";
12
+ * import { setDefaults } from "wagmi-extended";
13
+ *
14
+ * const queryClient = new QueryClient();
15
+ *
16
+ * //Set defaults for the extended library functions.
17
+ * setDefaults(queryClient, wagmiConfig);
18
+ *
19
+ * //Now helper functions like fetchTokenX can use these defaults if no explicit parameters are provided.
20
+ */
21
+ export declare function setDefaults(queryClient: QueryClient, wagmiConfig: Config): void;
22
+ /**
23
+ * Retrieves the currently set default configurations.
24
+ *
25
+ * @throws Will throw an error if defaults are not initialized.
26
+ * @returns An object containing the default queryClient and wagmiConfig.
27
+ *
28
+ * @example
29
+ * // Usage in a helper function:
30
+ * import { getDefaults } from "wagmi-extended";
31
+ *
32
+ * function exampleFunction() {
33
+ * const { queryClient, wagmiConfig } = getDefaults();
34
+ * // Use queryClient and wagmiConfig as needed...
35
+ * }
36
+ */
37
+ export declare function getDefaults(): {
38
+ queryClient: QueryClient;
39
+ wagmiConfig: Config;
40
+ };
@@ -0,0 +1,2 @@
1
+ import { Address } from "viem";
2
+ export declare const fetchAllowance: (asset: Address, spender: Address, userAddress: Address, config: any) => Promise<bigint>;
@@ -0,0 +1,24 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ import { Address } from "viem";
3
+ import { Config } from "wagmi";
4
+ export interface Token {
5
+ symbol: string;
6
+ decimals: number;
7
+ name: string;
8
+ }
9
+ export declare const EthTokenData: Token;
10
+ export declare function fetchDecimalsX(token: Address, queryClient?: QueryClient, wagmiConfig?: Config): Promise<number | undefined>;
11
+ export declare function fetchSymbolX(token: Address, queryClient?: QueryClient, wagmiConfig?: Config): Promise<string>;
12
+ export declare function fetchNameX(token: Address, queryClient: any, wagmiConfig: any): Promise<string>;
13
+ /**
14
+ * Fetches the token metadata (symbol, decimals) for the given token address.
15
+ * Internally calls:
16
+ * - `fetchSymbol(token)` to retrieve the token symbol,
17
+ * - `fetchDecimals(token)` to retrieve the token decimals
18
+ * - `fetchName(token)` to retrieve the token name
19
+ *
20
+ * @param token - The address of the token.
21
+ * @returns A `Token` object containing the symbol, decimals.
22
+ * @throws Will throw an error if symbol or decimals cannot be fetched.
23
+ */
24
+ export declare function fetchTokenX(token: Address, queryClient: any, wagmiConfig: any): Promise<Token>;
@@ -1,8 +1,8 @@
1
- import { WriteExtendedAsyncParams } from "./useHandleTransactionMutation";
1
+ import { WriteExtendedAsyncParams } from "./useHandleTransactionMutationX.js";
2
2
  /**
3
3
  * Custom hook for writing to a smart contract using Wagmi.
4
4
  *
5
- * This hook provides functionality for sending a transaction using Wagmi, handling the asynchronous nature of the operation, waiting for the transaction receipt, and error handling.
5
+ * This hook provides functionality for writing a contract using Wagmi, handling the asynchronous nature of the operation, waiting for the transaction receipt, and error handling.
6
6
  *
7
7
  * @param {WriteExtendedAsyncParams} [settings] - Optional settings for the write operation.
8
8
  * @param {boolean} [settings.disableWaitingForReceipt] - Disables waiting for the transaction receipt.
@@ -15,8 +15,48 @@ import { WriteExtendedAsyncParams } from "./useHandleTransactionMutation";
15
15
  * - {boolean} isPending - Indicates whether the transaction is pending.
16
16
  * - {string|undefined} errorMessage - The error message, if an error occurred during the transaction.
17
17
  * - {Function} writeContractAsync - Function to trigger the write operation.
18
+ *
19
+ /**
20
+ * Custom hook for writing a contract using Wagmi with extended functionality.
21
+ *
22
+ * This hook wraps Wagmi’s `useContractWriteX` with additional handling for
23
+ * waiting for a transaction receipt, logging control, and invalidation of specified queries.
24
+ *
25
+ * @param {WriteExtendedAsyncParams} [settings] - Optional settings for handling the transaction.
26
+ * @returns {Object} An object containing:
27
+ * - `isPending`: {boolean} indicating if the transaction is in progress.
28
+ * - `errorMessage`: {string|undefined} a potential error message.
29
+ * - `writeContractAsync`: {Function} a function to trigger the transaction.
30
+ *
31
+ * @example
32
+ * // In your component:
33
+ * function MyTransactionComponent() {
34
+ * const { writeContractAsync, isPending, errorMessage } = useContractWriteX({
35
+ * onSuccess: (txHash) => console.log("Transaction successful:", txHash),
36
+ * onError: (error) => console.error("Transaction error:", error),
37
+ * queriesToInvalidate: [["userBalance"], ["userActivity"]],
38
+ * });
39
+ *
40
+ * const handleWrite = async () => {
41
+ * try {
42
+ * const txHash = await writeContractAsync({ transaction params here.. });
43
+ * console.log("Received txHash:", txHash);
44
+ * } catch (err) {
45
+ * console.error("Failed writing transaction:", err);`
46
+ * }
47
+ * };
48
+ *
49
+ * return (
50
+ * <div>
51
+ * <button onClick={handleWrite} disabled={isPending}>
52
+ * {isPending ? "Processing..." : "Write Transaction"}
53
+ * </button>
54
+ * {errorMessage && <p>Error: {errorMessage}</p>}
55
+ * </div>
56
+ * );
57
+ * }
18
58
  */
19
- export declare function useContractWriteExtended(settings?: WriteExtendedAsyncParams): {
59
+ export declare function useContractWriteX(settings?: WriteExtendedAsyncParams): {
20
60
  isPending: boolean;
21
61
  errorMessage: string | undefined;
22
62
  writeContractAsync: import("wagmi/query").WriteContractMutateAsync<import("wagmi").Config, void>;
@@ -0,0 +1,40 @@
1
+ import { Address } from "viem";
2
+ /**
3
+ * Custom hook for approving ERC20 token transfers.
4
+ *
5
+ * This hook provides functionality for approving ERC20 token transfers, checking the current allowance, and handling the approval transaction using Wagmi.
6
+ *
7
+ * @param {Address} tokenAddress - The address of the ERC20 token contract (the transfer from).
8
+ * @param {Address} spenderAddress - The address of the spender to approve the transfer to.
9
+ * @param {bigint} [amount=BigInt(0)] - The amount to approve for transfer. Defaults to undefined.
10
+ * @param {boolean} [approveMax=false] - Indicates whether to approve the maximum amount or a specific amount.
11
+ * @returns {Object} Object containing the following properties:
12
+ * - {boolean} isApproved - Indicates whether the spender is already approved to transfer the specified amount of tokens.
13
+ * - {boolean} isApproving - Indicates whether an approval transaction is currently pending.
14
+ * - {Function} approveAsync - Function to trigger the approval transaction.
15
+ *
16
+ * @example
17
+ * // In your component:
18
+ * function ApproveTokenButton(amountToApprove) {
19
+ * const tokenAddress = "0xTokenAddressExample";
20
+ * const spenderAddress = "0xSpenderAddressExample";
21
+ *
22
+ * const { isApproved, isApproving, justApproved, approveAsync } = useERC20ApproveX(
23
+ * tokenAddress,
24
+ * spenderAddress,
25
+ * parseUnits(amountToApprove.toString(), 18),
26
+ * );
27
+ *
28
+ * return (
29
+ * <button onClick={approveAsync} disabled={isApproving || isApproved}>
30
+ * {isApproving ? "Approving..." : isApproved ? "Approved" : "Approve Token"}
31
+ * </button>
32
+ * );
33
+ * }
34
+ */
35
+ export declare const useERC20ApproveX: (tokenAddress?: Address, spenderAddress?: Address, amount?: bigint, approveMax?: boolean) => {
36
+ isApproved: boolean;
37
+ isApproving: boolean;
38
+ justApproved: boolean;
39
+ approveAsync: () => Promise<void>;
40
+ };
@@ -0,0 +1,192 @@
1
+ import { Address } from "viem";
2
+ /**
3
+ * Custom hook for fetching asset allowance.
4
+ *
5
+ * @param {Address} asset - The address of the ERC20 token contract.
6
+ * @param {Address} spender - The address of the spender to check allowance for.
7
+ *
8
+ *
9
+ * @example
10
+ * // In your component:
11
+ * function AllowanceDisplay() {
12
+ * const { data: allowance, isLoading, error } = useFetchAssetAllowanceX({
13
+ * asset: "0xTokenAddressExample",
14
+ * spender: "0xSpenderAddressExample",
15
+ * });
16
+ *
17
+ * if (isLoading) return <div>Loading allowance...</div>;
18
+ * if (error) return <div>Error loading allowance</div>;
19
+ *
20
+ * return (
21
+ * <div>
22
+ * Current Allowance: {allowance}
23
+ * </div>
24
+ * );
25
+ * }
26
+ */
27
+ export declare const useFetchAssetAllowanceX: ({ asset, spender, }: {
28
+ asset?: Address;
29
+ spender?: Address;
30
+ }) => {
31
+ data: bigint | undefined;
32
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
33
+ error: Error;
34
+ isError: true;
35
+ isPending: false;
36
+ isLoading: false;
37
+ isLoadingError: false;
38
+ isRefetchError: true;
39
+ isSuccess: false;
40
+ isPlaceholderData: false;
41
+ status: "error";
42
+ dataUpdatedAt: number;
43
+ errorUpdatedAt: number;
44
+ failureCount: number;
45
+ failureReason: Error | null;
46
+ errorUpdateCount: number;
47
+ isFetched: boolean;
48
+ isFetchedAfterMount: boolean;
49
+ isFetching: boolean;
50
+ isInitialLoading: boolean;
51
+ isPaused: boolean;
52
+ isRefetching: boolean;
53
+ isStale: boolean;
54
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
55
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
56
+ promise: Promise<bigint>;
57
+ } | {
58
+ data: bigint | undefined;
59
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
60
+ error: null;
61
+ isError: false;
62
+ isPending: false;
63
+ isLoading: false;
64
+ isLoadingError: false;
65
+ isRefetchError: false;
66
+ isSuccess: true;
67
+ isPlaceholderData: false;
68
+ status: "success";
69
+ dataUpdatedAt: number;
70
+ errorUpdatedAt: number;
71
+ failureCount: number;
72
+ failureReason: Error | null;
73
+ errorUpdateCount: number;
74
+ isFetched: boolean;
75
+ isFetchedAfterMount: boolean;
76
+ isFetching: boolean;
77
+ isInitialLoading: boolean;
78
+ isPaused: boolean;
79
+ isRefetching: boolean;
80
+ isStale: boolean;
81
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
82
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
83
+ promise: Promise<bigint>;
84
+ } | {
85
+ data: bigint | undefined;
86
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
87
+ error: Error;
88
+ isError: true;
89
+ isPending: false;
90
+ isLoading: false;
91
+ isLoadingError: true;
92
+ isRefetchError: false;
93
+ isSuccess: false;
94
+ isPlaceholderData: false;
95
+ status: "error";
96
+ dataUpdatedAt: number;
97
+ errorUpdatedAt: number;
98
+ failureCount: number;
99
+ failureReason: Error | null;
100
+ errorUpdateCount: number;
101
+ isFetched: boolean;
102
+ isFetchedAfterMount: boolean;
103
+ isFetching: boolean;
104
+ isInitialLoading: boolean;
105
+ isPaused: boolean;
106
+ isRefetching: boolean;
107
+ isStale: boolean;
108
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
109
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
110
+ promise: Promise<bigint>;
111
+ } | {
112
+ data: bigint | undefined;
113
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
114
+ error: null;
115
+ isError: false;
116
+ isPending: true;
117
+ isLoading: true;
118
+ isLoadingError: false;
119
+ isRefetchError: false;
120
+ isSuccess: false;
121
+ isPlaceholderData: false;
122
+ status: "pending";
123
+ dataUpdatedAt: number;
124
+ errorUpdatedAt: number;
125
+ failureCount: number;
126
+ failureReason: Error | null;
127
+ errorUpdateCount: number;
128
+ isFetched: boolean;
129
+ isFetchedAfterMount: boolean;
130
+ isFetching: boolean;
131
+ isInitialLoading: boolean;
132
+ isPaused: boolean;
133
+ isRefetching: boolean;
134
+ isStale: boolean;
135
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
136
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
137
+ promise: Promise<bigint>;
138
+ } | {
139
+ data: bigint | undefined;
140
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
141
+ error: null;
142
+ isError: false;
143
+ isPending: true;
144
+ isLoadingError: false;
145
+ isRefetchError: false;
146
+ isSuccess: false;
147
+ isPlaceholderData: false;
148
+ status: "pending";
149
+ dataUpdatedAt: number;
150
+ errorUpdatedAt: number;
151
+ failureCount: number;
152
+ failureReason: Error | null;
153
+ errorUpdateCount: number;
154
+ isFetched: boolean;
155
+ isFetchedAfterMount: boolean;
156
+ isFetching: boolean;
157
+ isLoading: boolean;
158
+ isInitialLoading: boolean;
159
+ isPaused: boolean;
160
+ isRefetching: boolean;
161
+ isStale: boolean;
162
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
163
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
164
+ promise: Promise<bigint>;
165
+ } | {
166
+ data: bigint | undefined;
167
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
168
+ isError: false;
169
+ error: null;
170
+ isPending: false;
171
+ isLoading: false;
172
+ isLoadingError: false;
173
+ isRefetchError: false;
174
+ isSuccess: true;
175
+ isPlaceholderData: true;
176
+ status: "success";
177
+ dataUpdatedAt: number;
178
+ errorUpdatedAt: number;
179
+ failureCount: number;
180
+ failureReason: Error | null;
181
+ errorUpdateCount: number;
182
+ isFetched: boolean;
183
+ isFetchedAfterMount: boolean;
184
+ isFetching: boolean;
185
+ isInitialLoading: boolean;
186
+ isPaused: boolean;
187
+ isRefetching: boolean;
188
+ isStale: boolean;
189
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
190
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
191
+ promise: Promise<bigint>;
192
+ };
@@ -13,7 +13,7 @@ export type WriteExtendedAsyncParams = {
13
13
  *
14
14
  * @returns {Function} A shared `onSettled` callback for transaction mutations.
15
15
  */
16
- export declare function useHandleTransactionMutation({ settings, }: {
16
+ export declare function useHandleTransactionMutationX({ settings, }: {
17
17
  settings?: WriteExtendedAsyncParams;
18
18
  }): {
19
19
  onMutate: () => void;
@@ -1,17 +1,10 @@
1
- import { Hash } from "viem";
2
- import { QueryKey } from "@tanstack/query-core";
3
- export type SeamlessSendAsyncParams = {
4
- onSuccess?: (txHash: Hash) => void;
5
- onError?: (e: any) => void;
6
- onSettled?: () => void;
7
- queriesToInvalidate?: (QueryKey | undefined)[];
8
- };
1
+ import { WriteExtendedAsyncParams } from "./useHandleTransactionMutationX.js";
9
2
  /**
10
3
  * Custom hook for sending a transaction using Wagmi.
11
4
  *
12
5
  * This hook provides functionality for sending a transaction using Wagmi, handling the asynchronous nature of the operation, waiting for the transaction receipt, and error handling.
13
6
  *
14
- * @param {SeamlessWriteAsyncParams} [settings] - Optional settings for the write operation.
7
+ * @param {WriteExtendedAsyncParams} [settings] - Optional settings for the write operation.
15
8
  * @param {boolean} [settings.disableWaitingForReceipt] - Disables waiting for the transaction receipt.
16
9
  * @param {boolean} [settings.disableLogging] - Disables logging the result of the transaction.
17
10
  * @param {Function} [settings.onSuccess] - Callback function to be called on successful transaction.
@@ -22,8 +15,36 @@ export type SeamlessSendAsyncParams = {
22
15
  * - {boolean} isPending - Indicates whether the transaction is pending.
23
16
  * - {string|undefined} errorMessage - The error message, if an error occurred during the transaction.
24
17
  * - {Function} sendTransactionAsync - Function to trigger the send transaction mutation.
18
+
19
+ * @example
20
+ * // In your component:
21
+ * function MyTransactionComponent() {
22
+ * const { sendTransactionAsync, isPending, errorMessage } = useSendTransactionX({
23
+ * onSuccess: (txHash) => console.log("Transaction successful:", txHash),
24
+ * onError: (error) => console.error("Transaction error:", error),
25
+ * queriesToInvalidate: [["userBalance"], ["userActivity"]],
26
+ * });
27
+ *
28
+ * const handleSend = async () => {
29
+ * try {
30
+ * const txHash = await sendTransactionAsync({ transaction params here.. });
31
+ * console.log("Received txHash:", txHash);
32
+ * } catch (err) {
33
+ * console.error("Failed sending transaction:", err);`
34
+ * }
35
+ * };
36
+ *
37
+ * return (
38
+ * <div>
39
+ * <button onClick={handleSend} disabled={isPending}>
40
+ * {isPending ? "Processing..." : "Send Transaction"}
41
+ * </button>
42
+ * {errorMessage && <p>Error: {errorMessage}</p>}
43
+ * </div>
44
+ * );
45
+ * }
25
46
  */
26
- export declare function useSendTransactionExtended(settings?: SeamlessSendAsyncParams): {
47
+ export declare function useSendTransactionX(settings?: WriteExtendedAsyncParams): {
27
48
  isPending: boolean;
28
49
  errorMessage: string | undefined;
29
50
  sendTransactionAsync: import("wagmi/query").SendTransactionMutateAsync<import("wagmi").Config, void>;