@cometh/connect-react-hooks 0.1.0-dev.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -83,7 +83,8 @@ var ConnectContext = _react.createContext.call(void 0, {
83
83
  },
84
84
  disconnectSmartAccount: async () => {
85
85
  },
86
- networksConfig: void 0
86
+ networksConfig: void 0,
87
+ apikey: void 0
87
88
  });
88
89
  var ConnectProvider = ({
89
90
  children,
@@ -101,9 +102,9 @@ var ConnectProvider = ({
101
102
  const paymasterUrl = _optionalChain([config, 'access', _8 => _8.networksConfig, 'access', _9 => _9.find, 'call', _10 => _10(
102
103
  (network) => _optionalChain([network, 'access', _11 => _11.chain, 'optionalAccess', _12 => _12.id]) === chain.id
103
104
  ), 'optionalAccess', _13 => _13.paymasterUrl]);
104
- const rpcUrl = _optionalChain([config, 'access', _14 => _14.networksConfig, 'access', _15 => _15.find, 'call', _16 => _16(
105
+ const publicClient = _optionalChain([config, 'access', _14 => _14.networksConfig, 'access', _15 => _15.find, 'call', _16 => _16(
105
106
  (network) => _optionalChain([network, 'access', _17 => _17.chain, 'optionalAccess', _18 => _18.id]) === chain.id
106
- ), 'optionalAccess', _19 => _19.rpcUrl]);
107
+ ), 'optionalAccess', _19 => _19.publicClient]);
107
108
  if (!bundlerUrl) throw new Error("Bundler url not found");
108
109
  try {
109
110
  const { client, address: newAddress } = await createSmartAccount({
@@ -111,7 +112,7 @@ var ConnectProvider = ({
111
112
  chain,
112
113
  bundlerUrl,
113
114
  paymasterUrl,
114
- rpcUrl,
115
+ publicClient,
115
116
  smartAccountAddress: params.address,
116
117
  comethSignerConfig: {
117
118
  ...config.comethSignerConfig,
@@ -144,7 +145,8 @@ var ConnectProvider = ({
144
145
  smartAccountAddress,
145
146
  updateSmartAccountClient,
146
147
  disconnectSmartAccount,
147
- networksConfig: config.networksConfig
148
+ networksConfig: config.networksConfig,
149
+ apikey: config.apiKey
148
150
  }),
149
151
  [
150
152
  queryClient,
@@ -1271,14 +1273,15 @@ function useBaseQuery(options, Observer, queryClient) {
1271
1273
  )
1272
1274
  );
1273
1275
  const result = observer.getOptimisticResult(defaultedOptions);
1276
+ const shouldSubscribe = !isRestoring && options.subscribed !== false;
1274
1277
  React6.useSyncExternalStore(
1275
1278
  React6.useCallback(
1276
1279
  (onStoreChange) => {
1277
- const unsubscribe = isRestoring ? noop2 : observer.subscribe(notifyManager.batchCalls(onStoreChange));
1280
+ const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop2;
1278
1281
  observer.updateResult();
1279
1282
  return unsubscribe;
1280
1283
  },
1281
- [observer, isRestoring]
1284
+ [observer, shouldSubscribe]
1282
1285
  ),
1283
1286
  () => observer.getCurrentResult(),
1284
1287
  () => observer.getCurrentResult()
@@ -1530,9 +1533,7 @@ var useAddOwner = (mutationProps) => {
1530
1533
  const { smartAccountClient, queryClient } = useSmartAccount();
1531
1534
  const { mutate, mutateAsync, ...result } = useMutation(
1532
1535
  {
1533
- mutationFn: async ({
1534
- ownerToAdd
1535
- }) => {
1536
+ mutationFn: async ({ ownerToAdd }) => {
1536
1537
  if (!smartAccountClient) {
1537
1538
  throw new Error("No smart account found");
1538
1539
  }
@@ -1957,15 +1958,11 @@ function useSetUpRecovery() {
1957
1958
  const { smartAccountClient, queryClient } = useSmartAccount();
1958
1959
  const { mutate, mutateAsync, ...result } = useMutation(
1959
1960
  {
1960
- mutationFn: async (variables) => {
1961
+ mutationFn: async () => {
1961
1962
  if (!smartAccountClient) {
1962
1963
  throw new Error("No smart account found");
1963
1964
  }
1964
- return smartAccountClient.setUpRecoveryModule({
1965
- passKeyName: variables.passKeyName,
1966
- publicClient: variables.publicClient,
1967
- webAuthnOptions: variables.webAuthnOptions
1968
- });
1965
+ return smartAccountClient.setUpRecoveryModule();
1969
1966
  }
1970
1967
  },
1971
1968
  queryClient
@@ -1986,7 +1983,7 @@ function useIsRecoveryActive(props = {}) {
1986
1983
  const { smartAccountClient, queryClient } = useSmartAccount();
1987
1984
  return useQuery(
1988
1985
  {
1989
- queryKey: ["isRecoveryActive", props.publicClient],
1986
+ queryKey: ["isRecoveryActive"],
1990
1987
  queryFn: async () => {
1991
1988
  if (!smartAccountClient) {
1992
1989
  throw new Error("No smart account found");
@@ -2004,7 +2001,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
2004
2001
  const { smartAccountClient, queryClient } = useSmartAccount();
2005
2002
  const { data, isLoading, isError, error } = useQuery(
2006
2003
  {
2007
- queryKey: ["getRecoveryRequest", props.publicClient],
2004
+ queryKey: ["getRecoveryRequest"],
2008
2005
  queryFn: async () => {
2009
2006
  if (!smartAccountClient) {
2010
2007
  throw new Error("No smart account found");
@@ -2034,7 +2031,7 @@ function useCancelRecoveryRequest() {
2034
2031
  throw new Error("No smart account found");
2035
2032
  }
2036
2033
  return smartAccountClient.cancelRecoveryRequest({
2037
- publicClient: variables.publicClient
2034
+ effectiveDelayAddress: variables.effectiveDelayAddress
2038
2035
  });
2039
2036
  }
2040
2037
  },
@@ -2077,13 +2074,14 @@ var useSwitchChain = () => {
2077
2074
  if (!selectedNetwork)
2078
2075
  throw new Error("No current configuration found");
2079
2076
  try {
2080
- await updateSmartAccountClient({
2077
+ const client = await updateSmartAccountClient({
2081
2078
  address: _optionalChain([smartAccountClient, 'optionalAccess', _103 => _103.account, 'access', _104 => _104.address]),
2082
2079
  chain: selectedNetwork.chain
2083
2080
  });
2084
2081
  _optionalChain([queryClient, 'optionalAccess', _105 => _105.invalidateQueries, 'call', _106 => _106({
2085
2082
  queryKey: ["switchChain"]
2086
2083
  })]);
2084
+ return client;
2087
2085
  } catch (e) {
2088
2086
  throw e instanceof Error ? e : new Error("An error occurred while switching chain");
2089
2087
  }
@@ -2099,7 +2097,7 @@ var useSwitchChain = () => {
2099
2097
  (params) => {
2100
2098
  setIsPending(true);
2101
2099
  setError(null);
2102
- switchChainInternal(params).catch((e) => {
2100
+ return switchChainInternal(params).catch((e) => {
2103
2101
  const err = e instanceof Error ? e : new Error(
2104
2102
  "An error occurred while switching chain"
2105
2103
  );
@@ -2115,7 +2113,8 @@ var useSwitchChain = () => {
2115
2113
  setIsPending(true);
2116
2114
  setError(null);
2117
2115
  try {
2118
- await switchChainInternal(params);
2116
+ const client = await switchChainInternal(params);
2117
+ return client;
2119
2118
  } catch (e) {
2120
2119
  const err = e instanceof Error ? e : new Error("An error occurred while switching chain");
2121
2120
  setError(err);
@@ -2233,6 +2232,193 @@ var useEstimateGas = (mutationProps) => {
2233
2232
  };
2234
2233
  };
2235
2234
 
2235
+ // src/hooks/session-key/useGrantPermission.ts
2236
+ var _query = require('wagmi/query');
2237
+
2238
+
2239
+
2240
+
2241
+ function useGrantPermission(mutationProps) {
2242
+ const { smartAccountClient } = useSmartAccount();
2243
+ const { mutate, mutateAsync, ...result } = _query.useMutation.call(void 0, {
2244
+ mutationKey: ["session-key-grant-permission", smartAccountClient],
2245
+ mutationFn: async (args) => {
2246
+ if (!smartAccountClient) throw new Error("No smart account found");
2247
+ const safe7559Account = smartAccountClient.extend(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
2248
+ const createSessionsResponse = await safe7559Account.grantPermission(
2249
+ args
2250
+ );
2251
+ const response = await safe7559Account.waitForUserOperationReceipt({
2252
+ hash: createSessionsResponse.userOpHash
2253
+ });
2254
+ return {
2255
+ txHash: response.receipt.transactionHash,
2256
+ createSessionsResponse
2257
+ };
2258
+ },
2259
+ ...mutationProps
2260
+ });
2261
+ return {
2262
+ data: result.data,
2263
+ error: result.error,
2264
+ isPending: result.isPending,
2265
+ isSuccess: result.isSuccess,
2266
+ isError: result.isError,
2267
+ grantPermission: mutate,
2268
+ grantPermissionAsync: mutateAsync
2269
+ };
2270
+ }
2271
+
2272
+ // src/hooks/session-key/useSendPermission.ts
2273
+
2274
+
2275
+
2276
+
2277
+ // src/hooks/session-key/useSessionKeySigner.ts
2278
+
2279
+
2280
+
2281
+
2282
+
2283
+
2284
+ var _accounts = require('viem/accounts');
2285
+ function useSessionKeySigner({
2286
+ sessionData,
2287
+ privateKey
2288
+ }) {
2289
+ const { smartAccountClient } = useSmartAccount();
2290
+ const query = _query.useQuery.call(void 0, {
2291
+ queryKey: ["session-key-signer", smartAccountClient],
2292
+ queryFn: async () => {
2293
+ if (!smartAccountClient) throw new Error("No smart account found");
2294
+ const safe7559Account = smartAccountClient.extend(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
2295
+ return _connectsdk4337.toSmartSessionsSigner.call(void 0, safe7559Account, {
2296
+ moduleData: {
2297
+ permissionIds: sessionData.permissionIds,
2298
+ action: sessionData.action,
2299
+ mode: "0x00",
2300
+ sessions: sessionData.sessions
2301
+ },
2302
+ signer: _accounts.privateKeyToAccount.call(void 0, privateKey)
2303
+ });
2304
+ },
2305
+ enabled: !!smartAccountClient
2306
+ });
2307
+ return query;
2308
+ }
2309
+
2310
+ // src/actions/createSessionSmartAccount.ts
2311
+
2312
+
2313
+
2314
+
2315
+
2316
+
2317
+ var createSessionSmartAccountClient = async (apiKey, smartAccountClient, sessionKeySigner) => {
2318
+ const sessionKeyAccount = await _connectsdk4337.createSafeSmartAccount.call(void 0, {
2319
+ apiKey,
2320
+ chain: smartAccountClient.chain,
2321
+ smartAccountAddress: smartAccountClient.account.address,
2322
+ smartSessionSigner: sessionKeySigner
2323
+ });
2324
+ const paymasterClient = smartAccountClient.paymaster;
2325
+ const bundlerUrl = smartAccountClient.transport.url;
2326
+ return _connectsdk4337.createSmartAccountClient.call(void 0, {
2327
+ account: sessionKeyAccount,
2328
+ chain: smartAccountClient.chain,
2329
+ bundlerTransport: _viem.http.call(void 0, bundlerUrl),
2330
+ paymaster: paymasterClient,
2331
+ userOperation: {
2332
+ estimateFeesPerGas: async () => {
2333
+ return await paymasterClient.getUserOperationGasPrice();
2334
+ }
2335
+ }
2336
+ }).extend(_connectsdk4337.smartSessionActions.call(void 0, ));
2337
+ };
2338
+
2339
+ // src/hooks/session-key/useSendPermission.ts
2340
+
2341
+ function useSendPermission({
2342
+ sessionData,
2343
+ privateKey,
2344
+ mutationProps
2345
+ }) {
2346
+ const context = _react.useContext.call(void 0, ConnectContext);
2347
+ if (context === void 0) {
2348
+ throw new Error("useSendPermission must be used within a ConnectProvider");
2349
+ }
2350
+ const { smartAccountClient } = useSmartAccount();
2351
+ const { data: sessionKeySigner } = useSessionKeySigner({
2352
+ sessionData,
2353
+ privateKey
2354
+ });
2355
+ const { mutate, mutateAsync, ...result } = _query.useMutation.call(void 0, {
2356
+ mutationKey: [
2357
+ "session-key-send-permission",
2358
+ sessionKeySigner,
2359
+ smartAccountClient
2360
+ ],
2361
+ mutationFn: async (args) => {
2362
+ if (!smartAccountClient) throw new Error("No smart account found");
2363
+ if (!sessionKeySigner) throw new Error("No signer found");
2364
+ if (!context.apikey) throw new Error("No apikey found");
2365
+ const sessionKeyClient = await createSessionSmartAccountClient(
2366
+ context.apikey,
2367
+ smartAccountClient,
2368
+ sessionKeySigner
2369
+ );
2370
+ const userOpHash = await sessionKeyClient.usePermission(args);
2371
+ const userOp = await sessionKeyClient.waitForUserOperationReceipt({
2372
+ hash: userOpHash
2373
+ });
2374
+ return userOp.receipt.transactionHash;
2375
+ },
2376
+ ...mutationProps
2377
+ });
2378
+ return {
2379
+ data: result.data,
2380
+ error: result.error,
2381
+ isPending: result.isPending,
2382
+ isSuccess: result.isSuccess,
2383
+ isError: result.isError,
2384
+ sendPermission: mutate,
2385
+ sendPermissionAsync: mutateAsync
2386
+ };
2387
+ }
2388
+
2389
+ // src/hooks/session-key/useSessionKeyClient.ts
2390
+
2391
+
2392
+
2393
+ function useSessionKeyClient({
2394
+ apiKey,
2395
+ sessionData,
2396
+ privateKey
2397
+ }) {
2398
+ const { smartAccountClient } = useSmartAccount();
2399
+ const { data: sessionKeySigner } = useSessionKeySigner({
2400
+ sessionData,
2401
+ privateKey
2402
+ });
2403
+ const query = _query.useQuery.call(void 0, {
2404
+ queryKey: ["session-key-get-client", sessionKeySigner, smartAccountClient],
2405
+ queryFn: async () => {
2406
+ if (!smartAccountClient) throw new Error("No smart account found");
2407
+ if (!sessionKeySigner) throw new Error("No signer found");
2408
+ return createSessionSmartAccountClient(
2409
+ apiKey,
2410
+ smartAccountClient,
2411
+ sessionKeySigner
2412
+ );
2413
+ }
2414
+ });
2415
+ return query;
2416
+ }
2417
+
2418
+
2419
+
2420
+
2421
+
2236
2422
 
2237
2423
 
2238
2424
 
@@ -2259,4 +2445,4 @@ var useEstimateGas = (mutationProps) => {
2259
2445
 
2260
2446
 
2261
2447
 
2262
- exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; 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.useGetTransactionCost = useGetTransactionCost; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useSendTransaction = useSendTransaction; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract;
2448
+ exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; 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.useGetTransactionCost = useGetTransactionCost; exports.useGrantPermission = useGrantPermission; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useSendPermission = useSendPermission; exports.useSendTransaction = useSendTransaction; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSessionKeyClient = useSessionKeyClient; exports.useSessionKeySigner = useSessionKeySigner; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract;