@dynamic-labs/wagmi-connector 1.1.0-alpha.2 → 1.1.0-alpha.3

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
+ ## [1.1.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2023-12-19)
3
+
4
+
5
+ ### Features
6
+
7
+ * add Flow support in magic wallet connector ([#4158](https://github.com/dynamic-labs/DynamicAuth/issues/4158)) ([fbbaea7](https://github.com/dynamic-labs/DynamicAuth/commit/fbbaea76b36ceb693f6bd4f2404dfa1204e61492))
8
+ * add showDynamicUserProfile to DynamicContext ([#4214](https://github.com/dynamic-labs/DynamicAuth/issues/4214)) ([2aeb8e3](https://github.com/dynamic-labs/DynamicAuth/commit/2aeb8e3c45a3d9f87bd9196ea9b46927e02eb633))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add shortname to braveevm to allow for lookups by name as well as key ([#4213](https://github.com/dynamic-labs/DynamicAuth/issues/4213)) ([969b089](https://github.com/dynamic-labs/DynamicAuth/commit/969b089be516fb57fcdc941f908c078998eb4ec0))
14
+ * solflare connect ([#4215](https://github.com/dynamic-labs/DynamicAuth/issues/4215)) ([9a4164e](https://github.com/dynamic-labs/DynamicAuth/commit/9a4164e53198f33ef7201cd4e1eff745a09e9701))
15
+ * wagmi attempt to connect to primary wallet first ([#4206](https://github.com/dynamic-labs/DynamicAuth/issues/4206)) ([9e5fc8e](https://github.com/dynamic-labs/DynamicAuth/commit/9e5fc8ef026628935ac32d3bb0c22bda35057e5d))
16
+
2
17
  ## [1.1.0-alpha.2](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.1...v1.1.0-alpha.2) (2023-12-18)
3
18
 
4
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "1.1.0-alpha.2",
3
+ "version": "1.1.0-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -10,10 +10,10 @@
10
10
  "react": "^17.0.2 || ^18.0.0",
11
11
  "viem": "^1.19.13",
12
12
  "wagmi": "^1.4.12",
13
- "@dynamic-labs/rpc-providers": "1.1.0-alpha.2",
14
- "@dynamic-labs/sdk-react-core": "1.1.0-alpha.2",
15
- "@dynamic-labs/types": "1.1.0-alpha.2",
16
- "@dynamic-labs/wallet-connector-core": "1.1.0-alpha.2",
13
+ "@dynamic-labs/rpc-providers": "1.1.0-alpha.3",
14
+ "@dynamic-labs/sdk-react-core": "1.1.0-alpha.3",
15
+ "@dynamic-labs/types": "1.1.0-alpha.3",
16
+ "@dynamic-labs/wallet-connector-core": "1.1.0-alpha.3",
17
17
  "eventemitter3": "5.0.1"
18
18
  },
19
19
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- import React, { useRef, useEffect, useMemo } from 'react';
1
+ import React, { useRef, useMemo, useEffect } from 'react';
2
2
  import { configureChains, mainnet, createConfig, WagmiConfig } from 'wagmi';
3
3
  import { publicProvider } from 'wagmi/providers/public';
4
4
  import { useDynamicContext, useUserWallets } from '@dynamic-labs/sdk-react-core';
@@ -7,6 +7,7 @@ import { getConnector } from './getConnector.js';
7
7
  import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChains.js';
8
8
  import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.js';
9
9
  import { SyncDynamicWagmi } from './SyncDynamicWagmi.js';
10
+ import { findAndOrderEvmWallets } from './utils/findAndOrderEvmWallets/findAndOrderEvmWallets.js';
10
11
 
11
12
  const { publicClient } = configureChains([mainnet], [publicProvider()]);
12
13
  const config = createConfig({
@@ -14,13 +15,15 @@ const config = createConfig({
14
15
  publicClient,
15
16
  });
16
17
  const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
17
- const { networkConfigurations, handleLogOut, sendWagmiSettings } = useDynamicContext();
18
+ const { networkConfigurations, handleLogOut, sendWagmiSettings, primaryWallet, } = useDynamicContext();
18
19
  /**
19
20
  * This will prevent the wagmi Connector from calling handleLogOut when we are the ones calling disconnect
20
21
  * as a result of a handleLogOut call (see SyncDynamicWagmi), but will preserve the existing behavior for customers.
21
22
  */
22
23
  const preventWagmiSyncFromCallingLogout = useRef(false);
23
- const wallets = useUserWallets();
24
+ // Sort places the primary wallet as the first wallet to attempt to connect with
25
+ const wallets = useUserWallets().sort((wallet) => wallet.address === (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address) ? -1 : 1);
26
+ const evmWallets = useMemo(() => findAndOrderEvmWallets(primaryWallet, wallets), [primaryWallet, wallets]);
24
27
  useEffect(() => {
25
28
  // only send wagmi settings once, when the first time DynamicWagmiConnector renders
26
29
  sendWagmiSettings({
@@ -38,12 +41,12 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
38
41
  const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
39
42
  return configureChains(mappedChains, mappedProviders);
40
43
  }, [customerSuppliedEvmNetworks, networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm]);
41
- const connector = useMemo(() => getConnector(wallets, (wallet) => new Connector({
44
+ const connector = useMemo(() => getConnector(evmWallets, (wallet) => new Connector({
42
45
  chains,
43
46
  handleLogOut,
44
47
  preventWagmiSyncFromCallingLogout,
45
48
  walletConnector: wallet.connector,
46
- })), [wallets, chains, handleLogOut, preventWagmiSyncFromCallingLogout]);
49
+ })), [evmWallets, chains, handleLogOut, preventWagmiSyncFromCallingLogout]);
47
50
  /**
48
51
  * Updating the wagmi config must be done in a useEffect because
49
52
  * when setting the public client and connectors, wagmi will fire
@@ -0,0 +1,2 @@
1
+ import { Wallet } from '@dynamic-labs/sdk-react-core';
2
+ export declare const findAndOrderEvmWallets: (primaryWallet: Wallet | null, wallets: Wallet[]) => Wallet[];
@@ -0,0 +1,13 @@
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 };
@@ -0,0 +1 @@
1
+ export { findAndOrderEvmWallets } from './findAndOrderEvmWallets';
@@ -1 +1,2 @@
1
1
  export * from './resolveRpcUrlFromEvmNetworks';
2
+ export * from './findAndOrderEvmWallets';