wagmi-extended 0.8.0 → 1.0.1

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 (31) hide show
  1. package/README.md +224 -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/{useToken.d.ts → useFetchAssetAllowanceX.d.ts} +50 -37
  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/{useFetchAssetAllowance.d.ts → useTokenX.d.ts} +62 -108
  11. package/dist/index.cjs.js +353 -141
  12. package/dist/index.cjs.js.map +1 -1
  13. package/dist/index.d.ts +8 -4
  14. package/dist/index.esm.js +341 -138
  15. package/dist/index.esm.js.map +1 -1
  16. package/dist/utils/{errorParser.d.ts → errorParserX.d.ts} +1 -1
  17. package/package.json +2 -2
  18. package/src/config/defaults.ts +60 -0
  19. package/src/fetch-functions/fetchAllowanceX.ts +22 -0
  20. package/src/{hooks/useToken.ts → fetch-functions/fetchTokenX.ts} +42 -30
  21. package/src/hooks/useContractWriteX.ts +84 -0
  22. package/src/hooks/{useERC20Approve.ts → useERC20ApproveX.ts} +42 -38
  23. package/src/hooks/useFetchAssetAllowanceX.ts +60 -0
  24. package/src/hooks/{useHandleTransactionMutation.ts → useHandleTransactionMutationX.ts} +3 -3
  25. package/src/hooks/{useSendTransactionExtended.ts → useSendTransactionX.ts} +35 -13
  26. package/src/hooks/useTokenX.ts +65 -0
  27. package/src/index.ts +27 -4
  28. package/src/utils/{errorParser.ts → errorParserX.ts} +1 -1
  29. package/dist/hooks/useERC20Approve.d.ts +0 -28
  30. package/src/hooks/useContractWriteExtended.ts +0 -44
  31. package/src/hooks/useFetchAssetAllowance.ts +0 -94
package/README.md CHANGED
@@ -1,7 +1,230 @@
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.
4
+ <br />
5
+ <br />
6
+ 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.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Requirements](#requirements)
12
+ - [API](#api)
13
+ - [Setup](#setup)
14
+ - [Usage](#usage)
15
+ - [useERC20ApproveX Hook](#useerc20approvex-hook)
16
+ - [useContractWriteX Hook](#usecontractwritex-hook)
17
+ - [useSendTransactionX Hook](#usesendtransactionx-hook)
18
+ - [useTokenX Hook](#usetokenx-hook)
19
+ - [License](#license)
20
+
21
+ ### Installation
22
+
23
+ Install via npm:
4
24
 
5
25
  ```bash
6
26
  npm install wagmi-extended
7
27
  ```
28
+
29
+ Or with Yarn:
30
+
31
+ ```bash
32
+ yarn add wagmi-extended
33
+ ```
34
+
35
+ ### Requirements
36
+
37
+ Your project must include the following peer dependencies:
38
+
39
+ - **React**: ^17.0.0 || ^18.0.0
40
+ - **Wagmi**: ^2.0.0
41
+ - **Viem**: ^2.0.0
42
+ - **@tanstack/react-query**: ^5.0.0
43
+
44
+ Note: You must wrap your application with necessary providers (e.g. QueryClientProvider from TanStack Query and WagmiProvider).
45
+
46
+ ### API
47
+
48
+ You can import all the functions and hooks directly from `wagmi-extended`. For example:
49
+
50
+ ```bash
51
+ import {
52
+ useTokenX,
53
+ useERC20ApproveX,
54
+ useSendTransactionX,
55
+ useWriteTransactionX,
56
+ setDefaults,
57
+ getDefaults,
58
+ } from "wagmi-extended";
59
+ ```
60
+
61
+ Each hook is documented with detailed JSDoc comments (including usage examples) in the source code. Refer to that documentation for additional details.
62
+
63
+ ## Setup
64
+
65
+ For easier use of fetch (non hook) functions setup the default configuration.
66
+ <br />
67
+ This is done by calling `setDefaults` in your application initialization (e.g., in index.tsx or App.tsx).
68
+
69
+ Example:
70
+
71
+ ```bash
72
+ // index.tsx (or App.tsx)
73
+ import React from "react";
74
+ import ReactDOM from "react-dom/client";
75
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
76
+ import { useConfig } from "wagmi";
77
+ import { setDefaults } from "wagmi-extended";
78
+
79
+ const queryClient = new QueryClient();
80
+ // Obtain your Wagmi configuration from your initialization or provider
81
+ const wagmiConfig = /* your wagmi config here */;
82
+
83
+ // Set defaults for the extended library functions.
84
+ setDefaults(queryClient, wagmiConfig);
85
+
86
+ ReactDOM.createRoot(document.getElementById("root")!).render(
87
+ <React.StrictMode>
88
+ <QueryClientProvider client={queryClient}>
89
+ <App />
90
+ </QueryClientProvider>
91
+ </React.StrictMode>
92
+ );
93
+ ```
94
+
95
+ ## Hooks explanations and examples
96
+
97
+ ### useERC20ApproveX Hook
98
+
99
+ The `useERC20ApproveX` hook simplifies ERC20 token approvals by checking the allowance and handling the transaction to approve transfers.
100
+
101
+ Example:
102
+
103
+ ```bash
104
+ import { useERC20ApproveX } from "wagmi-extended";
105
+
106
+ function ApproveButton(amountToApprove: number) {
107
+ const tokenAddress = "0xTokenAddress"; // Replace with your token address
108
+ const spenderAddress = "0xSpenderAddress"; // Replace with the spender address
109
+
110
+ const { isApproved, isApproving, approveAsync } = useERC20ApproveX(
111
+ tokenAddress,
112
+ spenderAddress,
113
+ parseUnits(amountToApprove.toString(), 18),
114
+ );
115
+
116
+ return (
117
+ <button onClick={approveAsync} disabled={isApproving || isApproved}>
118
+ {isApproving ? "Approving..." : isApproved ? "Approved" : "Approve Token"}
119
+ </button>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ### useContractWriteX hook
125
+
126
+ 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.
127
+
128
+ Example:
129
+
130
+ ```bash
131
+ function MyTransactionComponent() {
132
+ const { writeContractAsync, isPending, errorMessage } = useContractWriteX({
133
+ onSuccess: (txHash) => console.log("Transaction successful:", txHash),
134
+ onError: (error) => console.error("Transaction error:", error),
135
+ queriesToInvalidate: [["userBalance"], ["userActivity"]],
136
+ });
137
+
138
+ const handleWrite = async () => {
139
+ try {
140
+ const txHash = await writeContractAsync({ transaction params here.. });
141
+ console.log("Received txHash:", txHash);
142
+ } catch (err) {
143
+ console.error("Failed writing transaction:", err);`
144
+ }
145
+ };
146
+
147
+ return (
148
+ <div>
149
+ <button onClick={handleWrite} disabled={isPending}>
150
+ {isPending ? "Processing..." : "Write Transaction"}
151
+ </button>
152
+ {errorMessage && <p>Error: {errorMessage}</p>}
153
+ </div>
154
+ );
155
+ }
156
+ ```
157
+
158
+ ### useSendTransactionX Hook
159
+
160
+ 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.
161
+
162
+ Example:
163
+
164
+ ```bash
165
+ import { useSendTransactionX } from "wagmi-extended";
166
+
167
+ function TransactionButton() {
168
+ const { sendTransactionAsync, isPending, errorMessage } = useSendTransactionX({
169
+ onSuccess: (txHash) => console.log("Transaction successful:", txHash),
170
+ onError: (error) => console.error("Transaction failed:", error),
171
+ queriesToInvalidate: [["someQueryKey"]],
172
+ });
173
+
174
+ const handleTransaction = async () => {
175
+ try {
176
+ // Replace with actual transaction parameters
177
+ const txHash = await sendTransactionAsync({
178
+ address: "0xContractAddress",
179
+ abi: [], // Provide your contract ABI
180
+ functionName: "executeFunction",
181
+ args: [/* function arguments */],
182
+ });
183
+ console.log("Transaction hash:", txHash);
184
+ } catch (error) {
185
+ console.error(error);
186
+ }
187
+ };
188
+
189
+ return (
190
+ <button onClick={handleTransaction} disabled={isPending}>
191
+ {isPending ? "Processing..." : "Send Transaction"}
192
+ {errorMessage && <span>Error: {errorMessage}</span>}
193
+ </button>
194
+ );
195
+ }
196
+ ```
197
+
198
+ ### useTokenX Hook
199
+
200
+ The useTokenX hook fetches token metadata (symbol, decimals, name and symbol) for a given token address using React Query and your Wagmi configuration.
201
+
202
+ ```bash
203
+ import { useTokenX } from "wagmi-extended";
204
+ import { Address } from "viem";
205
+
206
+ function TokenDisplay({ tokenAddress }: { tokenAddress: Address }) {
207
+ const { data, isLoading, error } = useTokenX(tokenAddress);
208
+
209
+ if (isLoading) return <div>Loading token data...</div>;
210
+ if (error) return <div>Error: {error.message}</div>;
211
+
212
+ return (
213
+ <div>
214
+ <p>Symbol: {data.symbol}</p>
215
+ <p>Decimals: {data.decimals}</p>
216
+ <p>Name: {data.name}</p>
217
+ </div>
218
+ );
219
+ }
220
+ ```
221
+
222
+ ### License
223
+
224
+ This is free and unencumbered software released into the public domain.
225
+
226
+ 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.
227
+
228
+ 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.
229
+
230
+ 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.js";
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.js";
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
+ };
@@ -1,27 +1,35 @@
1
1
  import { Address } from "viem";
2
- export interface Token {
3
- symbol: string;
4
- decimals: number;
5
- name: string;
6
- }
7
- export declare const EthTokenData: Token;
8
- export declare function fetchDecimals(token: Address, queryClient: any, wagmiConfig: any): Promise<number | undefined>;
9
- export declare function fetchSymbol(token: Address, queryClient: any, wagmiConfig: any): Promise<string>;
10
- export declare function fetchName(token: Address, queryClient: any, wagmiConfig: any): Promise<string>;
11
2
  /**
12
- * Fetches the token metadata (symbol, decimals) for the given token address.
13
- * Internally calls:
14
- * - `fetchSymbol(token)` to retrieve the token symbol,
15
- * - `fetchDecimals(token)` to retrieve the token decimals
16
- * - `fetchName(token)` to retrieve the token name
3
+ * Custom hook for fetching asset allowance.
17
4
  *
18
- * @param token - The address of the token.
19
- * @returns A `Token` object containing the symbol, decimals.
20
- * @throws Will throw an error if symbol or decimals cannot be fetched.
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
+ * }
21
26
  */
22
- export declare function fetchToken(token: Address, queryClient: any, wagmiConfig: any): Promise<Token>;
23
- export declare const useToken: (asset?: Address) => {
24
- data: Token | undefined;
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];
25
33
  error: Error;
26
34
  isError: true;
27
35
  isPending: false;
@@ -43,11 +51,12 @@ export declare const useToken: (asset?: Address) => {
43
51
  isPaused: boolean;
44
52
  isRefetching: boolean;
45
53
  isStale: boolean;
46
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
54
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
47
55
  fetchStatus: import("@tanstack/react-query").FetchStatus;
48
- promise: Promise<Token>;
56
+ promise: Promise<bigint>;
49
57
  } | {
50
- data: Token | undefined;
58
+ data: bigint | undefined;
59
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
51
60
  error: null;
52
61
  isError: false;
53
62
  isPending: false;
@@ -69,11 +78,12 @@ export declare const useToken: (asset?: Address) => {
69
78
  isPaused: boolean;
70
79
  isRefetching: boolean;
71
80
  isStale: boolean;
72
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
81
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
73
82
  fetchStatus: import("@tanstack/react-query").FetchStatus;
74
- promise: Promise<Token>;
83
+ promise: Promise<bigint>;
75
84
  } | {
76
- data: Token | undefined;
85
+ data: bigint | undefined;
86
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
77
87
  error: Error;
78
88
  isError: true;
79
89
  isPending: false;
@@ -95,11 +105,12 @@ export declare const useToken: (asset?: Address) => {
95
105
  isPaused: boolean;
96
106
  isRefetching: boolean;
97
107
  isStale: boolean;
98
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
108
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
99
109
  fetchStatus: import("@tanstack/react-query").FetchStatus;
100
- promise: Promise<Token>;
110
+ promise: Promise<bigint>;
101
111
  } | {
102
- data: Token | undefined;
112
+ data: bigint | undefined;
113
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
103
114
  error: null;
104
115
  isError: false;
105
116
  isPending: true;
@@ -121,11 +132,12 @@ export declare const useToken: (asset?: Address) => {
121
132
  isPaused: boolean;
122
133
  isRefetching: boolean;
123
134
  isStale: boolean;
124
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
135
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
125
136
  fetchStatus: import("@tanstack/react-query").FetchStatus;
126
- promise: Promise<Token>;
137
+ promise: Promise<bigint>;
127
138
  } | {
128
- data: Token | undefined;
139
+ data: bigint | undefined;
140
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
129
141
  error: null;
130
142
  isError: false;
131
143
  isPending: true;
@@ -147,11 +159,12 @@ export declare const useToken: (asset?: Address) => {
147
159
  isPaused: boolean;
148
160
  isRefetching: boolean;
149
161
  isStale: boolean;
150
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
162
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
151
163
  fetchStatus: import("@tanstack/react-query").FetchStatus;
152
- promise: Promise<Token>;
164
+ promise: Promise<bigint>;
153
165
  } | {
154
- data: Token | undefined;
166
+ data: bigint | undefined;
167
+ queryKey: readonly ["HookFetchAllowance", `0x${string}` | undefined, `0x${string}` | undefined, `0x${string}` | undefined];
155
168
  isError: false;
156
169
  error: null;
157
170
  isPending: false;
@@ -173,7 +186,7 @@ export declare const useToken: (asset?: Address) => {
173
186
  isPaused: boolean;
174
187
  isRefetching: boolean;
175
188
  isStale: boolean;
176
- refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
189
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<bigint, Error>>;
177
190
  fetchStatus: import("@tanstack/react-query").FetchStatus;
178
- promise: Promise<Token>;
191
+ promise: Promise<bigint>;
179
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>;