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.
- package/README.md +220 -1
- package/dist/config/defaults.d.ts +40 -0
- package/dist/fetch-functions/fetchAllowanceX.d.ts +2 -0
- package/dist/fetch-functions/fetchTokenX.d.ts +24 -0
- package/dist/hooks/{useContractWriteExtended.d.ts → useContractWriteX.d.ts} +43 -3
- package/dist/hooks/useERC20ApproveX.d.ts +40 -0
- package/dist/hooks/useFetchAssetAllowanceX.d.ts +192 -0
- package/dist/hooks/{useHandleTransactionMutation.d.ts → useHandleTransactionMutationX.d.ts} +1 -1
- package/dist/hooks/{useSendTransactionExtended.d.ts → useSendTransactionX.d.ts} +31 -10
- package/dist/hooks/useTokenX.d.ts +204 -0
- package/dist/index.cjs.js +456 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.esm.js +446 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/query-config/index.d.ts +8 -0
- package/dist/utils/{errorParser.d.ts → errorParserX.d.ts} +1 -1
- package/package.json +2 -2
- package/src/config/defaults.ts +60 -0
- package/src/fetch-functions/fetchAllowanceX.ts +22 -0
- package/src/fetch-functions/fetchTokenX.ts +134 -0
- package/src/hooks/useContractWriteX.ts +84 -0
- package/src/hooks/useERC20ApproveX.ts +108 -0
- package/src/hooks/useFetchAssetAllowanceX.ts +60 -0
- package/src/hooks/{useHandleTransactionMutation.ts → useHandleTransactionMutationX.ts} +4 -4
- package/src/hooks/{useSendTransactionExtended.ts → useSendTransactionX.ts} +35 -13
- package/src/hooks/useTokenX.ts +65 -0
- package/src/index.ts +27 -3
- package/src/query-config/index.ts +8 -0
- package/src/utils/{errorParser.ts → errorParserX.ts} +1 -1
- package/tsconfig.json +9 -1
- package/src/hooks/useContractWriteExtended.ts +0 -44
package/src/index.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* ------------- */
|
|
2
|
+
/* Mutations */
|
|
3
|
+
/* ------------- */
|
|
4
|
+
export * from "./hooks/useContractWriteX.js";
|
|
5
|
+
export * from "./hooks/useSendTransactionX.js";
|
|
6
|
+
export * from "./hooks/useERC20ApproveX.js";
|
|
7
|
+
|
|
8
|
+
/* ------------- */
|
|
9
|
+
/* Queries */
|
|
10
|
+
/* ------------- */
|
|
11
|
+
export * from "./hooks/useTokenX.js";
|
|
12
|
+
export * from "./hooks/useFetchAssetAllowanceX.js";
|
|
13
|
+
|
|
14
|
+
/* ------------- */
|
|
15
|
+
/* Fetch */
|
|
16
|
+
/* ------------- */
|
|
17
|
+
export * from "./fetch-functions/fetchTokenX.js";
|
|
18
|
+
|
|
19
|
+
/* ------------- */
|
|
20
|
+
/* Utils */
|
|
21
|
+
/* ------------- */
|
|
22
|
+
export * from "./utils/errorParserX.js";
|
|
23
|
+
|
|
24
|
+
/* ------------- */
|
|
25
|
+
/* Config */
|
|
26
|
+
/* ------------- */
|
|
27
|
+
export * from "./config/defaults.js";
|
|
@@ -77,7 +77,7 @@ export const getErrorMapping = (): Record<string, string> =>
|
|
|
77
77
|
* const message = getParsedError(someError);
|
|
78
78
|
* console.log(message); // Outputs a custom error message or a default error message.
|
|
79
79
|
*/
|
|
80
|
-
export const
|
|
80
|
+
export const getParsedErrorX = (error: any | BaseError): string => {
|
|
81
81
|
const defaultMessage = "An unknown error occurred. Please contact support.";
|
|
82
82
|
let message = defaultMessage;
|
|
83
83
|
let errorKey = "";
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2019",
|
|
4
|
-
"module": "
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"baseUrl": ".", // important when using paths
|
|
6
|
+
"paths": {
|
|
7
|
+
"wagmi/query": ["node_modules/wagmi/query"],
|
|
8
|
+
"@tanstack/react-query/build/legacy/useQuery": [
|
|
9
|
+
"node_modules/@tanstack/react-query/build/legacy/useQuery"
|
|
10
|
+
],
|
|
11
|
+
"viem": ["node_modules/viem"]
|
|
12
|
+
},
|
|
5
13
|
"declaration": true,
|
|
6
14
|
"outDir": "dist",
|
|
7
15
|
"strict": true,
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useWriteContract } from "wagmi";
|
|
2
|
-
import {
|
|
3
|
-
WriteExtendedAsyncParams,
|
|
4
|
-
useHandleTransactionMutation,
|
|
5
|
-
} from "./useHandleTransactionMutation";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Custom hook for writing to a smart contract using Wagmi.
|
|
9
|
-
*
|
|
10
|
-
* 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.
|
|
11
|
-
*
|
|
12
|
-
* @param {WriteExtendedAsyncParams} [settings] - Optional settings for the write operation.
|
|
13
|
-
* @param {boolean} [settings.disableWaitingForReceipt] - Disables waiting for the transaction receipt.
|
|
14
|
-
* @param {boolean} [settings.disableLogging] - Disables logging the result of the transaction.
|
|
15
|
-
* @param {Function} [settings.onSuccess] - Callback function to be called on successful transaction.
|
|
16
|
-
* @param {Function} [settings.onError] - Callback function to be called on transaction error.
|
|
17
|
-
* @param {Function} [settings.onSettled] - Callback function to be called after the transaction settles (whether success or failure).
|
|
18
|
-
* @param {QueryKey[]} [settings.queriesToInvalidate] - Array of query keys to invalidate after the transaction receives a receipt.
|
|
19
|
-
* @returns {Object} Object containing the following properties:
|
|
20
|
-
* - {boolean} isPending - Indicates whether the transaction is pending.
|
|
21
|
-
* - {string|undefined} errorMessage - The error message, if an error occurred during the transaction.
|
|
22
|
-
* - {Function} writeContractAsync - Function to trigger the write operation.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export function useContractWriteExtended(settings?: WriteExtendedAsyncParams) {
|
|
26
|
-
const { isPending, errorMessage, onMutate, onSettled } =
|
|
27
|
-
useHandleTransactionMutation({
|
|
28
|
-
settings,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const { writeContractAsync, ...rest } = useWriteContract({
|
|
32
|
-
mutation: {
|
|
33
|
-
onMutate,
|
|
34
|
-
onSettled,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
...rest,
|
|
40
|
-
isPending,
|
|
41
|
-
errorMessage,
|
|
42
|
-
writeContractAsync,
|
|
43
|
-
};
|
|
44
|
-
}
|