wagmi-extended 0.4.0 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { WriteExtendedAsyncParams } from "./useHandleTransactionMutation";
1
+ import { WriteExtendedAsyncParams } from "./useHandleTransactionMutation.js";
2
2
  /**
3
3
  * Custom hook for writing to a smart contract using Wagmi.
4
4
  *
@@ -0,0 +1,28 @@
1
+ import { Address } from "viem";
2
+ /**
3
+ * Helper function to determine human readable state of approve.
4
+ *
5
+ * @param {boolean} isApproved - Indicates if the approval is already done.
6
+ * @param {boolean} justApproved - Indicates if the user has just approved.
7
+ * @return {string} - The appropriate button text.
8
+ */
9
+ export declare function getApproveState(isApproved?: boolean, justApproved?: boolean): "Approve Confirmed" | "Approved" | "Approve";
10
+ /**
11
+ * Custom hook for approving ERC20 token transfers.
12
+ *
13
+ * This hook provides functionality for approving ERC20 token transfers, checking the current allowance, and handling the approval transaction using Wagmi.
14
+ *
15
+ * @param {Address} tokenAddress - The address of the ERC20 token contract.
16
+ * @param {Address} spenderAddress - The address of the spender to approve the transfer to.
17
+ * @param {bigint} [amount=BigInt(0)] - The amount of tokens to approve for transfer. Defaults to 0.
18
+ * @returns {Object} Object containing the following properties:
19
+ * - {boolean} isApproved - Indicates whether the spender is already approved to transfer the specified amount of tokens.
20
+ * - {boolean} isApproving - Indicates whether an approval transaction is currently pending.
21
+ * - {Function} approveAsync - Function to trigger the approval transaction.
22
+ */
23
+ export declare const useERC20Approve: (tokenAddress?: Address, spenderAddress?: Address, amount?: bigint) => {
24
+ isApproved: boolean;
25
+ isApproving: boolean;
26
+ justApproved: boolean;
27
+ approveAsync: () => Promise<void>;
28
+ };
@@ -0,0 +1,250 @@
1
+ import { Address } from "viem";
2
+ export declare const fetchAllowance: (asset: Address, spender: Address, userAddress: Address, queryClient: any, config: any) => Promise<{
3
+ bigIntValue: bigint;
4
+ decimals: number;
5
+ symbol: string;
6
+ }>;
7
+ /**
8
+ * Custom hook for fetching asset allowance.
9
+ *
10
+ * @param {Address} asset - The address of the ERC20 token contract.
11
+ * @param {Address} spender - The address of the spender to check allowance for.
12
+ */
13
+ export declare const useFetchAssetAllowance: ({ asset, spender, }: {
14
+ asset?: Address;
15
+ spender?: Address;
16
+ }) => {
17
+ data: {
18
+ bigIntValue: bigint;
19
+ decimals: number;
20
+ symbol: string;
21
+ } | undefined;
22
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
23
+ error: Error;
24
+ isError: true;
25
+ isPending: false;
26
+ isLoading: false;
27
+ isLoadingError: false;
28
+ isRefetchError: true;
29
+ isSuccess: false;
30
+ isPlaceholderData: false;
31
+ status: "error";
32
+ dataUpdatedAt: number;
33
+ errorUpdatedAt: number;
34
+ failureCount: number;
35
+ failureReason: Error | null;
36
+ errorUpdateCount: number;
37
+ isFetched: boolean;
38
+ isFetchedAfterMount: boolean;
39
+ isFetching: boolean;
40
+ isInitialLoading: boolean;
41
+ isPaused: boolean;
42
+ isRefetching: boolean;
43
+ isStale: boolean;
44
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
45
+ bigIntValue: bigint;
46
+ decimals: number;
47
+ symbol: string;
48
+ }, Error>>;
49
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
50
+ promise: Promise<{
51
+ bigIntValue: bigint;
52
+ decimals: number;
53
+ symbol: string;
54
+ }>;
55
+ } | {
56
+ data: {
57
+ bigIntValue: bigint;
58
+ decimals: number;
59
+ symbol: string;
60
+ } | undefined;
61
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
62
+ error: null;
63
+ isError: false;
64
+ isPending: false;
65
+ isLoading: false;
66
+ isLoadingError: false;
67
+ isRefetchError: false;
68
+ isSuccess: true;
69
+ isPlaceholderData: false;
70
+ status: "success";
71
+ dataUpdatedAt: number;
72
+ errorUpdatedAt: number;
73
+ failureCount: number;
74
+ failureReason: Error | null;
75
+ errorUpdateCount: number;
76
+ isFetched: boolean;
77
+ isFetchedAfterMount: boolean;
78
+ isFetching: boolean;
79
+ isInitialLoading: boolean;
80
+ isPaused: boolean;
81
+ isRefetching: boolean;
82
+ isStale: boolean;
83
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
84
+ bigIntValue: bigint;
85
+ decimals: number;
86
+ symbol: string;
87
+ }, Error>>;
88
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
89
+ promise: Promise<{
90
+ bigIntValue: bigint;
91
+ decimals: number;
92
+ symbol: string;
93
+ }>;
94
+ } | {
95
+ data: {
96
+ bigIntValue: bigint;
97
+ decimals: number;
98
+ symbol: string;
99
+ } | undefined;
100
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
101
+ error: Error;
102
+ isError: true;
103
+ isPending: false;
104
+ isLoading: false;
105
+ isLoadingError: true;
106
+ isRefetchError: false;
107
+ isSuccess: false;
108
+ isPlaceholderData: false;
109
+ status: "error";
110
+ dataUpdatedAt: number;
111
+ errorUpdatedAt: number;
112
+ failureCount: number;
113
+ failureReason: Error | null;
114
+ errorUpdateCount: number;
115
+ isFetched: boolean;
116
+ isFetchedAfterMount: boolean;
117
+ isFetching: boolean;
118
+ isInitialLoading: boolean;
119
+ isPaused: boolean;
120
+ isRefetching: boolean;
121
+ isStale: boolean;
122
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
123
+ bigIntValue: bigint;
124
+ decimals: number;
125
+ symbol: string;
126
+ }, Error>>;
127
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
128
+ promise: Promise<{
129
+ bigIntValue: bigint;
130
+ decimals: number;
131
+ symbol: string;
132
+ }>;
133
+ } | {
134
+ data: {
135
+ bigIntValue: bigint;
136
+ decimals: number;
137
+ symbol: string;
138
+ } | undefined;
139
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
140
+ error: null;
141
+ isError: false;
142
+ isPending: true;
143
+ isLoading: 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
+ isInitialLoading: boolean;
158
+ isPaused: boolean;
159
+ isRefetching: boolean;
160
+ isStale: boolean;
161
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
162
+ bigIntValue: bigint;
163
+ decimals: number;
164
+ symbol: string;
165
+ }, Error>>;
166
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
167
+ promise: Promise<{
168
+ bigIntValue: bigint;
169
+ decimals: number;
170
+ symbol: string;
171
+ }>;
172
+ } | {
173
+ data: {
174
+ bigIntValue: bigint;
175
+ decimals: number;
176
+ symbol: string;
177
+ } | undefined;
178
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
179
+ error: null;
180
+ isError: false;
181
+ isPending: true;
182
+ isLoadingError: false;
183
+ isRefetchError: false;
184
+ isSuccess: false;
185
+ isPlaceholderData: false;
186
+ status: "pending";
187
+ dataUpdatedAt: number;
188
+ errorUpdatedAt: number;
189
+ failureCount: number;
190
+ failureReason: Error | null;
191
+ errorUpdateCount: number;
192
+ isFetched: boolean;
193
+ isFetchedAfterMount: boolean;
194
+ isFetching: boolean;
195
+ isLoading: boolean;
196
+ isInitialLoading: boolean;
197
+ isPaused: boolean;
198
+ isRefetching: boolean;
199
+ isStale: boolean;
200
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
201
+ bigIntValue: bigint;
202
+ decimals: number;
203
+ symbol: string;
204
+ }, Error>>;
205
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
206
+ promise: Promise<{
207
+ bigIntValue: bigint;
208
+ decimals: number;
209
+ symbol: string;
210
+ }>;
211
+ } | {
212
+ data: {
213
+ bigIntValue: bigint;
214
+ decimals: number;
215
+ symbol: string;
216
+ } | undefined;
217
+ queryKey: readonly ["hookFetchAllowance", `0x${string}`, `0x${string}`, `0x${string}`, any, any];
218
+ isError: false;
219
+ error: null;
220
+ isPending: false;
221
+ isLoading: false;
222
+ isLoadingError: false;
223
+ isRefetchError: false;
224
+ isSuccess: true;
225
+ isPlaceholderData: true;
226
+ status: "success";
227
+ dataUpdatedAt: number;
228
+ errorUpdatedAt: number;
229
+ failureCount: number;
230
+ failureReason: Error | null;
231
+ errorUpdateCount: number;
232
+ isFetched: boolean;
233
+ isFetchedAfterMount: boolean;
234
+ isFetching: boolean;
235
+ isInitialLoading: boolean;
236
+ isPaused: boolean;
237
+ isRefetching: boolean;
238
+ isStale: boolean;
239
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
240
+ bigIntValue: bigint;
241
+ decimals: number;
242
+ symbol: string;
243
+ }, Error>>;
244
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
245
+ promise: Promise<{
246
+ bigIntValue: bigint;
247
+ decimals: number;
248
+ symbol: string;
249
+ }>;
250
+ };
@@ -0,0 +1,179 @@
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
+ /**
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
17
+ *
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.
21
+ */
22
+ export declare function fetchToken(token: Address, queryClient: any, wagmiConfig: any): Promise<Token>;
23
+ export declare const useToken: (asset?: Address) => {
24
+ data: Token | undefined;
25
+ error: Error;
26
+ isError: true;
27
+ isPending: false;
28
+ isLoading: false;
29
+ isLoadingError: false;
30
+ isRefetchError: true;
31
+ isSuccess: false;
32
+ isPlaceholderData: false;
33
+ status: "error";
34
+ dataUpdatedAt: number;
35
+ errorUpdatedAt: number;
36
+ failureCount: number;
37
+ failureReason: Error | null;
38
+ errorUpdateCount: number;
39
+ isFetched: boolean;
40
+ isFetchedAfterMount: boolean;
41
+ isFetching: boolean;
42
+ isInitialLoading: boolean;
43
+ isPaused: boolean;
44
+ isRefetching: boolean;
45
+ isStale: boolean;
46
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
47
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
48
+ promise: Promise<Token>;
49
+ } | {
50
+ data: Token | undefined;
51
+ error: null;
52
+ isError: false;
53
+ isPending: false;
54
+ isLoading: false;
55
+ isLoadingError: false;
56
+ isRefetchError: false;
57
+ isSuccess: true;
58
+ isPlaceholderData: false;
59
+ status: "success";
60
+ dataUpdatedAt: number;
61
+ errorUpdatedAt: number;
62
+ failureCount: number;
63
+ failureReason: Error | null;
64
+ errorUpdateCount: number;
65
+ isFetched: boolean;
66
+ isFetchedAfterMount: boolean;
67
+ isFetching: boolean;
68
+ isInitialLoading: boolean;
69
+ isPaused: boolean;
70
+ isRefetching: boolean;
71
+ isStale: boolean;
72
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
73
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
74
+ promise: Promise<Token>;
75
+ } | {
76
+ data: Token | undefined;
77
+ error: Error;
78
+ isError: true;
79
+ isPending: false;
80
+ isLoading: false;
81
+ isLoadingError: true;
82
+ isRefetchError: false;
83
+ isSuccess: false;
84
+ isPlaceholderData: false;
85
+ status: "error";
86
+ dataUpdatedAt: number;
87
+ errorUpdatedAt: number;
88
+ failureCount: number;
89
+ failureReason: Error | null;
90
+ errorUpdateCount: number;
91
+ isFetched: boolean;
92
+ isFetchedAfterMount: boolean;
93
+ isFetching: boolean;
94
+ isInitialLoading: boolean;
95
+ isPaused: boolean;
96
+ isRefetching: boolean;
97
+ isStale: boolean;
98
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
99
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
100
+ promise: Promise<Token>;
101
+ } | {
102
+ data: Token | undefined;
103
+ error: null;
104
+ isError: false;
105
+ isPending: true;
106
+ isLoading: true;
107
+ isLoadingError: false;
108
+ isRefetchError: false;
109
+ isSuccess: false;
110
+ isPlaceholderData: false;
111
+ status: "pending";
112
+ dataUpdatedAt: number;
113
+ errorUpdatedAt: number;
114
+ failureCount: number;
115
+ failureReason: Error | null;
116
+ errorUpdateCount: number;
117
+ isFetched: boolean;
118
+ isFetchedAfterMount: boolean;
119
+ isFetching: boolean;
120
+ isInitialLoading: boolean;
121
+ isPaused: boolean;
122
+ isRefetching: boolean;
123
+ isStale: boolean;
124
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
125
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
126
+ promise: Promise<Token>;
127
+ } | {
128
+ data: Token | undefined;
129
+ error: null;
130
+ isError: false;
131
+ isPending: true;
132
+ isLoadingError: false;
133
+ isRefetchError: false;
134
+ isSuccess: false;
135
+ isPlaceholderData: false;
136
+ status: "pending";
137
+ dataUpdatedAt: number;
138
+ errorUpdatedAt: number;
139
+ failureCount: number;
140
+ failureReason: Error | null;
141
+ errorUpdateCount: number;
142
+ isFetched: boolean;
143
+ isFetchedAfterMount: boolean;
144
+ isFetching: boolean;
145
+ isLoading: boolean;
146
+ isInitialLoading: boolean;
147
+ isPaused: boolean;
148
+ isRefetching: boolean;
149
+ isStale: boolean;
150
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
151
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
152
+ promise: Promise<Token>;
153
+ } | {
154
+ data: Token | undefined;
155
+ isError: false;
156
+ error: null;
157
+ isPending: false;
158
+ isLoading: false;
159
+ isLoadingError: false;
160
+ isRefetchError: false;
161
+ isSuccess: true;
162
+ isPlaceholderData: true;
163
+ status: "success";
164
+ dataUpdatedAt: number;
165
+ errorUpdatedAt: number;
166
+ failureCount: number;
167
+ failureReason: Error | null;
168
+ errorUpdateCount: number;
169
+ isFetched: boolean;
170
+ isFetchedAfterMount: boolean;
171
+ isFetching: boolean;
172
+ isInitialLoading: boolean;
173
+ isPaused: boolean;
174
+ isRefetching: boolean;
175
+ isStale: boolean;
176
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<Token, Error>>;
177
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
178
+ promise: Promise<Token>;
179
+ };