@dynamic-labs/wagmi-connector 2.0.0-alpha.23 → 2.0.0-alpha.25

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,37 @@
1
1
 
2
+ ## [2.0.0-alpha.25](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.24...v2.0.0-alpha.25) (2024-04-04)
3
+
4
+
5
+ ### Features
6
+
7
+ * add in-app browser deeplink for metamask ([#5176](https://github.com/dynamic-labs/DynamicAuth/issues/5176)) ([02ce607](https://github.com/dynamic-labs/DynamicAuth/commit/02ce6077ed0deeaefc7a62ee91ff72f5bce2b327)), closes [#5123](https://github.com/dynamic-labs/DynamicAuth/issues/5123)
8
+
9
+ ## [2.0.0-alpha.24](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2024-04-03)
10
+
11
+
12
+ ### ⚠ BREAKING CHANGES
13
+
14
+ * rename otp verification callbacks (#5180)
15
+ * remove deprecated isVerificationInProgress flag and setter (#5089)
16
+
17
+ ### Features
18
+
19
+ * allow creating embedded wallets even if user signs in with a wallet ([#5093](https://github.com/dynamic-labs/DynamicAuth/issues/5093)) ([ba2dd62](https://github.com/dynamic-labs/DynamicAuth/commit/ba2dd625e0a7bf35018cf8aac8e80bd23b4e3b0f))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * api unit test by removing api and sdk versions for assertion ([#5168](https://github.com/dynamic-labs/DynamicAuth/issues/5168)) ([6d3b8ad](https://github.com/dynamic-labs/DynamicAuth/commit/6d3b8adebe62a4f2a7878630384348b2c491d779))
25
+ * bug when phone input is empty ([#5139](https://github.com/dynamic-labs/DynamicAuth/issues/5139)) ([7155b63](https://github.com/dynamic-labs/DynamicAuth/commit/7155b63518d00ba807bc321c6740b341d0a8b82f))
26
+ * clear error message on otp resend for sms ([#5182](https://github.com/dynamic-labs/DynamicAuth/issues/5182)) ([f40b48c](https://github.com/dynamic-labs/DynamicAuth/commit/f40b48c7f58c8e3dfe73fb124d642c3b8f193cee))
27
+ * link farcaster account ([#5170](https://github.com/dynamic-labs/DynamicAuth/issues/5170)) ([10fe272](https://github.com/dynamic-labs/DynamicAuth/commit/10fe272247605b5f09385f063231e2c881399cc8))
28
+ * show correct otp message for sms verification failure ([#5177](https://github.com/dynamic-labs/DynamicAuth/issues/5177)) ([b3bcd76](https://github.com/dynamic-labs/DynamicAuth/commit/b3bcd7694047dac55ce37babb71684a418633f95))
29
+ * update wagmi connector id when wallet connector changes ([#5185](https://github.com/dynamic-labs/DynamicAuth/issues/5185)) ([14fb83a](https://github.com/dynamic-labs/DynamicAuth/commit/14fb83a22c8e39095b79cc9951cae3f00f4fca2f))
30
+
31
+
32
+ * remove deprecated isVerificationInProgress flag and setter ([#5089](https://github.com/dynamic-labs/DynamicAuth/issues/5089)) ([060fef7](https://github.com/dynamic-labs/DynamicAuth/commit/060fef70df0c497e7a9b6e67ad0bfafef52c2bbb))
33
+ * rename otp verification callbacks ([#5180](https://github.com/dynamic-labs/DynamicAuth/issues/5180)) ([a580eec](https://github.com/dynamic-labs/DynamicAuth/commit/a580eec02d15b46a25c01d5473e4db2db89937e2))
34
+
2
35
  ## [2.0.0-alpha.23](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.22...v2.0.0-alpha.23) (2024-04-01)
3
36
 
4
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "2.0.0-alpha.23",
3
+ "version": "2.0.0-alpha.25",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -11,11 +11,11 @@
11
11
  "react": "^18.0.0",
12
12
  "viem": "2.7.6",
13
13
  "wagmi": "2.5.7",
14
- "@dynamic-labs/logger": "2.0.0-alpha.23",
15
- "@dynamic-labs/rpc-providers": "2.0.0-alpha.23",
16
- "@dynamic-labs/sdk-react-core": "2.0.0-alpha.23",
17
- "@dynamic-labs/types": "2.0.0-alpha.23",
18
- "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.23",
14
+ "@dynamic-labs/logger": "2.0.0-alpha.25",
15
+ "@dynamic-labs/rpc-providers": "2.0.0-alpha.25",
16
+ "@dynamic-labs/sdk-react-core": "2.0.0-alpha.25",
17
+ "@dynamic-labs/types": "2.0.0-alpha.25",
18
+ "@dynamic-labs/wallet-connector-core": "2.0.0-alpha.25",
19
19
  "eventemitter3": "5.0.1"
20
20
  },
21
21
  "license": "MIT",
@@ -1,8 +1,8 @@
1
1
  import { MutableRefObject } from 'react';
2
- import { Connector } from 'wagmi';
3
2
  import { Account, Transport, Chain } from 'viem';
4
- import { Wallet, WalletConnector } from '@dynamic-labs/sdk-react-core';
3
+ import { WalletConnector } from '@dynamic-labs/sdk-react-core';
5
4
  export type ConnectorParameters = {
5
+ connectorId: string;
6
6
  handleLogOut: () => Promise<void>;
7
7
  walletConnector: WalletConnector;
8
8
  preventWagmiSyncFromCallingLogout: MutableRefObject<boolean>;
@@ -58,8 +58,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
58
58
  [x: `address[${string}]`]: undefined;
59
59
  [x: `bool[${string}]`]: undefined;
60
60
  [x: `bytes[${string}]`]: undefined;
61
- [x: `bytes1[${string}]`]: undefined;
62
61
  [x: `bytes16[${string}]`]: undefined;
62
+ [x: `bytes1[${string}]`]: undefined;
63
63
  [x: `bytes2[${string}]`]: undefined;
64
64
  [x: `bytes3[${string}]`]: undefined;
65
65
  [x: `bytes4[${string}]`]: undefined;
@@ -160,8 +160,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
160
160
  address?: undefined;
161
161
  bool?: undefined;
162
162
  bytes?: undefined;
163
- bytes1?: undefined;
164
163
  bytes16?: undefined;
164
+ bytes1?: undefined;
165
165
  bytes2?: undefined;
166
166
  bytes3?: undefined;
167
167
  bytes4?: undefined;
@@ -336,8 +336,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
336
336
  [x: `address[${string}]`]: undefined;
337
337
  [x: `bool[${string}]`]: undefined;
338
338
  [x: `bytes[${string}]`]: undefined;
339
- [x: `bytes1[${string}]`]: undefined;
340
339
  [x: `bytes16[${string}]`]: undefined;
340
+ [x: `bytes1[${string}]`]: undefined;
341
341
  [x: `bytes2[${string}]`]: undefined;
342
342
  [x: `bytes3[${string}]`]: undefined;
343
343
  [x: `bytes4[${string}]`]: undefined;
@@ -438,8 +438,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
438
438
  address?: undefined;
439
439
  bool?: undefined;
440
440
  bytes?: undefined;
441
- bytes1?: undefined;
442
441
  bytes16?: undefined;
442
+ bytes1?: undefined;
443
443
  bytes2?: undefined;
444
444
  bytes3?: undefined;
445
445
  bytes4?: undefined;
@@ -618,8 +618,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
618
618
  [x: `address[${string}]`]: undefined;
619
619
  [x: `bool[${string}]`]: undefined;
620
620
  [x: `bytes[${string}]`]: undefined;
621
- [x: `bytes1[${string}]`]: undefined;
622
621
  [x: `bytes16[${string}]`]: undefined;
622
+ [x: `bytes1[${string}]`]: undefined;
623
623
  [x: `bytes2[${string}]`]: undefined;
624
624
  [x: `bytes3[${string}]`]: undefined;
625
625
  [x: `bytes4[${string}]`]: undefined;
@@ -720,8 +720,8 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
720
720
  address?: undefined;
721
721
  bool?: undefined;
722
722
  bytes?: undefined;
723
- bytes1?: undefined;
724
723
  bytes16?: undefined;
724
+ bytes1?: undefined;
725
725
  bytes2?: undefined;
726
726
  bytes3?: undefined;
727
727
  bytes4?: undefined;
@@ -835,7 +835,7 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
835
835
  uid?: undefined;
836
836
  } & Partial<Pick<import("viem").PublicActions<Transport, Chain, Account>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<Chain, Account>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, import("viem").WalletActions<Chain, Account>>) => client) => import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<Chain, Account>>;
837
837
  }>;
838
- id: `dynamic-${string}`;
838
+ id: string;
839
839
  isAuthorized: () => Promise<boolean>;
840
840
  name: "Dynamic";
841
841
  onAccountsChanged: (accounts: string[]) => void;
@@ -846,4 +846,3 @@ export declare const getCreateConnectorFn: (parameters: ConnectorParameters) =>
846
846
  }) => Promise<Chain>;
847
847
  type: "dynamic";
848
848
  }, {}>;
849
- export declare const createConnectorForFirstConnectedEvmWallet: (wallets: Wallet[], createConnector: (wallet: Wallet) => Connector) => Connector | undefined;
@@ -82,7 +82,7 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
82
82
  return (_a = parameters.walletConnector) === null || _a === void 0 ? void 0 : _a.getWalletClient();
83
83
  });
84
84
  },
85
- id: `dynamic-${parameters.walletConnector.key}`,
85
+ id: parameters.connectorId,
86
86
  isAuthorized() {
87
87
  var _a, _b;
88
88
  return __awaiter(this, void 0, void 0, function* () {
@@ -117,12 +117,5 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
117
117
  },
118
118
  type: 'dynamic',
119
119
  }));
120
- const createConnectorForFirstConnectedEvmWallet = (wallets, createConnector) => {
121
- for (const wallet of wallets) {
122
- if (wallet.connected && wallet.connector.connectedChain === 'EVM') {
123
- return createConnector(wallet);
124
- }
125
- }
126
- };
127
120
 
128
- export { createConnectorForFirstConnectedEvmWallet, getCreateConnectorFn };
121
+ export { getCreateConnectorFn };
@@ -2,31 +2,36 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { useRef, useMemo, useEffect } from 'react';
3
3
  import { useConfig } from 'wagmi';
4
4
  import { useDynamicContext, useUserWallets } from '@dynamic-labs/sdk-react-core';
5
- import { findAndOrderEvmWallets } from './utils/findAndOrderEvmWallets/findAndOrderEvmWallets.js';
6
- import { createConnectorForFirstConnectedEvmWallet, getCreateConnectorFn } from './Connector.js';
5
+ import { getCreateConnectorFn } from './Connector.js';
7
6
  import { SyncDynamicWagmi } from './SyncDynamicWagmi.js';
8
7
  import { useChainMismatchLogger } from './useChainMismatchLogger.js';
8
+ import { useFindEvmWallet } from './hooks/useFindEvmWallet/useFindEvmWallet.js';
9
+ import { useConnectorId } from './hooks/useConnectorId/useConnectorId.js';
9
10
 
10
11
  const DynamicWagmiConnector = ({ children, }) => {
11
12
  const config = useConfig();
12
13
  const { handleLogOut, primaryWallet } = useDynamicContext();
14
+ const wallets = useUserWallets();
13
15
  useChainMismatchLogger();
16
+ const evmWallet = useFindEvmWallet(primaryWallet, wallets);
17
+ const getConnectorId = useConnectorId();
14
18
  /**
15
19
  * This will prevent the wagmi Connector from calling handleLogOut when we are the ones calling disconnect
16
20
  * as a result of a handleLogOut call (see SyncDynamicWagmi), but will preserve the existing behavior for customers.
17
21
  */
18
22
  const preventWagmiSyncFromCallingLogout = useRef(false);
19
- // Sort places the primary wallet as the first wallet to attempt to connect with
20
- const wallets = useUserWallets().sort((wallet) => wallet.address === (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address) ? -1 : 1);
21
- const evmWallets = useMemo(() => findAndOrderEvmWallets(primaryWallet, wallets), [primaryWallet, wallets]);
22
- const connector = useMemo(() => createConnectorForFirstConnectedEvmWallet(evmWallets, (wallet) => {
23
- const connector = config._internal.connectors.setup(getCreateConnectorFn({
23
+ const connector = useMemo(() => {
24
+ if (!evmWallet) {
25
+ return;
26
+ }
27
+ const connectorId = getConnectorId(evmWallet.connector);
28
+ return config._internal.connectors.setup(getCreateConnectorFn({
29
+ connectorId,
24
30
  handleLogOut,
25
31
  preventWagmiSyncFromCallingLogout,
26
- walletConnector: wallet.connector,
32
+ walletConnector: evmWallet.connector,
27
33
  }));
28
- return connector;
29
- }), [config._internal.connectors, evmWallets, handleLogOut]);
34
+ }, [config._internal.connectors, getConnectorId, handleLogOut, evmWallet]);
30
35
  /**
31
36
  * Updating the wagmi config must be done in a useEffect because
32
37
  * when setting the public client and connectors, wagmi will fire
@@ -0,0 +1 @@
1
+ export { useConnectorId } from './useConnectorId';
@@ -0,0 +1,7 @@
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ /**
3
+ * This hook is used to generate a unique ID for a given WalletConnector.
4
+ * This is used to ensure the wagmi connector id will change if the wallet connector
5
+ * instance changes between rerenders.
6
+ */
7
+ export declare const useConnectorId: () => (walletConnector: WalletConnector) => string;
@@ -0,0 +1,23 @@
1
+ import { useRef, useCallback } from 'react';
2
+
3
+ /**
4
+ * This hook is used to generate a unique ID for a given WalletConnector.
5
+ * This is used to ensure the wagmi connector id will change if the wallet connector
6
+ * instance changes between rerenders.
7
+ */
8
+ const useConnectorId = () => {
9
+ const lastSeenWalletConnector = useRef(undefined);
10
+ const lastConnectorKey = useRef(0);
11
+ /**
12
+ * This function will generate a unique ID for a given WalletConnector.
13
+ */
14
+ return useCallback((walletConnector) => {
15
+ if (walletConnector !== lastSeenWalletConnector.current) {
16
+ lastSeenWalletConnector.current = walletConnector;
17
+ lastConnectorKey.current += 1;
18
+ }
19
+ return `dynamic-${walletConnector.key}-${lastConnectorKey.current}`;
20
+ }, []);
21
+ };
22
+
23
+ export { useConnectorId };
@@ -0,0 +1 @@
1
+ export { useFindEvmWallet } from './useFindEvmWallet';
@@ -0,0 +1,2 @@
1
+ import { Wallet } from '@dynamic-labs/sdk-react-core';
2
+ export declare const useFindEvmWallet: (primaryWallet: Wallet | null, wallets: Wallet[]) => Wallet | undefined;
@@ -0,0 +1,21 @@
1
+ const isEvmWallet = (wallet) => wallet.connector.connectedChain === 'EVM';
2
+ const isWalletConnected = (wallet) => wallet.connected;
3
+ const useFindEvmWallet = (primaryWallet, wallets) => {
4
+ /**
5
+ * If the primary wallet is an EVM wallet and is connected, return it.
6
+ */
7
+ if (primaryWallet &&
8
+ isEvmWallet(primaryWallet) &&
9
+ isWalletConnected(primaryWallet)) {
10
+ return primaryWallet;
11
+ }
12
+ /**
13
+ * If the primary wallet is not connected, find the first connected EVM wallet.
14
+ */
15
+ const connectedEvmWallets = wallets
16
+ .filter(isEvmWallet)
17
+ .filter(isWalletConnected);
18
+ return connectedEvmWallets[0];
19
+ };
20
+
21
+ export { useFindEvmWallet };
@@ -1,2 +0,0 @@
1
- import { Wallet } from '@dynamic-labs/sdk-react-core';
2
- export declare const findAndOrderEvmWallets: (primaryWallet: Wallet | null, wallets: Wallet[]) => Wallet[];
@@ -1,13 +0,0 @@
1
- const evmWalletsFilter = (wallet) => wallet.connector.connectedChain === 'EVM';
2
- const findAndOrderEvmWallets = (primaryWallet, wallets) => {
3
- const isPrimaryWalletEvm = (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.connectedChain) === 'EVM';
4
- if (isPrimaryWalletEvm) {
5
- const secondaryEvmWallets = wallets
6
- .filter(evmWalletsFilter)
7
- .filter((wallet) => wallet.address !== primaryWallet.address);
8
- return [primaryWallet, ...secondaryEvmWallets];
9
- }
10
- return wallets.filter(evmWalletsFilter);
11
- };
12
-
13
- export { findAndOrderEvmWallets };
@@ -1 +0,0 @@
1
- export { findAndOrderEvmWallets } from './findAndOrderEvmWallets';
@@ -1 +0,0 @@
1
- export * from './findAndOrderEvmWallets';