@dynamic-labs/wagmi-connector 0.18.4 → 0.18.6

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/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
1
 
2
+ ### [0.18.6](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.5...v0.18.6) (2023-08-21)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * detect when user closes oauth window when linking social account ([#3063](https://github.com/dynamic-labs/DynamicAuth/issues/3063)) ([1afa8f7](https://github.com/dynamic-labs/DynamicAuth/commit/1afa8f7b1c82759c90554fd4395d11779023f1ff))
8
+ * sync connected wallets with wagmi client ([#3072](https://github.com/dynamic-labs/DynamicAuth/issues/3072)) ([570c83d](https://github.com/dynamic-labs/DynamicAuth/commit/570c83dd426862a2151c9858824a34d6b5133588))
9
+
10
+ ### [0.18.5](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.4...v0.18.5) (2023-08-19)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * ensure social sign in embedded wallets sync correctly with wagmi ([ae8784d](https://github.com/dynamic-labs/DynamicAuth/commit/ae8784d1dff047b370e0ccafbcb8180fa64bb99b))
16
+
2
17
  ### [0.18.4](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.2...v0.18.4) (2023-08-17)
3
18
 
4
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -11,9 +11,9 @@
11
11
  "react": "^17.0.2 || ^18.0.0",
12
12
  "ethers": "5.7.2",
13
13
  "wagmi": "~0.12.13",
14
- "@dynamic-labs/sdk-react-core": "0.18.4",
15
- "@dynamic-labs/types": "0.18.4",
16
- "@dynamic-labs/wallet-connector-core": "0.18.4"
14
+ "@dynamic-labs/sdk-react-core": "0.18.6",
15
+ "@dynamic-labs/types": "0.18.6",
16
+ "eventemitter3": "5.0.1"
17
17
  },
18
18
  "license": "MIT",
19
19
  "main": "./src/index.cjs",
@@ -19,7 +19,8 @@ const client = createClient({
19
19
  let connector = undefined;
20
20
  const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
21
21
  var _a;
22
- const { networkConfigurations, handleLogOut, connectedWallets, sendWagmiSettings, } = useDynamicContext();
22
+ const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
23
+ const wallets = authMode === 'connect-only' ? connectedWallets : linkedWallets;
23
24
  sendWagmiSettings({
24
25
  dynamicWagmiSettings: customerSuppliedEvmNetworks,
25
26
  });
@@ -30,7 +31,7 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
30
31
  const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
31
32
  const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
32
33
  const { chains, provider } = configureChains(mappedChains, mappedProviders);
33
- connector = getConnector(connectedWallets, (wallet) => new Connector({
34
+ connector = getConnector(wallets, (wallet) => new Connector({
34
35
  chains,
35
36
  handleLogOut,
36
37
  walletConnector: wallet.connector,
@@ -1,29 +1,39 @@
1
- import React from 'react';
1
+ import React, { useRef, useEffect } from 'react';
2
2
  import { useClient, useConnect, useDisconnect } from 'wagmi';
3
3
  import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
4
- import { useSyncConnectState } from './hooks/useSyncConnectState/useSyncConnectState.js';
5
4
 
6
5
  const SyncDynamicWagmi = ({ children, connector, }) => {
7
6
  const { status: clientStatus } = useClient();
8
- const { walletConnector } = useDynamicContext();
9
- const { connect, status } = useConnect();
7
+ const { connect } = useConnect();
10
8
  const { disconnect } = useDisconnect();
11
- if (walletConnector) {
12
- // after connection is successful, re-setup event listeners after a short delay
13
- // so that they are not cleared by the teardown in useWalletEventListeners
14
- if (status === 'success') {
15
- setTimeout(() => {
16
- connector === null || connector === void 0 ? void 0 : connector.setupEventListeners();
17
- }, 100);
9
+ const { internalEvents, walletConnector } = useDynamicContext();
10
+ const lastConnectedConnectorId = useRef(undefined);
11
+ useEffect(() => {
12
+ const events = internalEvents.current;
13
+ const handleDisconnect = () => {
14
+ lastConnectedConnectorId.current = undefined;
15
+ disconnect();
16
+ };
17
+ events.on('clearPrimaryWallet', handleDisconnect);
18
+ return () => {
19
+ events.off('clearPrimaryWallet', handleDisconnect);
20
+ };
21
+ }, [disconnect, internalEvents]);
22
+ useEffect(() => {
23
+ if (walletConnector &&
24
+ connector &&
25
+ (connector === null || connector === void 0 ? void 0 : connector.id) !== lastConnectedConnectorId.current) {
26
+ lastConnectedConnectorId.current = connector.id;
27
+ connect({ connector });
18
28
  }
19
- }
20
- useSyncConnectState({
29
+ }, [
21
30
  clientStatus,
22
31
  connect,
23
32
  connector,
24
33
  disconnect,
34
+ lastConnectedConnectorId,
25
35
  walletConnector,
26
- });
36
+ ]);
27
37
  // use React.createElement to prevent bunding react/jsx-runtime,
28
38
  // which is not compatible when bundling apps using React 17
29
39
  return React.createElement(React.Fragment, null, children);
@@ -1,2 +0,0 @@
1
- export * from './useWalletConnectorEverPresent';
2
- export * from './useSyncConnectState';
@@ -1 +0,0 @@
1
- export { useSyncConnectState } from './useSyncConnectState';
@@ -1,19 +0,0 @@
1
- /**
2
- * This is used to track a previous value of a variable.
3
- *
4
- * Example:
5
- * const someHook = ({ value }) => {
6
- * const previousValue = usePrevious(value);
7
- * useEffect(() => {
8
- * if (previousValue !== value) {
9
- * // do something
10
- * }
11
- * }, [value, previousValue]);
12
- * }
13
- *
14
- * When someHook is rendered for the first time with value = true, previousValue will be undefined
15
- * so the condition will be true and the effect will run. When someHook is rendered again with
16
- * value = true, previousValue will have been set to true so the condition will be false and the
17
- * effect will not run.
18
- */
19
- export declare const usePrevious: <T>(value: T) => T | undefined;
@@ -1,29 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
-
3
- /**
4
- * This is used to track a previous value of a variable.
5
- *
6
- * Example:
7
- * const someHook = ({ value }) => {
8
- * const previousValue = usePrevious(value);
9
- * useEffect(() => {
10
- * if (previousValue !== value) {
11
- * // do something
12
- * }
13
- * }, [value, previousValue]);
14
- * }
15
- *
16
- * When someHook is rendered for the first time with value = true, previousValue will be undefined
17
- * so the condition will be true and the effect will run. When someHook is rendered again with
18
- * value = true, previousValue will have been set to true so the condition will be false and the
19
- * effect will not run.
20
- */
21
- const usePrevious = (value) => {
22
- const ref = useRef();
23
- useEffect(() => {
24
- ref.current = value;
25
- }, [value]);
26
- return ref.current;
27
- };
28
-
29
- export { usePrevious };
@@ -1,11 +0,0 @@
1
- import { Connector } from 'wagmi';
2
- import { ConnectArgs } from '@wagmi/core';
3
- import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
- export type SyncConnectStateHookProps = {
5
- clientStatus: 'connected' | 'connecting' | 'reconnecting' | 'disconnected';
6
- connect: (args?: Partial<ConnectArgs> | undefined) => void;
7
- connector: Connector | undefined;
8
- disconnect: () => void;
9
- walletConnector: WalletConnector | null;
10
- };
11
- export declare const useSyncConnectState: ({ walletConnector, disconnect, clientStatus, connect, connector, }: SyncConnectStateHookProps) => void;
@@ -1,28 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { useWalletConnectorEverPresent } from '../useWalletConnectorEverPresent/useWalletConnectorEverPresent.js';
3
- import { usePrevious } from './usePrevious.js';
4
-
5
- const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connect, connector, }) => {
6
- const wasWalletConnectEverPresent = useWalletConnectorEverPresent(walletConnector);
7
- const prevConnectorId = usePrevious(connector === null || connector === void 0 ? void 0 : connector.id);
8
- useEffect(() => {
9
- if (!walletConnector) {
10
- if (wasWalletConnectEverPresent) {
11
- disconnect();
12
- }
13
- }
14
- else if ((connector === null || connector === void 0 ? void 0 : connector.id) !== prevConnectorId) {
15
- connect({ connector });
16
- }
17
- }, [
18
- clientStatus,
19
- connect,
20
- connector,
21
- disconnect,
22
- prevConnectorId,
23
- walletConnector,
24
- wasWalletConnectEverPresent,
25
- ]);
26
- };
27
-
28
- export { useSyncConnectState };
@@ -1 +0,0 @@
1
- export { useWalletConnectorEverPresent } from './useWalletConnectorEverPresent';
@@ -1,2 +0,0 @@
1
- import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
- export declare const useWalletConnectorEverPresent: (walletConnector: WalletConnector | null) => boolean;
@@ -1,13 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- const useWalletConnectorEverPresent = (walletConnector) => {
4
- const [present, setPresent] = useState(false);
5
- useEffect(() => {
6
- if (walletConnector) {
7
- setPresent(true);
8
- }
9
- }, [walletConnector]);
10
- return present;
11
- };
12
-
13
- export { useWalletConnectorEverPresent };