@cometh/connect-react-hooks 0.0.11 → 0.0.12-dev.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +70 -1
- package/dist/index.d.cts +230 -22
- package/dist/index.d.ts +230 -22
- package/dist/index.js +69 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -2266,6 +2266,75 @@ var useSwitchChain = () => {
|
|
2266
2266
|
};
|
2267
2267
|
};
|
2268
2268
|
|
2269
|
+
// src/hooks/useGetTransactionCost.ts
|
2270
|
+
var useGetTransactionCost = (mutationProps) => {
|
2271
|
+
const { smartAccountClient, queryClient } = useSmartAccount();
|
2272
|
+
const { mutate, mutateAsync, ...result } = useMutation(
|
2273
|
+
{
|
2274
|
+
mutationFn: async (variables) => {
|
2275
|
+
if (!smartAccountClient) {
|
2276
|
+
throw new Error("No smart account found");
|
2277
|
+
}
|
2278
|
+
const { transactions } = variables;
|
2279
|
+
const userOperation = await smartAccountClient.account.prepareUserOperation(
|
2280
|
+
transactions
|
2281
|
+
);
|
2282
|
+
const estimateGas = await smartAccountClient.estimateGas({
|
2283
|
+
userOperation
|
2284
|
+
});
|
2285
|
+
const totalGas = estimateGas.preVerificationGas + estimateGas.verificationGasLimit + estimateGas.callGasLimit;
|
2286
|
+
return { totalGasCost: totalGas * estimateGas.maxFeePerGas };
|
2287
|
+
},
|
2288
|
+
...mutationProps
|
2289
|
+
},
|
2290
|
+
queryClient
|
2291
|
+
);
|
2292
|
+
return {
|
2293
|
+
data: _optionalChain([result, 'access', _98 => _98.data, 'optionalAccess', _99 => _99.totalGasCost]),
|
2294
|
+
error: result.error,
|
2295
|
+
isPending: result.isPending,
|
2296
|
+
isSuccess: result.isSuccess,
|
2297
|
+
isError: result.isError,
|
2298
|
+
getTransactionCost: mutate,
|
2299
|
+
getTransactionCostAsync: mutateAsync
|
2300
|
+
};
|
2301
|
+
};
|
2302
|
+
|
2303
|
+
// src/hooks/useEstimateGas.ts
|
2304
|
+
var useEstimateGas = (mutationProps) => {
|
2305
|
+
const { smartAccountClient, queryClient } = useSmartAccount();
|
2306
|
+
const { mutate, mutateAsync, ...result } = useMutation(
|
2307
|
+
{
|
2308
|
+
mutationFn: async (variables) => {
|
2309
|
+
if (!smartAccountClient) {
|
2310
|
+
throw new Error("No smart account found");
|
2311
|
+
}
|
2312
|
+
const { transactions } = variables;
|
2313
|
+
const userOperation = await smartAccountClient.account.prepareUserOperation(
|
2314
|
+
transactions
|
2315
|
+
);
|
2316
|
+
const estimateGas = await smartAccountClient.estimateGas({
|
2317
|
+
userOperation
|
2318
|
+
});
|
2319
|
+
return estimateGas;
|
2320
|
+
},
|
2321
|
+
...mutationProps
|
2322
|
+
},
|
2323
|
+
queryClient
|
2324
|
+
);
|
2325
|
+
return {
|
2326
|
+
data: result.data,
|
2327
|
+
error: result.error,
|
2328
|
+
isPending: result.isPending,
|
2329
|
+
isSuccess: result.isSuccess,
|
2330
|
+
isError: result.isError,
|
2331
|
+
estimateGas: mutate,
|
2332
|
+
estimateGasAsync: mutateAsync
|
2333
|
+
};
|
2334
|
+
};
|
2335
|
+
|
2336
|
+
|
2337
|
+
|
2269
2338
|
|
2270
2339
|
|
2271
2340
|
|
@@ -2298,4 +2367,4 @@ var useSwitchChain = () => {
|
|
2298
2367
|
|
2299
2368
|
|
2300
2369
|
|
2301
|
-
exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; exports.useAddSessionKey = useAddSessionKey; exports.useAddWhitelistDestination = useAddWhitelistDestination; exports.useCancelRecoveryRequest = useCancelRecoveryRequest; exports.useConnect = useConnect; exports.useCreateNewSigner = useCreateNewSigner; exports.useDisconnect = useDisconnect; exports.useGenerateQRCodeUrl = useGenerateQRCodeUrl; exports.useGetEnrichedOwners = useGetEnrichedOwners; exports.useGetGasPrice = useGetGasPrice; exports.useGetOwners = useGetOwners; exports.useGetRecoveryRequest = useGetRecoveryRequest; exports.useGetSessionFromAddress = useGetSessionFromAddress; exports.useIsAddressWhitelistDestination = useIsAddressWhitelistDestination; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRemoveWhitelistDestination = useRemoveWhitelistDestination; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useRevokeSessionKey = useRevokeSessionKey; exports.useSendTransaction = useSendTransaction; exports.useSendTransactionWithSessionKey = useSendTransactionWithSessionKey; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract; exports.useWriteContractWithSessionKey = useWriteContractWithSessionKey;
|
2370
|
+
exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; exports.useAddSessionKey = useAddSessionKey; exports.useAddWhitelistDestination = useAddWhitelistDestination; exports.useCancelRecoveryRequest = useCancelRecoveryRequest; exports.useConnect = useConnect; exports.useCreateNewSigner = useCreateNewSigner; exports.useDisconnect = useDisconnect; exports.useEstimateGas = useEstimateGas; exports.useGenerateQRCodeUrl = useGenerateQRCodeUrl; exports.useGetEnrichedOwners = useGetEnrichedOwners; exports.useGetGasPrice = useGetGasPrice; exports.useGetOwners = useGetOwners; exports.useGetRecoveryRequest = useGetRecoveryRequest; exports.useGetSessionFromAddress = useGetSessionFromAddress; exports.useGetTransactionCost = useGetTransactionCost; exports.useIsAddressWhitelistDestination = useIsAddressWhitelistDestination; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRemoveWhitelistDestination = useRemoveWhitelistDestination; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useRevokeSessionKey = useRevokeSessionKey; exports.useSendTransaction = useSendTransaction; exports.useSendTransactionWithSessionKey = useSendTransactionWithSessionKey; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract; exports.useWriteContractWithSessionKey = useWriteContractWithSessionKey;
|
package/dist/index.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Address, Transport, Chain, Hash, Hex, Abi, ContractFunctionName, ContractFunctionArgs, Account, DeriveChain, ContractFunctionParameters, GetChainParameter, GetValue, FormattedTransactionRequest, UnionOmit, SignableMessage } from 'viem';
|
2
2
|
import { createSafeSmartAccountParameters, ComethSmartAccountClient, SafeSmartAccount, EnrichedOwner, Session, AddSessionKeyParams, Signer, webAuthnOptions, QRCodeOptions, SetUpRecoveryModuleParams, IsRecoveryActiveParams, IsRecoveryActiveReturnType, RecoveryParamsResponse, GetRecoveryRequestParams, CancelRecoveryRequestParams } from '@cometh/connect-sdk-4337';
|
3
|
-
import { y, z, O, aI, a3, at,
|
3
|
+
import { y, z, O, aI, a3, at, b } from './hydration-Bnn1iiSg.js';
|
4
4
|
import React, { ReactNode } from 'react';
|
5
5
|
import { ENTRYPOINT_ADDRESS_V07_TYPE, EntryPoint } from 'permissionless/types/entrypoint';
|
6
6
|
import { GetAccountParameter } from 'viem/_types/types/account';
|
@@ -27,19 +27,6 @@ type UseBaseQueryResult<TData = unknown, TError = y> = at<TData, TError>;
|
|
27
27
|
type UseQueryResult<TData = unknown, TError = y> = UseBaseQueryResult<TData, TError>;
|
28
28
|
interface UseMutationOptions<TData = unknown, TError = y, TVariables = void, TContext = unknown> extends O<aI<TData, TError, TVariables, TContext>, '_defaulted'> {
|
29
29
|
}
|
30
|
-
type UseMutateFunction<TData = unknown, TError = y, TVariables = void, TContext = unknown> = (...args: Parameters<aK<TData, TError, TVariables, TContext>>) => void;
|
31
|
-
type UseMutateAsyncFunction<TData = unknown, TError = y, TVariables = void, TContext = unknown> = aK<TData, TError, TVariables, TContext>;
|
32
|
-
type UseBaseMutationResult<TData = unknown, TError = y, TVariables = unknown, TContext = unknown> = Override<aQ<TData, TError, TVariables, TContext>, {
|
33
|
-
mutate: UseMutateFunction<TData, TError, TVariables, TContext>;
|
34
|
-
}> & {
|
35
|
-
mutateAsync: UseMutateAsyncFunction<TData, TError, TVariables, TContext>;
|
36
|
-
};
|
37
|
-
type UseMutationResult<TData = unknown, TError = y, TVariables = unknown, TContext = unknown> = UseBaseMutationResult<TData, TError, TVariables, TContext>;
|
38
|
-
type Override<TTargetA, TTargetB> = {
|
39
|
-
[AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
|
40
|
-
};
|
41
|
-
|
42
|
-
declare function useMutation<TData = unknown, TError = y, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>, queryClient?: b): UseMutationResult<TData, TError, TVariables, TContext>;
|
43
30
|
|
44
31
|
type NetworkParams = {
|
45
32
|
chain?: Chain;
|
@@ -70,7 +57,7 @@ interface UseAccountResult {
|
|
70
57
|
}
|
71
58
|
declare const useAccount: () => UseAccountResult;
|
72
59
|
|
73
|
-
type MutationOptionsWithoutMutationFn
|
60
|
+
type MutationOptionsWithoutMutationFn = Omit<UseMutationOptions<any, any, any, any>, "mutationFn" | "mutationKey">;
|
74
61
|
type Transaction = {
|
75
62
|
to: Address;
|
76
63
|
value: bigint;
|
@@ -101,7 +88,6 @@ type SendTransactionMutate = (variables: UseSendTransactionProps) => void;
|
|
101
88
|
* This function returns a promise that resolves to the transaction hash.
|
102
89
|
*/
|
103
90
|
type SendTransactionMutateAsync = (variables: UseSendTransactionProps) => Promise<Hash>;
|
104
|
-
type MutationOptionsWithoutMutationFn = Omit<Parameters<typeof useMutation>[0], "mutationFn">;
|
105
91
|
type UseSendTransactionReturn = QueryResultType & {
|
106
92
|
sendTransaction: SendTransactionMutate;
|
107
93
|
sendTransactionAsync: SendTransactionMutateAsync;
|
@@ -272,7 +258,7 @@ type WriteContractParameters<abi extends Abi | readonly unknown[] = Abi, functio
|
|
272
258
|
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
273
259
|
dataSuffix?: Hex;
|
274
260
|
}> & UnionEvaluate<UnionOmit<FormattedTransactionRequest<derivedChain>, "data" | "from" | "to" | "value">>;
|
275
|
-
declare const useWriteContract: (mutationProps?: MutationOptionsWithoutMutationFn
|
261
|
+
declare const useWriteContract: (mutationProps?: MutationOptionsWithoutMutationFn) => UseWriteContractReturn;
|
276
262
|
|
277
263
|
/**
|
278
264
|
* Props for the useSendTransactionWithSessionKey hook.
|
@@ -310,7 +296,7 @@ type UseSendTransactionWithSessionKeyReturn = QueryResultType & {
|
|
310
296
|
*
|
311
297
|
* @throws {Error} If no smart account is found when trying to send a transaction.
|
312
298
|
*/
|
313
|
-
declare const useSendTransactionWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn
|
299
|
+
declare const useSendTransactionWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn) => UseSendTransactionWithSessionKeyReturn;
|
314
300
|
|
315
301
|
/**
|
316
302
|
* @description A custom hook for writing to smart contracts through a smart account using a session key.
|
@@ -392,7 +378,7 @@ type WriteContractWithSessionKeyParameters<abi extends Abi | readonly unknown[]
|
|
392
378
|
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
393
379
|
dataSuffix?: Hex;
|
394
380
|
}> & UnionEvaluate<UnionOmit<FormattedTransactionRequest<derivedChain>, "data" | "from" | "to" | "value">>;
|
395
|
-
declare const useWriteContractWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn
|
381
|
+
declare const useWriteContractWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn) => UseWriteContractWithSessionKeyReturn;
|
396
382
|
|
397
383
|
declare const useDisconnect: () => {
|
398
384
|
disconnect: () => void;
|
@@ -516,7 +502,7 @@ type UseValidateAddDeviceReturn = QueryResultType & {
|
|
516
502
|
*
|
517
503
|
* @throws {Error} If no smart account is found when trying to validate adding a device.
|
518
504
|
*/
|
519
|
-
declare const useValidateAddDevice: (mutationProps?: MutationOptionsWithoutMutationFn
|
505
|
+
declare const useValidateAddDevice: (mutationProps?: MutationOptionsWithoutMutationFn) => UseValidateAddDeviceReturn;
|
520
506
|
|
521
507
|
/**
|
522
508
|
* Props for the useVerifyMessage hook.
|
@@ -562,7 +548,7 @@ type UseVerifyMessageReturn = {
|
|
562
548
|
*
|
563
549
|
* @throws {Error} If no smart account is found when trying to verify a signature.
|
564
550
|
*/
|
565
|
-
declare const useVerifyMessage: (mutationProps?: MutationOptionsWithoutMutationFn
|
551
|
+
declare const useVerifyMessage: (mutationProps?: MutationOptionsWithoutMutationFn) => UseVerifyMessageReturn;
|
566
552
|
|
567
553
|
type GasPriceResult = {
|
568
554
|
maxFeePerGas: bigint;
|
@@ -948,4 +934,226 @@ declare const useSwitchChain: () => {
|
|
948
934
|
error: Error | null;
|
949
935
|
};
|
950
936
|
|
951
|
-
|
937
|
+
/**
|
938
|
+
* Props for the useGetTransactionCost hook.
|
939
|
+
* @property {Transaction | Transaction[]} transactions - A single transaction or an array of transactions to get cost for.
|
940
|
+
*/
|
941
|
+
type UseGetTransactionCostProps = {
|
942
|
+
transactions: Transaction | Transaction[];
|
943
|
+
};
|
944
|
+
/**
|
945
|
+
* Type for the getTransactionCost function.
|
946
|
+
* This function doesn't return a promise, suitable for fire-and-forget usage.
|
947
|
+
*/
|
948
|
+
type UseGetTransactionCostMutate = (variables: UseGetTransactionCostProps) => void;
|
949
|
+
/**
|
950
|
+
* Type for the getTransactionCostAsync function.
|
951
|
+
* This function returns a promise that resolves to the transaction cost in wei.
|
952
|
+
*/
|
953
|
+
type UseGetTransactionCostMutateAsync = (variables: UseGetTransactionCostProps) => Promise<{
|
954
|
+
totalGasCost: bigint;
|
955
|
+
}>;
|
956
|
+
type UseGetTransactionCostReturn = {
|
957
|
+
data?: bigint;
|
958
|
+
error: unknown;
|
959
|
+
isPending: boolean;
|
960
|
+
isSuccess: boolean;
|
961
|
+
isError: boolean;
|
962
|
+
getTransactionCost: UseGetTransactionCostMutate;
|
963
|
+
getTransactionCostAsync: UseGetTransactionCostMutateAsync;
|
964
|
+
};
|
965
|
+
/**
|
966
|
+
* A custom hook for getting transaction costs.
|
967
|
+
*
|
968
|
+
* This hook provides functionality to get gas costs for transactions using the smart account client.
|
969
|
+
* It can handle both single transactions and batched transactions.
|
970
|
+
*
|
971
|
+
* @param mutationProps Optional mutation properties from @tanstack/react-query
|
972
|
+
*
|
973
|
+
* @example
|
974
|
+
* ```tsx
|
975
|
+
* import { useGetTransactionCost } from "@/hooks/useGetTransactionCost";
|
976
|
+
* import { parseEther, type Address } from "viem";
|
977
|
+
*
|
978
|
+
* export const TransactionCost = () => {
|
979
|
+
* const { getTransactionCost, getTransactionCostAsync, isPending, isError, error, isSuccess, data } = useGetTransactionCost();
|
980
|
+
*
|
981
|
+
* const handleGetCost = async () => {
|
982
|
+
* try {
|
983
|
+
* // Example of getting cost for a single transaction
|
984
|
+
* const singleTxCost = await getTransactionCostAsync({
|
985
|
+
* transactions: {
|
986
|
+
* to: "0x..." as Address,
|
987
|
+
* value: parseEther("0.1"),
|
988
|
+
* data: "0x",
|
989
|
+
* }
|
990
|
+
* });
|
991
|
+
* console.log("Transaction cost:", singleTxCost.totalGasCost);
|
992
|
+
*
|
993
|
+
* // Example of getting cost for multiple transactions
|
994
|
+
* const batchTxCost = await getTransactionCostAsync({
|
995
|
+
* transactions: [
|
996
|
+
* {
|
997
|
+
* to: "0x..." as Address,
|
998
|
+
* value: parseEther("0.1"),
|
999
|
+
* data: "0x",
|
1000
|
+
* },
|
1001
|
+
* {
|
1002
|
+
* to: "0x..." as Address,
|
1003
|
+
* value: parseEther("0.2"),
|
1004
|
+
* data: "0x",
|
1005
|
+
* }
|
1006
|
+
* ]
|
1007
|
+
* });
|
1008
|
+
* console.log("Batch transaction cost:", batchTxCost.totalGasCost);
|
1009
|
+
* } catch (error) {
|
1010
|
+
* console.error("Error getting transaction cost:", error);
|
1011
|
+
* }
|
1012
|
+
* };
|
1013
|
+
*
|
1014
|
+
* return (
|
1015
|
+
* <div>
|
1016
|
+
* <button onClick={handleGetCost} disabled={isPending}>
|
1017
|
+
* Get Transaction Cost
|
1018
|
+
* </button>
|
1019
|
+
* {isError && <p>Error: {(error as Error).message}</p>}
|
1020
|
+
* {isSuccess && <p>Transaction cost: {data?.toString()} wei</p>}
|
1021
|
+
* </div>
|
1022
|
+
* );
|
1023
|
+
* };
|
1024
|
+
* ```
|
1025
|
+
*
|
1026
|
+
* @returns An object containing:
|
1027
|
+
* - `data`: The total transaction cost in wei (as bigint)
|
1028
|
+
* - `error`: Any error that occurred during cost calculation
|
1029
|
+
* - `isPending`: Whether the calculation is in progress
|
1030
|
+
* - `isSuccess`: Whether the calculation was successful
|
1031
|
+
* - `isError`: Whether an error occurred
|
1032
|
+
* - `getTransactionCost`: A function to trigger cost calculation without waiting for the result
|
1033
|
+
* - `getTransactionCostAsync`: A function to trigger cost calculation and wait for the result
|
1034
|
+
*/
|
1035
|
+
declare const useGetTransactionCost: (mutationProps?: MutationOptionsWithoutMutationFn) => UseGetTransactionCostReturn;
|
1036
|
+
|
1037
|
+
/**
|
1038
|
+
* Props for the useEstimateGas hook.
|
1039
|
+
* @property {Transaction | Transaction[]} transactions - A single transaction or an array of transactions to estimate gas for.
|
1040
|
+
*/
|
1041
|
+
type UseEstimateGasProps = {
|
1042
|
+
transactions: Transaction | Transaction[];
|
1043
|
+
};
|
1044
|
+
/**
|
1045
|
+
* Gas estimation result type
|
1046
|
+
*/
|
1047
|
+
type GasEstimationResult = {
|
1048
|
+
callGasLimit: bigint;
|
1049
|
+
verificationGasLimit: bigint;
|
1050
|
+
preVerificationGas: bigint;
|
1051
|
+
maxFeePerGas: bigint;
|
1052
|
+
maxPriorityFeePerGas: bigint;
|
1053
|
+
paymasterVerificationGasLimit?: bigint;
|
1054
|
+
paymasterPostOpGasLimit?: bigint;
|
1055
|
+
};
|
1056
|
+
/**
|
1057
|
+
* Type for the estimateGas function.
|
1058
|
+
* This function doesn't return a promise, suitable for fire-and-forget usage.
|
1059
|
+
*/
|
1060
|
+
type EstimateGasMutate = (variables: UseEstimateGasProps) => void;
|
1061
|
+
/**
|
1062
|
+
* Type for the estimateGasAsync function.
|
1063
|
+
* This function returns a promise that resolves to the detailed gas estimation.
|
1064
|
+
*/
|
1065
|
+
type EstimateGasMutateAsync = (variables: UseEstimateGasProps) => Promise<GasEstimationResult>;
|
1066
|
+
type UseEstimateGasReturn = {
|
1067
|
+
data?: GasEstimationResult;
|
1068
|
+
error: unknown;
|
1069
|
+
isPending: boolean;
|
1070
|
+
isSuccess: boolean;
|
1071
|
+
isError: boolean;
|
1072
|
+
estimateGas: EstimateGasMutate;
|
1073
|
+
estimateGasAsync: EstimateGasMutateAsync;
|
1074
|
+
};
|
1075
|
+
/**
|
1076
|
+
* A custom hook for estimating detailed gas parameters for transactions.
|
1077
|
+
*
|
1078
|
+
* This hook provides functionality to estimate various gas parameters for transactions
|
1079
|
+
* using the smart account client. It can handle both single transactions and batched transactions.
|
1080
|
+
*
|
1081
|
+
* @param mutationProps Optional mutation properties from @tanstack/react-query
|
1082
|
+
*
|
1083
|
+
* @example
|
1084
|
+
* ```tsx
|
1085
|
+
* import { useEstimateGas } from "@/hooks/useEstimateGas";
|
1086
|
+
* import { parseEther, type Address } from "viem";
|
1087
|
+
*
|
1088
|
+
* export const GasEstimator = () => {
|
1089
|
+
* const { estimateGas, estimateGasAsync, isPending, isError, error, isSuccess, data } = useEstimateGas();
|
1090
|
+
*
|
1091
|
+
* const handleEstimateGas = async () => {
|
1092
|
+
* try {
|
1093
|
+
* // Example of estimating gas for a single transaction
|
1094
|
+
* const singleTxEstimate = await estimateGasAsync({
|
1095
|
+
* transactions: {
|
1096
|
+
* to: "0x..." as Address,
|
1097
|
+
* value: parseEther("0.1"),
|
1098
|
+
* data: "0x",
|
1099
|
+
* }
|
1100
|
+
* });
|
1101
|
+
* console.log("Gas limits:", {
|
1102
|
+
* callGas: singleTxEstimate.callGasLimit.toString(),
|
1103
|
+
* verificationGas: singleTxEstimate.verificationGasLimit.toString(),
|
1104
|
+
* preVerificationGas: singleTxEstimate.preVerificationGas.toString(),
|
1105
|
+
* });
|
1106
|
+
*
|
1107
|
+
* // Example of estimating gas for multiple transactions
|
1108
|
+
* const batchTxEstimate = await estimateGasAsync({
|
1109
|
+
* transactions: [
|
1110
|
+
* {
|
1111
|
+
* to: "0x..." as Address,
|
1112
|
+
* value: parseEther("0.1"),
|
1113
|
+
* data: "0x",
|
1114
|
+
* },
|
1115
|
+
* {
|
1116
|
+
* to: "0x..." as Address,
|
1117
|
+
* value: parseEther("0.2"),
|
1118
|
+
* data: "0x",
|
1119
|
+
* }
|
1120
|
+
* ]
|
1121
|
+
* });
|
1122
|
+
* console.log("Batch transaction gas parameters:", batchTxEstimate);
|
1123
|
+
* } catch (error) {
|
1124
|
+
* console.error("Error estimating gas:", error);
|
1125
|
+
* }
|
1126
|
+
* };
|
1127
|
+
*
|
1128
|
+
* return (
|
1129
|
+
* <div>
|
1130
|
+
* <button onClick={handleEstimateGas} disabled={isPending}>
|
1131
|
+
* Estimate Gas Parameters
|
1132
|
+
* </button>
|
1133
|
+
* {isError && <p>Error: {(error as Error).message}</p>}
|
1134
|
+
* {isSuccess && data && (
|
1135
|
+
* <div>
|
1136
|
+
* <p>Call Gas Limit: {data.callGasLimit.toString()}</p>
|
1137
|
+
* <p>Verification Gas Limit: {data.verificationGasLimit.toString()}</p>
|
1138
|
+
* <p>Pre-verification Gas: {data.preVerificationGas.toString()}</p>
|
1139
|
+
* <p>Max Fee Per Gas: {data.maxFeePerGas.toString()}</p>
|
1140
|
+
* <p>Max Priority Fee Per Gas: {data.maxPriorityFeePerGas.toString()}</p>
|
1141
|
+
* </div>
|
1142
|
+
* )}
|
1143
|
+
* </div>
|
1144
|
+
* );
|
1145
|
+
* };
|
1146
|
+
* ```
|
1147
|
+
*
|
1148
|
+
* @returns An object containing:
|
1149
|
+
* - `data`: Detailed gas estimation parameters including various gas limits and fees
|
1150
|
+
* - `error`: Any error that occurred during estimation
|
1151
|
+
* - `isPending`: Whether the estimation is in progress
|
1152
|
+
* - `isSuccess`: Whether the estimation was successful
|
1153
|
+
* - `isError`: Whether an error occurred
|
1154
|
+
* - `estimateGas`: A function to trigger gas estimation without waiting for the result
|
1155
|
+
* - `estimateGasAsync`: A function to trigger gas estimation and wait for the result
|
1156
|
+
*/
|
1157
|
+
declare const useEstimateGas: (mutationProps?: MutationOptionsWithoutMutationFn) => UseEstimateGasReturn;
|
1158
|
+
|
1159
|
+
export { ConnectProvider, type SendTransactionMutate, type SendTransactionMutateAsync, type SendTransactionWithSessionKeyMutate, type SendTransactionWithSessionKeyMutateAsync, type UseAddOwnerReturn, type UseAddSessionKeyReturn, type UseAddWhitelistDestinationReturn, type UseRemoveOwnerReturn, type UseRemoveWhitelistDestinationReturn, type UseRetrieveAccountAddressFromPasskeyOptions, type UseRevokeSessionKeyReturn, type VerifyMessageMutate, type VerifyMessageMutateAsync, type WriteContractMutate, type WriteContractMutateAsync, type WriteContractWithSessionKeyMutate, type WriteContractWithSessionKeyMutateAsync, useAccount, useAddOwner, useAddSessionKey, useAddWhitelistDestination, useCancelRecoveryRequest, useConnect, useCreateNewSigner, useDisconnect, useEstimateGas, useGenerateQRCodeUrl, useGetEnrichedOwners, useGetGasPrice, useGetOwners, useGetRecoveryRequest, useGetSessionFromAddress, useGetTransactionCost, useIsAddressWhitelistDestination, useIsRecoveryActive, useRemoveOwner, useRemoveWhitelistDestination, useRetrieveAccountAddressFromPasskeyId, useRetrieveAccountAddressFromPasskeys, useRevokeSessionKey, useSendTransaction, useSendTransactionWithSessionKey, useSerializeUrlWithSignerPayload, useSetUpRecovery, useSignMessage, useSwitchChain, useValidateAddDevice, useVerifyMessage, useWriteContract, useWriteContractWithSessionKey };
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Address, Transport, Chain, Hash, Hex, Abi, ContractFunctionName, ContractFunctionArgs, Account, DeriveChain, ContractFunctionParameters, GetChainParameter, GetValue, FormattedTransactionRequest, UnionOmit, SignableMessage } from 'viem';
|
2
2
|
import { createSafeSmartAccountParameters, ComethSmartAccountClient, SafeSmartAccount, EnrichedOwner, Session, AddSessionKeyParams, Signer, webAuthnOptions, QRCodeOptions, SetUpRecoveryModuleParams, IsRecoveryActiveParams, IsRecoveryActiveReturnType, RecoveryParamsResponse, GetRecoveryRequestParams, CancelRecoveryRequestParams } from '@cometh/connect-sdk-4337';
|
3
|
-
import { y, z, O, aI, a3, at,
|
3
|
+
import { y, z, O, aI, a3, at, b } from './hydration-Bnn1iiSg.js';
|
4
4
|
import React, { ReactNode } from 'react';
|
5
5
|
import { ENTRYPOINT_ADDRESS_V07_TYPE, EntryPoint } from 'permissionless/types/entrypoint';
|
6
6
|
import { GetAccountParameter } from 'viem/_types/types/account';
|
@@ -27,19 +27,6 @@ type UseBaseQueryResult<TData = unknown, TError = y> = at<TData, TError>;
|
|
27
27
|
type UseQueryResult<TData = unknown, TError = y> = UseBaseQueryResult<TData, TError>;
|
28
28
|
interface UseMutationOptions<TData = unknown, TError = y, TVariables = void, TContext = unknown> extends O<aI<TData, TError, TVariables, TContext>, '_defaulted'> {
|
29
29
|
}
|
30
|
-
type UseMutateFunction<TData = unknown, TError = y, TVariables = void, TContext = unknown> = (...args: Parameters<aK<TData, TError, TVariables, TContext>>) => void;
|
31
|
-
type UseMutateAsyncFunction<TData = unknown, TError = y, TVariables = void, TContext = unknown> = aK<TData, TError, TVariables, TContext>;
|
32
|
-
type UseBaseMutationResult<TData = unknown, TError = y, TVariables = unknown, TContext = unknown> = Override<aQ<TData, TError, TVariables, TContext>, {
|
33
|
-
mutate: UseMutateFunction<TData, TError, TVariables, TContext>;
|
34
|
-
}> & {
|
35
|
-
mutateAsync: UseMutateAsyncFunction<TData, TError, TVariables, TContext>;
|
36
|
-
};
|
37
|
-
type UseMutationResult<TData = unknown, TError = y, TVariables = unknown, TContext = unknown> = UseBaseMutationResult<TData, TError, TVariables, TContext>;
|
38
|
-
type Override<TTargetA, TTargetB> = {
|
39
|
-
[AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
|
40
|
-
};
|
41
|
-
|
42
|
-
declare function useMutation<TData = unknown, TError = y, TVariables = void, TContext = unknown>(options: UseMutationOptions<TData, TError, TVariables, TContext>, queryClient?: b): UseMutationResult<TData, TError, TVariables, TContext>;
|
43
30
|
|
44
31
|
type NetworkParams = {
|
45
32
|
chain?: Chain;
|
@@ -70,7 +57,7 @@ interface UseAccountResult {
|
|
70
57
|
}
|
71
58
|
declare const useAccount: () => UseAccountResult;
|
72
59
|
|
73
|
-
type MutationOptionsWithoutMutationFn
|
60
|
+
type MutationOptionsWithoutMutationFn = Omit<UseMutationOptions<any, any, any, any>, "mutationFn" | "mutationKey">;
|
74
61
|
type Transaction = {
|
75
62
|
to: Address;
|
76
63
|
value: bigint;
|
@@ -101,7 +88,6 @@ type SendTransactionMutate = (variables: UseSendTransactionProps) => void;
|
|
101
88
|
* This function returns a promise that resolves to the transaction hash.
|
102
89
|
*/
|
103
90
|
type SendTransactionMutateAsync = (variables: UseSendTransactionProps) => Promise<Hash>;
|
104
|
-
type MutationOptionsWithoutMutationFn = Omit<Parameters<typeof useMutation>[0], "mutationFn">;
|
105
91
|
type UseSendTransactionReturn = QueryResultType & {
|
106
92
|
sendTransaction: SendTransactionMutate;
|
107
93
|
sendTransactionAsync: SendTransactionMutateAsync;
|
@@ -272,7 +258,7 @@ type WriteContractParameters<abi extends Abi | readonly unknown[] = Abi, functio
|
|
272
258
|
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
273
259
|
dataSuffix?: Hex;
|
274
260
|
}> & UnionEvaluate<UnionOmit<FormattedTransactionRequest<derivedChain>, "data" | "from" | "to" | "value">>;
|
275
|
-
declare const useWriteContract: (mutationProps?: MutationOptionsWithoutMutationFn
|
261
|
+
declare const useWriteContract: (mutationProps?: MutationOptionsWithoutMutationFn) => UseWriteContractReturn;
|
276
262
|
|
277
263
|
/**
|
278
264
|
* Props for the useSendTransactionWithSessionKey hook.
|
@@ -310,7 +296,7 @@ type UseSendTransactionWithSessionKeyReturn = QueryResultType & {
|
|
310
296
|
*
|
311
297
|
* @throws {Error} If no smart account is found when trying to send a transaction.
|
312
298
|
*/
|
313
|
-
declare const useSendTransactionWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn
|
299
|
+
declare const useSendTransactionWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn) => UseSendTransactionWithSessionKeyReturn;
|
314
300
|
|
315
301
|
/**
|
316
302
|
* @description A custom hook for writing to smart contracts through a smart account using a session key.
|
@@ -392,7 +378,7 @@ type WriteContractWithSessionKeyParameters<abi extends Abi | readonly unknown[]
|
|
392
378
|
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
393
379
|
dataSuffix?: Hex;
|
394
380
|
}> & UnionEvaluate<UnionOmit<FormattedTransactionRequest<derivedChain>, "data" | "from" | "to" | "value">>;
|
395
|
-
declare const useWriteContractWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn
|
381
|
+
declare const useWriteContractWithSessionKey: (mutationProps?: MutationOptionsWithoutMutationFn) => UseWriteContractWithSessionKeyReturn;
|
396
382
|
|
397
383
|
declare const useDisconnect: () => {
|
398
384
|
disconnect: () => void;
|
@@ -516,7 +502,7 @@ type UseValidateAddDeviceReturn = QueryResultType & {
|
|
516
502
|
*
|
517
503
|
* @throws {Error} If no smart account is found when trying to validate adding a device.
|
518
504
|
*/
|
519
|
-
declare const useValidateAddDevice: (mutationProps?: MutationOptionsWithoutMutationFn
|
505
|
+
declare const useValidateAddDevice: (mutationProps?: MutationOptionsWithoutMutationFn) => UseValidateAddDeviceReturn;
|
520
506
|
|
521
507
|
/**
|
522
508
|
* Props for the useVerifyMessage hook.
|
@@ -562,7 +548,7 @@ type UseVerifyMessageReturn = {
|
|
562
548
|
*
|
563
549
|
* @throws {Error} If no smart account is found when trying to verify a signature.
|
564
550
|
*/
|
565
|
-
declare const useVerifyMessage: (mutationProps?: MutationOptionsWithoutMutationFn
|
551
|
+
declare const useVerifyMessage: (mutationProps?: MutationOptionsWithoutMutationFn) => UseVerifyMessageReturn;
|
566
552
|
|
567
553
|
type GasPriceResult = {
|
568
554
|
maxFeePerGas: bigint;
|
@@ -948,4 +934,226 @@ declare const useSwitchChain: () => {
|
|
948
934
|
error: Error | null;
|
949
935
|
};
|
950
936
|
|
951
|
-
|
937
|
+
/**
|
938
|
+
* Props for the useGetTransactionCost hook.
|
939
|
+
* @property {Transaction | Transaction[]} transactions - A single transaction or an array of transactions to get cost for.
|
940
|
+
*/
|
941
|
+
type UseGetTransactionCostProps = {
|
942
|
+
transactions: Transaction | Transaction[];
|
943
|
+
};
|
944
|
+
/**
|
945
|
+
* Type for the getTransactionCost function.
|
946
|
+
* This function doesn't return a promise, suitable for fire-and-forget usage.
|
947
|
+
*/
|
948
|
+
type UseGetTransactionCostMutate = (variables: UseGetTransactionCostProps) => void;
|
949
|
+
/**
|
950
|
+
* Type for the getTransactionCostAsync function.
|
951
|
+
* This function returns a promise that resolves to the transaction cost in wei.
|
952
|
+
*/
|
953
|
+
type UseGetTransactionCostMutateAsync = (variables: UseGetTransactionCostProps) => Promise<{
|
954
|
+
totalGasCost: bigint;
|
955
|
+
}>;
|
956
|
+
type UseGetTransactionCostReturn = {
|
957
|
+
data?: bigint;
|
958
|
+
error: unknown;
|
959
|
+
isPending: boolean;
|
960
|
+
isSuccess: boolean;
|
961
|
+
isError: boolean;
|
962
|
+
getTransactionCost: UseGetTransactionCostMutate;
|
963
|
+
getTransactionCostAsync: UseGetTransactionCostMutateAsync;
|
964
|
+
};
|
965
|
+
/**
|
966
|
+
* A custom hook for getting transaction costs.
|
967
|
+
*
|
968
|
+
* This hook provides functionality to get gas costs for transactions using the smart account client.
|
969
|
+
* It can handle both single transactions and batched transactions.
|
970
|
+
*
|
971
|
+
* @param mutationProps Optional mutation properties from @tanstack/react-query
|
972
|
+
*
|
973
|
+
* @example
|
974
|
+
* ```tsx
|
975
|
+
* import { useGetTransactionCost } from "@/hooks/useGetTransactionCost";
|
976
|
+
* import { parseEther, type Address } from "viem";
|
977
|
+
*
|
978
|
+
* export const TransactionCost = () => {
|
979
|
+
* const { getTransactionCost, getTransactionCostAsync, isPending, isError, error, isSuccess, data } = useGetTransactionCost();
|
980
|
+
*
|
981
|
+
* const handleGetCost = async () => {
|
982
|
+
* try {
|
983
|
+
* // Example of getting cost for a single transaction
|
984
|
+
* const singleTxCost = await getTransactionCostAsync({
|
985
|
+
* transactions: {
|
986
|
+
* to: "0x..." as Address,
|
987
|
+
* value: parseEther("0.1"),
|
988
|
+
* data: "0x",
|
989
|
+
* }
|
990
|
+
* });
|
991
|
+
* console.log("Transaction cost:", singleTxCost.totalGasCost);
|
992
|
+
*
|
993
|
+
* // Example of getting cost for multiple transactions
|
994
|
+
* const batchTxCost = await getTransactionCostAsync({
|
995
|
+
* transactions: [
|
996
|
+
* {
|
997
|
+
* to: "0x..." as Address,
|
998
|
+
* value: parseEther("0.1"),
|
999
|
+
* data: "0x",
|
1000
|
+
* },
|
1001
|
+
* {
|
1002
|
+
* to: "0x..." as Address,
|
1003
|
+
* value: parseEther("0.2"),
|
1004
|
+
* data: "0x",
|
1005
|
+
* }
|
1006
|
+
* ]
|
1007
|
+
* });
|
1008
|
+
* console.log("Batch transaction cost:", batchTxCost.totalGasCost);
|
1009
|
+
* } catch (error) {
|
1010
|
+
* console.error("Error getting transaction cost:", error);
|
1011
|
+
* }
|
1012
|
+
* };
|
1013
|
+
*
|
1014
|
+
* return (
|
1015
|
+
* <div>
|
1016
|
+
* <button onClick={handleGetCost} disabled={isPending}>
|
1017
|
+
* Get Transaction Cost
|
1018
|
+
* </button>
|
1019
|
+
* {isError && <p>Error: {(error as Error).message}</p>}
|
1020
|
+
* {isSuccess && <p>Transaction cost: {data?.toString()} wei</p>}
|
1021
|
+
* </div>
|
1022
|
+
* );
|
1023
|
+
* };
|
1024
|
+
* ```
|
1025
|
+
*
|
1026
|
+
* @returns An object containing:
|
1027
|
+
* - `data`: The total transaction cost in wei (as bigint)
|
1028
|
+
* - `error`: Any error that occurred during cost calculation
|
1029
|
+
* - `isPending`: Whether the calculation is in progress
|
1030
|
+
* - `isSuccess`: Whether the calculation was successful
|
1031
|
+
* - `isError`: Whether an error occurred
|
1032
|
+
* - `getTransactionCost`: A function to trigger cost calculation without waiting for the result
|
1033
|
+
* - `getTransactionCostAsync`: A function to trigger cost calculation and wait for the result
|
1034
|
+
*/
|
1035
|
+
declare const useGetTransactionCost: (mutationProps?: MutationOptionsWithoutMutationFn) => UseGetTransactionCostReturn;
|
1036
|
+
|
1037
|
+
/**
|
1038
|
+
* Props for the useEstimateGas hook.
|
1039
|
+
* @property {Transaction | Transaction[]} transactions - A single transaction or an array of transactions to estimate gas for.
|
1040
|
+
*/
|
1041
|
+
type UseEstimateGasProps = {
|
1042
|
+
transactions: Transaction | Transaction[];
|
1043
|
+
};
|
1044
|
+
/**
|
1045
|
+
* Gas estimation result type
|
1046
|
+
*/
|
1047
|
+
type GasEstimationResult = {
|
1048
|
+
callGasLimit: bigint;
|
1049
|
+
verificationGasLimit: bigint;
|
1050
|
+
preVerificationGas: bigint;
|
1051
|
+
maxFeePerGas: bigint;
|
1052
|
+
maxPriorityFeePerGas: bigint;
|
1053
|
+
paymasterVerificationGasLimit?: bigint;
|
1054
|
+
paymasterPostOpGasLimit?: bigint;
|
1055
|
+
};
|
1056
|
+
/**
|
1057
|
+
* Type for the estimateGas function.
|
1058
|
+
* This function doesn't return a promise, suitable for fire-and-forget usage.
|
1059
|
+
*/
|
1060
|
+
type EstimateGasMutate = (variables: UseEstimateGasProps) => void;
|
1061
|
+
/**
|
1062
|
+
* Type for the estimateGasAsync function.
|
1063
|
+
* This function returns a promise that resolves to the detailed gas estimation.
|
1064
|
+
*/
|
1065
|
+
type EstimateGasMutateAsync = (variables: UseEstimateGasProps) => Promise<GasEstimationResult>;
|
1066
|
+
type UseEstimateGasReturn = {
|
1067
|
+
data?: GasEstimationResult;
|
1068
|
+
error: unknown;
|
1069
|
+
isPending: boolean;
|
1070
|
+
isSuccess: boolean;
|
1071
|
+
isError: boolean;
|
1072
|
+
estimateGas: EstimateGasMutate;
|
1073
|
+
estimateGasAsync: EstimateGasMutateAsync;
|
1074
|
+
};
|
1075
|
+
/**
|
1076
|
+
* A custom hook for estimating detailed gas parameters for transactions.
|
1077
|
+
*
|
1078
|
+
* This hook provides functionality to estimate various gas parameters for transactions
|
1079
|
+
* using the smart account client. It can handle both single transactions and batched transactions.
|
1080
|
+
*
|
1081
|
+
* @param mutationProps Optional mutation properties from @tanstack/react-query
|
1082
|
+
*
|
1083
|
+
* @example
|
1084
|
+
* ```tsx
|
1085
|
+
* import { useEstimateGas } from "@/hooks/useEstimateGas";
|
1086
|
+
* import { parseEther, type Address } from "viem";
|
1087
|
+
*
|
1088
|
+
* export const GasEstimator = () => {
|
1089
|
+
* const { estimateGas, estimateGasAsync, isPending, isError, error, isSuccess, data } = useEstimateGas();
|
1090
|
+
*
|
1091
|
+
* const handleEstimateGas = async () => {
|
1092
|
+
* try {
|
1093
|
+
* // Example of estimating gas for a single transaction
|
1094
|
+
* const singleTxEstimate = await estimateGasAsync({
|
1095
|
+
* transactions: {
|
1096
|
+
* to: "0x..." as Address,
|
1097
|
+
* value: parseEther("0.1"),
|
1098
|
+
* data: "0x",
|
1099
|
+
* }
|
1100
|
+
* });
|
1101
|
+
* console.log("Gas limits:", {
|
1102
|
+
* callGas: singleTxEstimate.callGasLimit.toString(),
|
1103
|
+
* verificationGas: singleTxEstimate.verificationGasLimit.toString(),
|
1104
|
+
* preVerificationGas: singleTxEstimate.preVerificationGas.toString(),
|
1105
|
+
* });
|
1106
|
+
*
|
1107
|
+
* // Example of estimating gas for multiple transactions
|
1108
|
+
* const batchTxEstimate = await estimateGasAsync({
|
1109
|
+
* transactions: [
|
1110
|
+
* {
|
1111
|
+
* to: "0x..." as Address,
|
1112
|
+
* value: parseEther("0.1"),
|
1113
|
+
* data: "0x",
|
1114
|
+
* },
|
1115
|
+
* {
|
1116
|
+
* to: "0x..." as Address,
|
1117
|
+
* value: parseEther("0.2"),
|
1118
|
+
* data: "0x",
|
1119
|
+
* }
|
1120
|
+
* ]
|
1121
|
+
* });
|
1122
|
+
* console.log("Batch transaction gas parameters:", batchTxEstimate);
|
1123
|
+
* } catch (error) {
|
1124
|
+
* console.error("Error estimating gas:", error);
|
1125
|
+
* }
|
1126
|
+
* };
|
1127
|
+
*
|
1128
|
+
* return (
|
1129
|
+
* <div>
|
1130
|
+
* <button onClick={handleEstimateGas} disabled={isPending}>
|
1131
|
+
* Estimate Gas Parameters
|
1132
|
+
* </button>
|
1133
|
+
* {isError && <p>Error: {(error as Error).message}</p>}
|
1134
|
+
* {isSuccess && data && (
|
1135
|
+
* <div>
|
1136
|
+
* <p>Call Gas Limit: {data.callGasLimit.toString()}</p>
|
1137
|
+
* <p>Verification Gas Limit: {data.verificationGasLimit.toString()}</p>
|
1138
|
+
* <p>Pre-verification Gas: {data.preVerificationGas.toString()}</p>
|
1139
|
+
* <p>Max Fee Per Gas: {data.maxFeePerGas.toString()}</p>
|
1140
|
+
* <p>Max Priority Fee Per Gas: {data.maxPriorityFeePerGas.toString()}</p>
|
1141
|
+
* </div>
|
1142
|
+
* )}
|
1143
|
+
* </div>
|
1144
|
+
* );
|
1145
|
+
* };
|
1146
|
+
* ```
|
1147
|
+
*
|
1148
|
+
* @returns An object containing:
|
1149
|
+
* - `data`: Detailed gas estimation parameters including various gas limits and fees
|
1150
|
+
* - `error`: Any error that occurred during estimation
|
1151
|
+
* - `isPending`: Whether the estimation is in progress
|
1152
|
+
* - `isSuccess`: Whether the estimation was successful
|
1153
|
+
* - `isError`: Whether an error occurred
|
1154
|
+
* - `estimateGas`: A function to trigger gas estimation without waiting for the result
|
1155
|
+
* - `estimateGasAsync`: A function to trigger gas estimation and wait for the result
|
1156
|
+
*/
|
1157
|
+
declare const useEstimateGas: (mutationProps?: MutationOptionsWithoutMutationFn) => UseEstimateGasReturn;
|
1158
|
+
|
1159
|
+
export { ConnectProvider, type SendTransactionMutate, type SendTransactionMutateAsync, type SendTransactionWithSessionKeyMutate, type SendTransactionWithSessionKeyMutateAsync, type UseAddOwnerReturn, type UseAddSessionKeyReturn, type UseAddWhitelistDestinationReturn, type UseRemoveOwnerReturn, type UseRemoveWhitelistDestinationReturn, type UseRetrieveAccountAddressFromPasskeyOptions, type UseRevokeSessionKeyReturn, type VerifyMessageMutate, type VerifyMessageMutateAsync, type WriteContractMutate, type WriteContractMutateAsync, type WriteContractWithSessionKeyMutate, type WriteContractWithSessionKeyMutateAsync, useAccount, useAddOwner, useAddSessionKey, useAddWhitelistDestination, useCancelRecoveryRequest, useConnect, useCreateNewSigner, useDisconnect, useEstimateGas, useGenerateQRCodeUrl, useGetEnrichedOwners, useGetGasPrice, useGetOwners, useGetRecoveryRequest, useGetSessionFromAddress, useGetTransactionCost, useIsAddressWhitelistDestination, useIsRecoveryActive, useRemoveOwner, useRemoveWhitelistDestination, useRetrieveAccountAddressFromPasskeyId, useRetrieveAccountAddressFromPasskeys, useRevokeSessionKey, useSendTransaction, useSendTransactionWithSessionKey, useSerializeUrlWithSignerPayload, useSetUpRecovery, useSignMessage, useSwitchChain, useValidateAddDevice, useVerifyMessage, useWriteContract, useWriteContractWithSessionKey };
|
package/dist/index.js
CHANGED
@@ -2265,6 +2265,73 @@ var useSwitchChain = () => {
|
|
2265
2265
|
error
|
2266
2266
|
};
|
2267
2267
|
};
|
2268
|
+
|
2269
|
+
// src/hooks/useGetTransactionCost.ts
|
2270
|
+
var useGetTransactionCost = (mutationProps) => {
|
2271
|
+
const { smartAccountClient, queryClient } = useSmartAccount();
|
2272
|
+
const { mutate, mutateAsync, ...result } = useMutation(
|
2273
|
+
{
|
2274
|
+
mutationFn: async (variables) => {
|
2275
|
+
if (!smartAccountClient) {
|
2276
|
+
throw new Error("No smart account found");
|
2277
|
+
}
|
2278
|
+
const { transactions } = variables;
|
2279
|
+
const userOperation = await smartAccountClient.account.prepareUserOperation(
|
2280
|
+
transactions
|
2281
|
+
);
|
2282
|
+
const estimateGas = await smartAccountClient.estimateGas({
|
2283
|
+
userOperation
|
2284
|
+
});
|
2285
|
+
const totalGas = estimateGas.preVerificationGas + estimateGas.verificationGasLimit + estimateGas.callGasLimit;
|
2286
|
+
return { totalGasCost: totalGas * estimateGas.maxFeePerGas };
|
2287
|
+
},
|
2288
|
+
...mutationProps
|
2289
|
+
},
|
2290
|
+
queryClient
|
2291
|
+
);
|
2292
|
+
return {
|
2293
|
+
data: result.data?.totalGasCost,
|
2294
|
+
error: result.error,
|
2295
|
+
isPending: result.isPending,
|
2296
|
+
isSuccess: result.isSuccess,
|
2297
|
+
isError: result.isError,
|
2298
|
+
getTransactionCost: mutate,
|
2299
|
+
getTransactionCostAsync: mutateAsync
|
2300
|
+
};
|
2301
|
+
};
|
2302
|
+
|
2303
|
+
// src/hooks/useEstimateGas.ts
|
2304
|
+
var useEstimateGas = (mutationProps) => {
|
2305
|
+
const { smartAccountClient, queryClient } = useSmartAccount();
|
2306
|
+
const { mutate, mutateAsync, ...result } = useMutation(
|
2307
|
+
{
|
2308
|
+
mutationFn: async (variables) => {
|
2309
|
+
if (!smartAccountClient) {
|
2310
|
+
throw new Error("No smart account found");
|
2311
|
+
}
|
2312
|
+
const { transactions } = variables;
|
2313
|
+
const userOperation = await smartAccountClient.account.prepareUserOperation(
|
2314
|
+
transactions
|
2315
|
+
);
|
2316
|
+
const estimateGas = await smartAccountClient.estimateGas({
|
2317
|
+
userOperation
|
2318
|
+
});
|
2319
|
+
return estimateGas;
|
2320
|
+
},
|
2321
|
+
...mutationProps
|
2322
|
+
},
|
2323
|
+
queryClient
|
2324
|
+
);
|
2325
|
+
return {
|
2326
|
+
data: result.data,
|
2327
|
+
error: result.error,
|
2328
|
+
isPending: result.isPending,
|
2329
|
+
isSuccess: result.isSuccess,
|
2330
|
+
isError: result.isError,
|
2331
|
+
estimateGas: mutate,
|
2332
|
+
estimateGasAsync: mutateAsync
|
2333
|
+
};
|
2334
|
+
};
|
2268
2335
|
export {
|
2269
2336
|
ConnectProvider,
|
2270
2337
|
useAccount,
|
@@ -2275,12 +2342,14 @@ export {
|
|
2275
2342
|
useConnect,
|
2276
2343
|
useCreateNewSigner,
|
2277
2344
|
useDisconnect,
|
2345
|
+
useEstimateGas,
|
2278
2346
|
useGenerateQRCodeUrl,
|
2279
2347
|
useGetEnrichedOwners,
|
2280
2348
|
useGetGasPrice,
|
2281
2349
|
useGetOwners,
|
2282
2350
|
useGetRecoveryRequest,
|
2283
2351
|
useGetSessionFromAddress,
|
2352
|
+
useGetTransactionCost,
|
2284
2353
|
useIsAddressWhitelistDestination,
|
2285
2354
|
useIsRecoveryActive,
|
2286
2355
|
useRemoveOwner,
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"url": "https://twitter.com/slovaye"
|
8
8
|
}
|
9
9
|
],
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.12-dev.1",
|
11
11
|
"description": "React hooks Connect 4337",
|
12
12
|
"repository": "https://github.com/cometh-hq/connect-sdk-4337.git",
|
13
13
|
"keywords": [
|
@@ -58,7 +58,7 @@
|
|
58
58
|
"typescript": "^5"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@cometh/connect-sdk-4337": "
|
61
|
+
"@cometh/connect-sdk-4337": "0.1.1-3.dev-1",
|
62
62
|
"permissionless": "0.1.31"
|
63
63
|
}
|
64
64
|
}
|