@edgeandnode/graph-auth-kit 0.4.2 → 0.4.3-feat-useGraphAuthKitAccountEffect-hook-1723603598026-07ebb8b825ae109ee0ed9d2795fdd44ebe4deafc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -230,6 +230,11 @@ export function Layout({ children }: Readonly<{ children: ReactNode }>) {
230
230
 
231
231
  - `useGraphAuthKitAccount` -> This is an override of the [wagmi useAccount hook](https://wagmi.sh/react/api/hooks/useAccount). The reason is, if the user connects with a multisig, the wagmi context is connected with the user-selected EoA, so all of the wagmi context hooks reference this EoA and not the Safe. This returns the wagmi `UseAccountReturnType` but the `address` and `addresses` values include the entered Safe address. It also adds an `eoa` property that is the connected EoA address.
232
232
  - `useGraphAuthKitConnector` -> The user selected wallet/connector option.
233
+ - `useClientToEthersSigner` -> Returns the ethers@5.x.x JsonRpcSigner or SafeEthersSigner if the user is connected via a multisig
234
+ - `useAuthAccount` -> similar to the `useGraphAuthKitAccount` but requires the user to be authenticated and throws an error if not
235
+ - `useGraphAuthKitAccountEffect` -> Override of the [wagmi useAccountEffect hook](https://wagmi.sh/react/api/hooks/useAccountEffect) that listens to account changes and the `_enteredMultisigInfo` on the inner context instance. If the account data changes, emits a `onConnect` or `onDisconnect` event, but in the `onConnect` also checks the `useGraphAuthKitInnerContext()._enteredMultisigInfo` value and if the user has connected via a multisig, returns the mutlsig as the `address` value and the connected EoA as the `eoa` value.
236
+ - `useGraphAuthKitWalletClient` -> Override of the [wagmi useWalletClient hook](https://wagmi.sh/react/api/hooks/useWalletClient) that returns the extended Safe viem actions if the user is connected to a multisig.
237
+ - `useGraphAuthKitWriteContract` -> Override of the [wagmi useWriteContract hook](https://wagmi.sh/react/api/hooks/useWriteContract) that creates the transaction on the Safe if the user is connected via multisig; otherwise, returns the `useWriteContract` mutation hook.
233
238
 
234
239
  ## Components
235
240
 
package/dist/hooks.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { type Compute } from '@wagmi/core/internal';
1
2
  import { type providers } from 'ethers';
2
3
  import { type Address, type Chain } from 'viem';
3
- import { type Config, type Connector, type ResolvedRegister, type UseAccountReturnType, type UseWalletClientReturnType, type UseWriteContractParameters, type UseWriteContractReturnType } from 'wagmi';
4
+ import { type Config, type Connector, type ResolvedRegister, type UseAccountReturnType, type UseConfigParameters, type UseWalletClientReturnType, type UseWriteContractParameters, type UseWriteContractReturnType } from 'wagmi';
4
5
  import { SafeEthersSigner } from './safe/SafeEthersSigner';
5
6
  import { GraphAuthKitConnector } from './types';
6
7
  /**
@@ -45,6 +46,23 @@ export type UseAuthAccountReturnType<config extends Config = Config, chain = Con
45
46
  * preventing checks if the `address` is null further down the tree.
46
47
  */
47
48
  export declare function useAuthAccount(): UseAuthAccountReturnType;
49
+ export type UseGraphAuthKitAccountEffectArgs = Compute<{
50
+ onConnect?(data: Compute<Pick<Extract<UseGraphAuthKitAccountReturnType, {
51
+ status: 'connected';
52
+ }>, 'address' | 'addresses' | 'chain' | 'chainId' | 'connector' | 'eoa'> & {
53
+ isReconnected: boolean;
54
+ }>): void;
55
+ onDisconnect?(): void;
56
+ } & UseConfigParameters>;
57
+ /**
58
+ * Override hook of the wagmi `useAccountEffect` that listens to changes derived from the `useGraphAuthKitAccount` hook.
59
+ * Listening to the `useAccountEffect` hook does not work when the user connects via a multisig in the graph-auth-kit
60
+ * as the connected account is the EoA and not the Safe address.
61
+ * This hooks listens on account changes, but checks if the user has connected through a multisig.
62
+ *
63
+ * @see https://wagmi.sh/react/api/hooks/useAccountEffect
64
+ */
65
+ export declare function useGraphAuthKitAccountEffect(args?: UseGraphAuthKitAccountEffectArgs): void;
48
66
  /**
49
67
  * Override hook of wagmi `useWalletClient`.
50
68
  * The GraphAuthKit lets users connect to a Safe by entering the Safe information in,
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE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B,CAAC,MAAM,EAAE,OAAO,CAAC,CA8B7C"}
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ import { k, A, p, B, D, s, g, h, L, e, M, R, r, a, S, l, q, j, m, o, f, n, d, i
6
6
  import { u as useGraphAuthKitInnerContext, b as clientToProvider } from "./GraphAuthKit.context-DzwGnUfB.js";
7
7
  import { a as a2, f as f2, c, k as k2, g as g2, i as i2, h as h2, j as j2, e as e2 } from "./GraphAuthKit.context-DzwGnUfB.js";
8
8
  import { useMutation } from "@tanstack/react-query";
9
- import { useMemo } from "react";
9
+ import { watchAccount } from "@wagmi/core";
10
+ import { useMemo, useEffect } from "react";
10
11
  import { encodeFunctionData, getAddress } from "viem";
11
- import { useChainId, useConnectorClient, useAccount, useWalletClient, useConfig, useSwitchChain } from "wagmi";
12
+ import { useChainId, useConnectorClient, useAccount, useConfig, useWalletClient, useSwitchChain } from "wagmi";
12
13
  import { writeContractMutationOptions } from "wagmi/query";
13
14
  import { VoidSigner } from "@ethersproject/abstract-signer";
14
15
  import { OperationType } from "@safe-global/safe-core-sdk-types";
@@ -387,6 +388,43 @@ function useAuthAccount() {
387
388
  eoa: auth.eoa
388
389
  };
389
390
  }
391
+ function useGraphAuthKitAccountEffect(args = {}) {
392
+ const { onConnect, onDisconnect } = args;
393
+ const config = useConfig(args);
394
+ const { _enteredMultisigInfo } = useGraphAuthKitInnerContext();
395
+ useEffect(() => {
396
+ return watchAccount(config, {
397
+ onChange(account, prevAccount) {
398
+ if ((prevAccount.status === "reconnecting" || prevAccount.status === "connecting" && prevAccount.address === void 0) && account.status === "connected" || account.status === "connected" && (_enteredMultisigInfo == null ? void 0 : _enteredMultisigInfo.address) != null && _enteredMultisigInfo.address !== account.address) {
399
+ let { address, addresses, chain, chainId, connector } = account;
400
+ let eoa = void 0;
401
+ console.log("account status has changed.firing onConnect", _enteredMultisigInfo ?? {});
402
+ if (_enteredMultisigInfo != null) {
403
+ const [, ...rest] = addresses;
404
+ const multisigAddress = getAddress(_enteredMultisigInfo.address);
405
+ eoa = address;
406
+ address = multisigAddress;
407
+ addresses = [multisigAddress, eoa, ...rest];
408
+ }
409
+ const isReconnected = prevAccount.status === "reconnecting" || // if `previousAccount.status` is `undefined`, the connector connected immediately.
410
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
411
+ prevAccount.status === void 0;
412
+ onConnect == null ? void 0 : onConnect({
413
+ address,
414
+ addresses,
415
+ eoa,
416
+ chain,
417
+ chainId,
418
+ connector,
419
+ isReconnected
420
+ });
421
+ } else if (prevAccount.status === "connected" && account.status === "disconnected") {
422
+ onDisconnect == null ? void 0 : onDisconnect();
423
+ }
424
+ }
425
+ });
426
+ }, [config, _enteredMultisigInfo, onConnect, onDisconnect]);
427
+ }
390
428
  function useGraphAuthKitWalletClient() {
391
429
  const ctx = useGraphAuthKitInnerContext();
392
430
  const walletClient = useWalletClient();
@@ -518,6 +556,7 @@ export {
518
556
  useClientToEthersSigner,
519
557
  e2 as useGraphAuthKit,
520
558
  useGraphAuthKitAccount,
559
+ useGraphAuthKitAccountEffect,
521
560
  useGraphAuthKitConnector,
522
561
  useGraphAuthKitWalletClient,
523
562
  useGraphAuthKitWriteContract
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgeandnode/graph-auth-kit",
3
- "version": "0.4.2",
3
+ "version": "0.4.3-feat-useGraphAuthKitAccountEffect-hook-1723603598026-07ebb8b825ae109ee0ed9d2795fdd44ebe4deafc",
4
4
  "private": false,
5
5
  "description": "Wallet authentication connect kit in The Graph suite of applications",
6
6
  "author": "Edge & Node",
@@ -59,7 +59,6 @@
59
59
  "@types/react": "^18.3.3",
60
60
  "@types/react-dom": "^18.3.0",
61
61
  "@vitejs/plugin-react-swc": "^3.5.0",
62
- "@wagmi/core": "^2.13.4",
63
62
  "autoprefixer": "^10.4.19",
64
63
  "ethers": "5.7.2",
65
64
  "postcss": "^8.4.40",
@@ -69,12 +68,13 @@
69
68
  "ts-node": "^10.9.2",
70
69
  "viem": "2.19.3",
71
70
  "wagmi": "2.12.5",
72
- "@edgeandnode/gds": "^5.27.0",
73
71
  "@edgeandnode/common": "^6.18.0",
74
72
  "@edgeandnode/go": "^6.42.0",
73
+ "@edgeandnode/gds": "^5.27.0",
75
74
  "@edgeandnode/test-utils": "^2.0.0"
76
75
  },
77
76
  "dependencies": {
77
+ "@wagmi/core": "^2.13.4",
78
78
  "zod": "^3.23.8"
79
79
  },
80
80
  "scripts": {