@cometh/connect-react-hooks 0.0.12-dev.3 → 0.1.0-dev.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.
package/dist/index.js CHANGED
@@ -9,7 +9,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
9
9
 
10
10
  // src/actions/createSmartAccount.ts
11
11
  import {
12
- ENTRYPOINT_ADDRESS_V07,
13
12
  createComethPaymasterClient,
14
13
  createSafeSmartAccount,
15
14
  createSmartAccountClient
@@ -21,7 +20,7 @@ async function createSmartAccount(config) {
21
20
  paymasterUrl,
22
21
  apiKey,
23
22
  chain,
24
- rpcUrl,
23
+ publicClient,
25
24
  baseUrl,
26
25
  comethSignerConfig,
27
26
  safeContractConfig,
@@ -30,10 +29,9 @@ async function createSmartAccount(config) {
30
29
  const account = await createSafeSmartAccount({
31
30
  apiKey,
32
31
  chain,
33
- rpcUrl,
32
+ publicClient,
34
33
  baseUrl,
35
34
  smartAccountAddress,
36
- entryPoint: ENTRYPOINT_ADDRESS_V07,
37
35
  comethSignerConfig,
38
36
  safeContractConfig
39
37
  });
@@ -42,27 +40,26 @@ async function createSmartAccount(config) {
42
40
  const paymasterClient = await createComethPaymasterClient({
43
41
  transport: http(paymasterUrl),
44
42
  chain,
45
- entryPoint: ENTRYPOINT_ADDRESS_V07,
46
- rpcUrl
43
+ publicClient
47
44
  });
48
45
  client = createSmartAccountClient({
49
46
  account,
50
- entryPoint: ENTRYPOINT_ADDRESS_V07,
51
47
  chain,
52
48
  bundlerTransport: http(bundlerUrl),
53
- middleware: {
54
- sponsorUserOperation: paymasterClient.sponsorUserOperation,
55
- gasPrice: paymasterClient.gasPrice
49
+ paymaster: paymasterClient,
50
+ userOperation: {
51
+ estimateFeesPerGas: async () => {
52
+ return await paymasterClient.getUserOperationGasPrice();
53
+ }
56
54
  },
57
- rpcUrl
55
+ publicClient
58
56
  });
59
57
  } else {
60
58
  client = createSmartAccountClient({
61
59
  account,
62
- entryPoint: ENTRYPOINT_ADDRESS_V07,
63
60
  chain,
64
61
  bundlerTransport: http(bundlerUrl),
65
- rpcUrl
62
+ publicClient
66
63
  });
67
64
  }
68
65
  const address = client.account.address;
@@ -128,7 +125,7 @@ var ConnectProvider = ({
128
125
  console.log(e);
129
126
  }
130
127
  },
131
- [config]
128
+ [config, config.networksConfig[0].chain]
132
129
  );
133
130
  const disconnectSmartAccount = useCallback(async () => {
134
131
  setSmartAccountClient(null);
@@ -230,7 +227,6 @@ var Subscribable = class {
230
227
  // ../../node_modules/@tanstack/query-core/build/modern/utils.js
231
228
  var isServer = typeof window === "undefined" || "Deno" in globalThis;
232
229
  function noop() {
233
- return void 0;
234
230
  }
235
231
  function isValidTimeout(value) {
236
232
  return typeof value === "number" && value >= 0 && value !== Infinity;
@@ -322,6 +318,15 @@ function replaceData(prevData, data, options) {
322
318
  if (typeof options.structuralSharing === "function") {
323
319
  return options.structuralSharing(prevData, data);
324
320
  } else if (options.structuralSharing !== false) {
321
+ if (process.env.NODE_ENV !== "production") {
322
+ try {
323
+ return replaceEqualDeep(prevData, data);
324
+ } catch (error) {
325
+ console.error(
326
+ `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`
327
+ );
328
+ }
329
+ }
325
330
  return replaceEqualDeep(prevData, data);
326
331
  }
327
332
  return data;
@@ -448,6 +453,39 @@ var OnlineManager = (_a2 = class extends Subscribable {
448
453
  }, _online = new WeakMap(), _cleanup2 = new WeakMap(), _setup2 = new WeakMap(), _a2);
449
454
  var onlineManager = new OnlineManager();
450
455
 
456
+ // ../../node_modules/@tanstack/query-core/build/modern/thenable.js
457
+ function pendingThenable() {
458
+ let resolve;
459
+ let reject;
460
+ const thenable = new Promise((_resolve, _reject) => {
461
+ resolve = _resolve;
462
+ reject = _reject;
463
+ });
464
+ thenable.status = "pending";
465
+ thenable.catch(() => {
466
+ });
467
+ function finalize(data) {
468
+ Object.assign(thenable, data);
469
+ delete thenable.resolve;
470
+ delete thenable.reject;
471
+ }
472
+ thenable.resolve = (value) => {
473
+ finalize({
474
+ status: "fulfilled",
475
+ value
476
+ });
477
+ resolve(value);
478
+ };
479
+ thenable.reject = (reason) => {
480
+ finalize({
481
+ status: "rejected",
482
+ reason
483
+ });
484
+ reject(reason);
485
+ };
486
+ return thenable;
487
+ }
488
+
451
489
  // ../../node_modules/@tanstack/query-core/build/modern/retryer.js
452
490
  function canFetch(networkMode) {
453
491
  return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
@@ -464,22 +502,6 @@ function createNotifyManager() {
464
502
  callback();
465
503
  };
466
504
  let scheduleFn = (cb) => setTimeout(cb, 0);
467
- const setScheduler = (fn) => {
468
- scheduleFn = fn;
469
- };
470
- const batch = (callback) => {
471
- let result;
472
- transactions++;
473
- try {
474
- result = callback();
475
- } finally {
476
- transactions--;
477
- if (!transactions) {
478
- flush();
479
- }
480
- }
481
- return result;
482
- };
483
505
  const schedule = (callback) => {
484
506
  if (transactions) {
485
507
  queue.push(callback);
@@ -489,13 +511,6 @@ function createNotifyManager() {
489
511
  });
490
512
  }
491
513
  };
492
- const batchCalls = (callback) => {
493
- return (...args) => {
494
- schedule(() => {
495
- callback(...args);
496
- });
497
- };
498
- };
499
514
  const flush = () => {
500
515
  const originalQueue = queue;
501
516
  queue = [];
@@ -509,19 +524,48 @@ function createNotifyManager() {
509
524
  });
510
525
  }
511
526
  };
512
- const setNotifyFunction = (fn) => {
513
- notifyFn = fn;
514
- };
515
- const setBatchNotifyFunction = (fn) => {
516
- batchNotifyFn = fn;
517
- };
518
527
  return {
519
- batch,
520
- batchCalls,
528
+ batch: (callback) => {
529
+ let result;
530
+ transactions++;
531
+ try {
532
+ result = callback();
533
+ } finally {
534
+ transactions--;
535
+ if (!transactions) {
536
+ flush();
537
+ }
538
+ }
539
+ return result;
540
+ },
541
+ /**
542
+ * All calls to the wrapped function will be batched.
543
+ */
544
+ batchCalls: (callback) => {
545
+ return (...args) => {
546
+ schedule(() => {
547
+ callback(...args);
548
+ });
549
+ };
550
+ },
521
551
  schedule,
522
- setNotifyFunction,
523
- setBatchNotifyFunction,
524
- setScheduler
552
+ /**
553
+ * Use this method to set a custom notify function.
554
+ * This can be used to for example wrap notifications with `React.act` while running tests.
555
+ */
556
+ setNotifyFunction: (fn) => {
557
+ notifyFn = fn;
558
+ },
559
+ /**
560
+ * Use this method to set a custom function to batch notifications together into a single tick.
561
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
562
+ */
563
+ setBatchNotifyFunction: (fn) => {
564
+ batchNotifyFn = fn;
565
+ },
566
+ setScheduler: (fn) => {
567
+ scheduleFn = fn;
568
+ }
525
569
  };
526
570
  }
527
571
  var notifyManager = createNotifyManager();
@@ -555,7 +599,7 @@ function getDefaultState() {
555
599
  }
556
600
 
557
601
  // ../../node_modules/@tanstack/query-core/build/modern/queryObserver.js
558
- var _client, _currentQuery, _currentQueryInitialState, _currentResult, _currentResultState, _currentResultOptions, _selectError, _selectFn, _selectResult, _lastQueryWithDefinedData, _staleTimeoutId, _refetchIntervalId, _currentRefetchInterval, _trackedProps, _QueryObserver_instances, executeFetch_fn, updateStaleTimeout_fn, computeRefetchInterval_fn, updateRefetchInterval_fn, updateTimers_fn, clearStaleTimeout_fn, clearRefetchInterval_fn, updateQuery_fn, notify_fn, _a3;
602
+ var _client, _currentQuery, _currentQueryInitialState, _currentResult, _currentResultState, _currentResultOptions, _currentThenable, _selectError, _selectFn, _selectResult, _lastQueryWithDefinedData, _staleTimeoutId, _refetchIntervalId, _currentRefetchInterval, _trackedProps, _QueryObserver_instances, executeFetch_fn, updateStaleTimeout_fn, computeRefetchInterval_fn, updateRefetchInterval_fn, updateTimers_fn, clearStaleTimeout_fn, clearRefetchInterval_fn, updateQuery_fn, notify_fn, _a3;
559
603
  var QueryObserver = (_a3 = class extends Subscribable {
560
604
  constructor(client, options) {
561
605
  super();
@@ -566,6 +610,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
566
610
  __privateAdd(this, _currentResult);
567
611
  __privateAdd(this, _currentResultState);
568
612
  __privateAdd(this, _currentResultOptions);
613
+ __privateAdd(this, _currentThenable);
569
614
  __privateAdd(this, _selectError);
570
615
  __privateAdd(this, _selectFn);
571
616
  __privateAdd(this, _selectResult);
@@ -579,6 +624,12 @@ var QueryObserver = (_a3 = class extends Subscribable {
579
624
  this.options = options;
580
625
  __privateSet(this, _client, client);
581
626
  __privateSet(this, _selectError, null);
627
+ __privateSet(this, _currentThenable, pendingThenable());
628
+ if (!this.options.experimental_prefetchInRender) {
629
+ __privateGet(this, _currentThenable).reject(
630
+ new Error("experimental_prefetchInRender feature flag is not enabled")
631
+ );
632
+ }
582
633
  this.bindMethods();
583
634
  this.setOptions(options);
584
635
  }
@@ -699,7 +750,6 @@ var QueryObserver = (_a3 = class extends Subscribable {
699
750
  fetchOptimistic(options) {
700
751
  const defaultedOptions = __privateGet(this, _client).defaultQueryOptions(options);
701
752
  const query = __privateGet(this, _client).getQueryCache().build(__privateGet(this, _client), defaultedOptions);
702
- query.isFetchingOptimistic = true;
703
753
  return query.fetch().then(() => this.createResult(query, defaultedOptions));
704
754
  }
705
755
  fetch(fetchOptions) {
@@ -818,9 +868,42 @@ var QueryObserver = (_a3 = class extends Subscribable {
818
868
  isPlaceholderData,
819
869
  isRefetchError: isError && hasData,
820
870
  isStale: isStale(query, options),
821
- refetch: this.refetch
871
+ refetch: this.refetch,
872
+ promise: __privateGet(this, _currentThenable)
822
873
  };
823
- return result;
874
+ const nextResult = result;
875
+ if (this.options.experimental_prefetchInRender) {
876
+ const finalizeThenableIfPossible = (thenable) => {
877
+ if (nextResult.status === "error") {
878
+ thenable.reject(nextResult.error);
879
+ } else if (nextResult.data !== void 0) {
880
+ thenable.resolve(nextResult.data);
881
+ }
882
+ };
883
+ const recreateThenable = () => {
884
+ const pending = __privateSet(this, _currentThenable, nextResult.promise = pendingThenable());
885
+ finalizeThenableIfPossible(pending);
886
+ };
887
+ const prevThenable = __privateGet(this, _currentThenable);
888
+ switch (prevThenable.status) {
889
+ case "pending":
890
+ if (query.queryHash === prevQuery.queryHash) {
891
+ finalizeThenableIfPossible(prevThenable);
892
+ }
893
+ break;
894
+ case "fulfilled":
895
+ if (nextResult.status === "error" || nextResult.data !== prevThenable.value) {
896
+ recreateThenable();
897
+ }
898
+ break;
899
+ case "rejected":
900
+ if (nextResult.status !== "error" || nextResult.error !== prevThenable.reason) {
901
+ recreateThenable();
902
+ }
903
+ break;
904
+ }
905
+ }
906
+ return nextResult;
824
907
  }
825
908
  updateResult(notifyOptions) {
826
909
  const prevResult = __privateGet(this, _currentResult);
@@ -867,7 +950,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
867
950
  __privateMethod(this, _QueryObserver_instances, updateTimers_fn).call(this);
868
951
  }
869
952
  }
870
- }, _client = new WeakMap(), _currentQuery = new WeakMap(), _currentQueryInitialState = new WeakMap(), _currentResult = new WeakMap(), _currentResultState = new WeakMap(), _currentResultOptions = new WeakMap(), _selectError = new WeakMap(), _selectFn = new WeakMap(), _selectResult = new WeakMap(), _lastQueryWithDefinedData = new WeakMap(), _staleTimeoutId = new WeakMap(), _refetchIntervalId = new WeakMap(), _currentRefetchInterval = new WeakMap(), _trackedProps = new WeakMap(), _QueryObserver_instances = new WeakSet(), executeFetch_fn = function(fetchOptions) {
953
+ }, _client = new WeakMap(), _currentQuery = new WeakMap(), _currentQueryInitialState = new WeakMap(), _currentResult = new WeakMap(), _currentResultState = new WeakMap(), _currentResultOptions = new WeakMap(), _currentThenable = new WeakMap(), _selectError = new WeakMap(), _selectFn = new WeakMap(), _selectResult = new WeakMap(), _lastQueryWithDefinedData = new WeakMap(), _staleTimeoutId = new WeakMap(), _refetchIntervalId = new WeakMap(), _currentRefetchInterval = new WeakMap(), _trackedProps = new WeakMap(), _QueryObserver_instances = new WeakSet(), executeFetch_fn = function(fetchOptions) {
871
954
  __privateMethod(this, _QueryObserver_instances, updateQuery_fn).call(this);
872
955
  let promise = __privateGet(this, _currentQuery).fetch(
873
956
  this.options,
@@ -1123,7 +1206,7 @@ function noop2() {
1123
1206
 
1124
1207
  // ../../node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js
1125
1208
  var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
1126
- if (options.suspense || options.throwOnError) {
1209
+ if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
1127
1210
  if (!errorResetBoundary.isReset()) {
1128
1211
  options.retryOnMount = false;
1129
1212
  }
@@ -1144,13 +1227,16 @@ var getHasError = ({
1144
1227
  };
1145
1228
 
1146
1229
  // ../../node_modules/@tanstack/react-query/build/modern/suspense.js
1147
- var ensureStaleTime = (defaultedOptions) => {
1230
+ var ensureSuspenseTimers = (defaultedOptions) => {
1231
+ const originalStaleTime = defaultedOptions.staleTime;
1148
1232
  if (defaultedOptions.suspense) {
1149
- if (typeof defaultedOptions.staleTime !== "number") {
1150
- defaultedOptions.staleTime = 1e3;
1233
+ defaultedOptions.staleTime = typeof originalStaleTime === "function" ? (...args) => Math.max(originalStaleTime(...args), 1e3) : Math.max(originalStaleTime ?? 1e3, 1e3);
1234
+ if (typeof defaultedOptions.gcTime === "number") {
1235
+ defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, 1e3);
1151
1236
  }
1152
1237
  }
1153
1238
  };
1239
+ var willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
1154
1240
  var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
1155
1241
  var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
1156
1242
  errorResetBoundary.clearReset();
@@ -1174,9 +1260,10 @@ function useBaseQuery(options, Observer, queryClient) {
1174
1260
  defaultedOptions
1175
1261
  );
1176
1262
  defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
1177
- ensureStaleTime(defaultedOptions);
1263
+ ensureSuspenseTimers(defaultedOptions);
1178
1264
  ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
1179
1265
  useClearResetErrorBoundary(errorResetBoundary);
1266
+ const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);
1180
1267
  const [observer] = React6.useState(
1181
1268
  () => new Observer(
1182
1269
  client,
@@ -1187,7 +1274,7 @@ function useBaseQuery(options, Observer, queryClient) {
1187
1274
  React6.useSyncExternalStore(
1188
1275
  React6.useCallback(
1189
1276
  (onStoreChange) => {
1190
- const unsubscribe = isRestoring ? () => void 0 : observer.subscribe(notifyManager.batchCalls(onStoreChange));
1277
+ const unsubscribe = isRestoring ? noop2 : observer.subscribe(notifyManager.batchCalls(onStoreChange));
1191
1278
  observer.updateResult();
1192
1279
  return unsubscribe;
1193
1280
  },
@@ -1215,6 +1302,18 @@ function useBaseQuery(options, Observer, queryClient) {
1215
1302
  defaultedOptions,
1216
1303
  result
1217
1304
  );
1305
+ if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) {
1306
+ const promise = isNewCacheEntry ? (
1307
+ // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
1308
+ fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
1309
+ ) : (
1310
+ // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
1311
+ client.getQueryCache().get(defaultedOptions.queryHash)?.promise
1312
+ );
1313
+ promise?.catch(noop2).finally(() => {
1314
+ observer.updateResult();
1315
+ });
1316
+ }
1218
1317
  return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
1219
1318
  }
1220
1319
 
@@ -1266,12 +1365,12 @@ var useSendTransaction = (mutationProps) => {
1266
1365
  if (!smartAccountClient) {
1267
1366
  throw new Error("No smart account found");
1268
1367
  }
1269
- const { transactions } = variables;
1270
- if (!Array.isArray(transactions)) {
1271
- return smartAccountClient.sendTransaction(transactions);
1368
+ const { calls } = variables;
1369
+ if (!Array.isArray(calls)) {
1370
+ return smartAccountClient.sendTransaction(calls);
1272
1371
  }
1273
- return smartAccountClient.sendTransactions({
1274
- transactions
1372
+ return smartAccountClient.sendTransaction({
1373
+ calls
1275
1374
  });
1276
1375
  },
1277
1376
  // Spread any additional mutation options provided
@@ -1328,78 +1427,6 @@ var useWriteContract = (mutationProps) => {
1328
1427
  };
1329
1428
  };
1330
1429
 
1331
- // src/hooks/sessionKeys/useSendTransactionWithSessionKey.ts
1332
- var useSendTransactionWithSessionKey = (mutationProps) => {
1333
- const { smartAccountClient, queryClient } = useSmartAccount();
1334
- const { mutate, mutateAsync, ...result } = useMutation(
1335
- {
1336
- mutationFn: (variables) => {
1337
- if (!smartAccountClient) {
1338
- throw new Error("No smart account found");
1339
- }
1340
- const { transactions } = variables;
1341
- if (!Array.isArray(transactions)) {
1342
- return smartAccountClient.sendTransactionWithSessionKey(
1343
- transactions
1344
- );
1345
- }
1346
- return smartAccountClient.sendTransactionsWithSessionKey({
1347
- transactions
1348
- });
1349
- },
1350
- ...mutationProps
1351
- },
1352
- queryClient
1353
- );
1354
- return {
1355
- data: result.data,
1356
- error: result.error,
1357
- isPending: result.isPending,
1358
- isSuccess: result.isSuccess,
1359
- isError: result.isError,
1360
- sendTransaction: mutate,
1361
- sendTransactionAsync: mutateAsync
1362
- };
1363
- };
1364
-
1365
- // src/hooks/sessionKeys/useWriteContractWithSessionKey.ts
1366
- import { encodeFunctionData as encodeFunctionData2 } from "viem";
1367
- var useWriteContractWithSessionKey = (mutationProps) => {
1368
- const { smartAccountClient, queryClient } = useSmartAccount();
1369
- const { mutate, mutateAsync, ...result } = useMutation(
1370
- {
1371
- mutationFn: async (variables) => {
1372
- if (!smartAccountClient) {
1373
- throw new Error("No smart account found");
1374
- }
1375
- const { abi, address, functionName, args, value } = variables;
1376
- const data = encodeFunctionData2({
1377
- abi,
1378
- functionName,
1379
- args
1380
- });
1381
- const hash = await smartAccountClient.sendTransactionWithSessionKey({
1382
- to: address,
1383
- data,
1384
- value
1385
- });
1386
- return hash;
1387
- },
1388
- ...mutationProps
1389
- },
1390
- queryClient
1391
- );
1392
- return {
1393
- data: result.data,
1394
- error: result.error,
1395
- isPending: result.isPending,
1396
- isSuccess: result.isSuccess,
1397
- isError: result.isError,
1398
- writeContractWithSessionKey: mutate,
1399
- writeContractWithSessionKeyAsync: mutateAsync
1400
- };
1401
- };
1402
-
1403
1430
  // src/hooks/useConnect.ts
1404
1431
  import { useCallback as useCallback4, useContext as useContext6, useState as useState5 } from "react";
1405
1432
  var useConnect = () => {
@@ -1584,161 +1611,6 @@ var useGetEnrichedOwners = (queryProps) => {
1584
1611
  );
1585
1612
  };
1586
1613
 
1587
- // src/hooks/sessionKeys/useSessionKeys.ts
1588
- var useAddSessionKey = (mutationProps) => {
1589
- const { smartAccountClient, queryClient } = useSmartAccount();
1590
- const { mutate, mutateAsync, ...result } = useMutation(
1591
- {
1592
- mutationFn: async (params) => {
1593
- if (!smartAccountClient) {
1594
- throw new Error("No smart account found");
1595
- }
1596
- return await smartAccountClient.addSessionKey(params);
1597
- },
1598
- ...mutationProps
1599
- },
1600
- queryClient
1601
- );
1602
- return {
1603
- data: result.data,
1604
- error: result.error,
1605
- isPending: result.isPending,
1606
- isSuccess: result.isSuccess,
1607
- isError: result.isError,
1608
- addSessionKey: mutate,
1609
- addSessionKeyAsync: mutateAsync
1610
- };
1611
- };
1612
- var useRevokeSessionKey = (mutationProps) => {
1613
- const { smartAccountClient, queryClient } = useSmartAccount();
1614
- const { mutate, mutateAsync, ...result } = useMutation(
1615
- {
1616
- mutationFn: async ({
1617
- sessionKey
1618
- }) => {
1619
- if (!smartAccountClient) {
1620
- throw new Error("No smart account found");
1621
- }
1622
- return await smartAccountClient.revokeSessionKey({
1623
- sessionKey
1624
- });
1625
- },
1626
- ...mutationProps
1627
- },
1628
- queryClient
1629
- );
1630
- return {
1631
- data: result.data,
1632
- error: result.error,
1633
- isPending: result.isPending,
1634
- isSuccess: result.isSuccess,
1635
- isError: result.isError,
1636
- revokeSessionKey: mutate,
1637
- revokeSessionKeyAsync: mutateAsync
1638
- };
1639
- };
1640
- var useAddWhitelistDestination = (mutationProps) => {
1641
- const { smartAccountClient, queryClient } = useSmartAccount();
1642
- const { mutate, mutateAsync, ...result } = useMutation(
1643
- {
1644
- mutationFn: async ({
1645
- sessionKey,
1646
- destination
1647
- }) => {
1648
- if (!smartAccountClient) {
1649
- throw new Error("No smart account found");
1650
- }
1651
- return await smartAccountClient.addWhitelistDestination({
1652
- sessionKey,
1653
- destination
1654
- });
1655
- },
1656
- ...mutationProps
1657
- },
1658
- queryClient
1659
- );
1660
- return {
1661
- data: result.data,
1662
- error: result.error,
1663
- isPending: result.isPending,
1664
- isSuccess: result.isSuccess,
1665
- isError: result.isError,
1666
- addWhitelistDestination: mutate,
1667
- addWhitelistDestinationAsync: mutateAsync
1668
- };
1669
- };
1670
- var useRemoveWhitelistDestination = (mutationProps) => {
1671
- const { smartAccountClient, queryClient } = useSmartAccount();
1672
- const { mutate, mutateAsync, ...result } = useMutation(
1673
- {
1674
- mutationFn: async ({
1675
- sessionKey,
1676
- destination
1677
- }) => {
1678
- if (!smartAccountClient) {
1679
- throw new Error("No smart account found");
1680
- }
1681
- return await smartAccountClient.removeWhitelistDestination({
1682
- sessionKey,
1683
- destination
1684
- });
1685
- },
1686
- ...mutationProps
1687
- },
1688
- queryClient
1689
- );
1690
- return {
1691
- data: result.data,
1692
- error: result.error,
1693
- isPending: result.isPending,
1694
- isSuccess: result.isSuccess,
1695
- isError: result.isError,
1696
- removeWhitelistDestination: mutate,
1697
- removeWhitelistDestinationAsync: mutateAsync
1698
- };
1699
- };
1700
- var useGetSessionFromAddress = (sessionKey, queryProps) => {
1701
- const { smartAccountClient, queryClient } = useSmartAccount();
1702
- return useQuery(
1703
- {
1704
- queryKey: ["getSessionFromAddress", sessionKey],
1705
- queryFn: async () => {
1706
- if (!smartAccountClient) {
1707
- throw new Error("No smart account found");
1708
- }
1709
- return await smartAccountClient.getSessionFromAddress({
1710
- sessionKey
1711
- });
1712
- },
1713
- ...queryProps
1714
- },
1715
- queryClient
1716
- );
1717
- };
1718
- var useIsAddressWhitelistDestination = (sessionKey, targetAddress, queryProps) => {
1719
- const { smartAccountClient, queryClient } = useSmartAccount();
1720
- return useQuery(
1721
- {
1722
- queryKey: [
1723
- "isAddressWhitelistDestination",
1724
- sessionKey,
1725
- targetAddress
1726
- ],
1727
- queryFn: async () => {
1728
- if (!smartAccountClient) {
1729
- throw new Error("No smart account found");
1730
- }
1731
- return await smartAccountClient.isAddressWhitelistDestination({
1732
- sessionKey,
1733
- targetAddress
1734
- });
1735
- },
1736
- ...queryProps
1737
- },
1738
- queryClient
1739
- );
1740
- };
1741
-
1742
1614
  // src/hooks/owners/useValidateAddDevice.ts
1743
1615
  var useValidateAddDevice = (mutationProps) => {
1744
1616
  const { smartAccountClient, queryClient } = useSmartAccount();
@@ -2091,10 +1963,8 @@ function useSetUpRecovery() {
2091
1963
  }
2092
1964
  return smartAccountClient.setUpRecoveryModule({
2093
1965
  passKeyName: variables.passKeyName,
2094
- rpcUrl: variables.rpcUrl,
2095
- webAuthnOptions: variables.webAuthnOptions,
2096
- // biome-ignore lint/suspicious/noExplicitAny: TODO: remove any
2097
- middleware: variables.middleware
1966
+ publicClient: variables.publicClient,
1967
+ webAuthnOptions: variables.webAuthnOptions
2098
1968
  });
2099
1969
  }
2100
1970
  },
@@ -2116,7 +1986,7 @@ function useIsRecoveryActive(props = {}) {
2116
1986
  const { smartAccountClient, queryClient } = useSmartAccount();
2117
1987
  return useQuery(
2118
1988
  {
2119
- queryKey: ["isRecoveryActive", props.rpcUrl],
1989
+ queryKey: ["isRecoveryActive", props.publicClient],
2120
1990
  queryFn: async () => {
2121
1991
  if (!smartAccountClient) {
2122
1992
  throw new Error("No smart account found");
@@ -2134,7 +2004,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
2134
2004
  const { smartAccountClient, queryClient } = useSmartAccount();
2135
2005
  const { data, isLoading, isError, error } = useQuery(
2136
2006
  {
2137
- queryKey: ["getRecoveryRequest", props.rpcUrl],
2007
+ queryKey: ["getRecoveryRequest", props.publicClient],
2138
2008
  queryFn: async () => {
2139
2009
  if (!smartAccountClient) {
2140
2010
  throw new Error("No smart account found");
@@ -2164,9 +2034,7 @@ function useCancelRecoveryRequest() {
2164
2034
  throw new Error("No smart account found");
2165
2035
  }
2166
2036
  return smartAccountClient.cancelRecoveryRequest({
2167
- rpcUrl: variables.rpcUrl,
2168
- // biome-ignore lint/suspicious/noExplicitAny: TODO: remove any
2169
- middleware: variables.middleware
2037
+ publicClient: variables.publicClient
2170
2038
  });
2171
2039
  }
2172
2040
  },
@@ -2267,6 +2135,10 @@ var useSwitchChain = () => {
2267
2135
  };
2268
2136
 
2269
2137
  // src/hooks/useGetTransactionCost.ts
2138
+ import { http as http3 } from "viem";
2139
+ import {
2140
+ createBundlerClient
2141
+ } from "viem/account-abstraction";
2270
2142
  var useGetTransactionCost = (mutationProps) => {
2271
2143
  const { smartAccountClient, queryClient } = useSmartAccount();
2272
2144
  const { mutate, mutateAsync, ...result } = useMutation(
@@ -2275,15 +2147,14 @@ var useGetTransactionCost = (mutationProps) => {
2275
2147
  if (!smartAccountClient) {
2276
2148
  throw new Error("No smart account found");
2277
2149
  }
2278
- const { transactions } = variables;
2279
- const userOperation = await smartAccountClient.account.buildUserOperation(
2280
- transactions
2281
- );
2282
- const estimateGas = await smartAccountClient.estimateGas({
2283
- userOperation
2150
+ const bundlerClient = createBundlerClient({
2151
+ account: smartAccountClient.account,
2152
+ client: smartAccountClient,
2153
+ transport: http3(smartAccountClient.transport.url)
2284
2154
  });
2155
+ const estimateGas = await bundlerClient.estimateUserOperationGas(variables);
2285
2156
  const totalGas = estimateGas.preVerificationGas + estimateGas.verificationGasLimit + estimateGas.callGasLimit;
2286
- return { totalGasCost: totalGas * estimateGas.maxFeePerGas };
2157
+ return { totalGasCost: totalGas };
2287
2158
  },
2288
2159
  ...mutationProps
2289
2160
  },
@@ -2301,6 +2172,12 @@ var useGetTransactionCost = (mutationProps) => {
2301
2172
  };
2302
2173
 
2303
2174
  // src/hooks/useEstimateGas.ts
2175
+ import { http as http4, createPublicClient as createPublicClient2 } from "viem";
2176
+ import {
2177
+ createBundlerClient as createBundlerClient2
2178
+ } from "viem/account-abstraction";
2179
+ import { estimateFeesPerGas } from "viem/actions";
2180
+ import { getAction } from "viem/utils";
2304
2181
  var useEstimateGas = (mutationProps) => {
2305
2182
  const { smartAccountClient, queryClient } = useSmartAccount();
2306
2183
  const { mutate, mutateAsync, ...result } = useMutation(
@@ -2309,14 +2186,37 @@ var useEstimateGas = (mutationProps) => {
2309
2186
  if (!smartAccountClient) {
2310
2187
  throw new Error("No smart account found");
2311
2188
  }
2312
- const { transactions } = variables;
2313
- const userOperation = await smartAccountClient.account.buildUserOperation(
2314
- transactions
2315
- );
2316
- const estimateGas = await smartAccountClient.estimateGas({
2317
- userOperation
2189
+ const publicClient = createPublicClient2({
2190
+ chain: smartAccountClient.chain,
2191
+ transport: http4(),
2192
+ cacheTime: 6e4,
2193
+ batch: {
2194
+ multicall: { wait: 50 }
2195
+ }
2196
+ });
2197
+ const maxGasPriceResult = await getAction(
2198
+ publicClient,
2199
+ estimateFeesPerGas,
2200
+ "estimateFeesPerGas"
2201
+ )({
2202
+ chain: smartAccountClient.chain,
2203
+ type: "eip1559"
2318
2204
  });
2319
- return estimateGas;
2205
+ const bundlerClient = createBundlerClient2({
2206
+ account: smartAccountClient.account,
2207
+ client: smartAccountClient,
2208
+ transport: http4(smartAccountClient.transport.url)
2209
+ });
2210
+ const estimateGas = await bundlerClient.estimateUserOperationGas(variables);
2211
+ return {
2212
+ callGasLimit: estimateGas.callGasLimit,
2213
+ verificationGasLimit: estimateGas.verificationGasLimit,
2214
+ preVerificationGas: estimateGas.preVerificationGas,
2215
+ paymasterVerificationGasLimit: estimateGas.paymasterVerificationGasLimit,
2216
+ paymasterPostOpGasLimit: estimateGas.paymasterPostOpGasLimit,
2217
+ maxFeePerGas: maxGasPriceResult.maxFeePerGas,
2218
+ maxPriorityFeePerGas: maxGasPriceResult.maxPriorityFeePerGas
2219
+ };
2320
2220
  },
2321
2221
  ...mutationProps
2322
2222
  },
@@ -2336,8 +2236,6 @@ export {
2336
2236
  ConnectProvider,
2337
2237
  useAccount,
2338
2238
  useAddOwner,
2339
- useAddSessionKey,
2340
- useAddWhitelistDestination,
2341
2239
  useCancelRecoveryRequest,
2342
2240
  useConnect,
2343
2241
  useCreateNewSigner,
@@ -2348,23 +2246,17 @@ export {
2348
2246
  useGetGasPrice,
2349
2247
  useGetOwners,
2350
2248
  useGetRecoveryRequest,
2351
- useGetSessionFromAddress,
2352
2249
  useGetTransactionCost,
2353
- useIsAddressWhitelistDestination,
2354
2250
  useIsRecoveryActive,
2355
2251
  useRemoveOwner,
2356
- useRemoveWhitelistDestination,
2357
2252
  useRetrieveAccountAddressFromPasskeyId,
2358
2253
  useRetrieveAccountAddressFromPasskeys,
2359
- useRevokeSessionKey,
2360
2254
  useSendTransaction,
2361
- useSendTransactionWithSessionKey,
2362
2255
  useSerializeUrlWithSignerPayload,
2363
2256
  useSetUpRecovery,
2364
2257
  useSignMessage,
2365
2258
  useSwitchChain,
2366
2259
  useValidateAddDevice,
2367
2260
  useVerifyMessage,
2368
- useWriteContract,
2369
- useWriteContractWithSessionKey
2261
+ useWriteContract
2370
2262
  };