@dynamic-labs/wagmi-connector 1.0.0 → 1.0.2
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 +17 -0
- package/package.json +6 -7
- package/src/lib/DynamicWagmiConnector.js +8 -5
- package/src/lib/utils/findAndOrderEvmWallets/findAndOrderEvmWallets.d.ts +2 -0
- package/src/lib/utils/findAndOrderEvmWallets/findAndOrderEvmWallets.js +13 -0
- package/src/lib/utils/findAndOrderEvmWallets/index.d.ts +1 -0
- package/src/lib/utils/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
|
|
2
|
+
### [1.0.2](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.1...v1.0.2) (2023-12-18)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* prevent duplicated brave wallet connector ([#4209](https://github.com/dynamic-labs/DynamicAuth/issues/4209)) ([31589b9](https://github.com/dynamic-labs/DynamicAuth/commit/31589b92ea067a5e7ca5a5bd9adb881d086d7868))
|
|
8
|
+
* ensure wagmi connects to primary wallet ([#4206](https://github.com/dynamic-labs/DynamicAuth/issues/4206)) ([#4210](https://github.com/dynamic-labs/DynamicAuth/issues/4210)) ([072bb05](https://github.com/dynamic-labs/DynamicAuth/commit/072bb05a5a9fd5b82f5498c20ff74ca966f3ea9f))
|
|
9
|
+
* ensure wallets group view shows multiple options ([#4184](https://github.com/dynamic-labs/DynamicAuth/issues/4184)) ([#4187](https://github.com/dynamic-labs/DynamicAuth/issues/4187)) ([b751f49](https://github.com/dynamic-labs/DynamicAuth/commit/b751f4952ea5a46b536edc999f37ea134348f8ef)), closes [#4186](https://github.com/dynamic-labs/DynamicAuth/issues/4186)
|
|
10
|
+
* enable brave to read the connected network ([#4198](https://github.com/dynamic-labs/DynamicAuth/issues/4198)) ([979e866](https://github.com/dynamic-labs/DynamicAuth/commit/979e86660f13982992cd43b1d9a8218150437e8b))
|
|
11
|
+
|
|
12
|
+
### [1.0.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0...v1.0.1) (2023-12-14)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* update wagmi to v1.4.12 ([#4171](https://github.com/dynamic-labs/DynamicAuth/issues/4171)) ([a741989](https://github.com/dynamic-labs/DynamicAuth/commit/a74198978f4708e96b12743b2f1f372b23940020))
|
|
18
|
+
|
|
2
19
|
## [1.0.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.14...v1.0.0) (2023-12-12)
|
|
3
20
|
|
|
4
21
|
Changelog: https://docs.dynamic.xyz/changelog/v1
|
package/package.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
7
7
|
"directory": "packages/wagmi-connector"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@wagmi/core": "^1.3.0",
|
|
11
10
|
"react": "^17.0.2 || ^18.0.0",
|
|
12
11
|
"viem": "^1.1.0",
|
|
13
|
-
"wagmi": "^1.
|
|
14
|
-
"@dynamic-labs/rpc-providers": "1.0.
|
|
15
|
-
"@dynamic-labs/sdk-react-core": "1.0.
|
|
16
|
-
"@dynamic-labs/types": "1.0.
|
|
17
|
-
"@dynamic-labs/wallet-connector-core": "1.0.
|
|
12
|
+
"wagmi": "^1.4.12",
|
|
13
|
+
"@dynamic-labs/rpc-providers": "1.0.2",
|
|
14
|
+
"@dynamic-labs/sdk-react-core": "1.0.2",
|
|
15
|
+
"@dynamic-labs/types": "1.0.2",
|
|
16
|
+
"@dynamic-labs/wallet-connector-core": "1.0.2",
|
|
18
17
|
"eventemitter3": "5.0.1"
|
|
19
18
|
},
|
|
20
19
|
"license": "MIT",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef,
|
|
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
|
-
|
|
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(
|
|
44
|
+
const connector = useMemo(() => getConnector(evmWallets, (wallet) => new Connector({
|
|
42
45
|
chains,
|
|
43
46
|
handleLogOut,
|
|
44
47
|
preventWagmiSyncFromCallingLogout,
|
|
45
48
|
walletConnector: wallet.connector,
|
|
46
|
-
})), [
|
|
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,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';
|
package/src/lib/utils/index.d.ts
CHANGED