@dynamic-labs/wagmi-connector 3.0.0-alpha.3 → 3.0.0-alpha.31
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 +305 -0
- package/package.json +6 -6
- package/src/lib/Connector.d.ts +1155 -195
- package/src/lib/Connector.js +19 -31
- package/src/lib/DynamicWagmiConnector.js +2 -2
- package/src/lib/hooks/useFindEvmWallet/useFindEvmWallet.d.ts +1 -1
- package/src/lib/hooks/useFindEvmWallet/useFindEvmWallet.js +21 -17
package/src/lib/Connector.js
CHANGED
|
@@ -3,18 +3,18 @@ import { __awaiter } from '../../_virtual/_tslib.js';
|
|
|
3
3
|
import { createConnector } from '@wagmi/core';
|
|
4
4
|
import { getAddress, createWalletClient, custom } from 'viem';
|
|
5
5
|
|
|
6
|
-
const getCreateConnectorFn = (
|
|
6
|
+
const getCreateConnectorFn = ({ connectorId, wallet, preventWagmiSyncFromCallingLogout, handleLogOut, }) => createConnector((config) => ({
|
|
7
7
|
connect() {
|
|
8
8
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9
|
-
if (!
|
|
9
|
+
if (!wallet.connector) {
|
|
10
10
|
throw new Error('WalletConnector is not defined');
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
wallet.connector.on('accountChange', ({ accounts }) => {
|
|
13
13
|
const handler = this.onAccountsChanged.bind(this);
|
|
14
14
|
handler(accounts);
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
wallet.connector.on('chainChange', ({ chain }) => this.onChainChanged(chain));
|
|
17
|
+
wallet.connector.on('disconnect', this.onDisconnect.bind(this));
|
|
18
18
|
const accounts = yield this.getAccounts();
|
|
19
19
|
return {
|
|
20
20
|
accounts,
|
|
@@ -24,38 +24,30 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
|
|
|
24
24
|
},
|
|
25
25
|
disconnect() {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
if (!
|
|
28
|
-
yield
|
|
29
|
-
yield
|
|
27
|
+
if (!preventWagmiSyncFromCallingLogout.current) {
|
|
28
|
+
yield wallet.connector.endSession();
|
|
29
|
+
yield handleLogOut();
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
wallet.connector.off('accountChange');
|
|
32
|
+
wallet.connector.off('chainChange');
|
|
33
|
+
wallet.connector.off('disconnect');
|
|
34
34
|
/**
|
|
35
35
|
* In our own Dynamic Wagmi sync component, we will flip the flag to true before calling disconnect,
|
|
36
36
|
* and here it automatically flips back to false afterwards. This will prevent the Connector from
|
|
37
37
|
* calling handleLogOut when we are the ones calling disconnect, but will preserve the existing behavior
|
|
38
38
|
* for customers who use useDisconnect directly.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
preventWagmiSyncFromCallingLogout.current = false;
|
|
41
41
|
});
|
|
42
42
|
},
|
|
43
43
|
getAccounts() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
|
|
46
|
-
const address = yield ((_a = parameters.walletConnector) === null || _a === void 0 ? void 0 : _a.getAddress());
|
|
47
|
-
if (!address) {
|
|
48
|
-
throw new Error('Not connected');
|
|
49
|
-
}
|
|
50
|
-
return [getAddress(address)];
|
|
45
|
+
return [getAddress(wallet.address)];
|
|
51
46
|
});
|
|
52
47
|
},
|
|
53
48
|
getChainId() {
|
|
54
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
|
|
56
|
-
throw new Error('WalletConnector is not defined');
|
|
57
|
-
}
|
|
58
|
-
const network = yield parameters.walletConnector.getNetwork();
|
|
50
|
+
const network = yield wallet.getNetwork();
|
|
59
51
|
if (!network) {
|
|
60
52
|
throw new Error('Network is not defined');
|
|
61
53
|
}
|
|
@@ -65,7 +57,7 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
|
|
|
65
57
|
getClient(args) {
|
|
66
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
59
|
var _a, _b;
|
|
68
|
-
const signer = yield
|
|
60
|
+
const signer = yield wallet.getSigner();
|
|
69
61
|
if (signer.account && signer.chain) {
|
|
70
62
|
return signer;
|
|
71
63
|
}
|
|
@@ -79,15 +71,14 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
|
|
|
79
71
|
},
|
|
80
72
|
getProvider() {
|
|
81
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
|
|
83
|
-
return (_a = parameters.walletConnector) === null || _a === void 0 ? void 0 : _a.getWalletClient();
|
|
74
|
+
return wallet.getWalletClient();
|
|
84
75
|
});
|
|
85
76
|
},
|
|
86
|
-
id:
|
|
77
|
+
id: connectorId,
|
|
87
78
|
isAuthorized() {
|
|
88
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
80
|
var _a, _b;
|
|
90
|
-
const accounts = (_b = (yield ((_a =
|
|
81
|
+
const accounts = (_b = (yield ((_a = wallet.connector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()))) !== null && _b !== void 0 ? _b : [];
|
|
91
82
|
return accounts.length > 0;
|
|
92
83
|
});
|
|
93
84
|
},
|
|
@@ -105,14 +96,11 @@ const getCreateConnectorFn = (parameters) => createConnector((config) => ({
|
|
|
105
96
|
onDisconnect() { },
|
|
106
97
|
switchChain(_a) {
|
|
107
98
|
return __awaiter(this, arguments, void 0, function* ({ chainId }) {
|
|
108
|
-
var _b;
|
|
109
99
|
const chain = config.chains.find((x) => x.id === chainId);
|
|
110
100
|
if (!chain) {
|
|
111
101
|
throw new Error(`Chain ${chainId} is not supported`);
|
|
112
102
|
}
|
|
113
|
-
yield
|
|
114
|
-
networkChainId: chainId,
|
|
115
|
-
}));
|
|
103
|
+
yield wallet.switchNetwork(chainId);
|
|
116
104
|
return chain;
|
|
117
105
|
});
|
|
118
106
|
},
|
|
@@ -15,7 +15,7 @@ const DynamicWagmiConnectorInner = ({ suppressChainMismatchError = false, childr
|
|
|
15
15
|
const { handleLogOut, primaryWallet } = useDynamicContext();
|
|
16
16
|
const wallets = useUserWallets();
|
|
17
17
|
useChainMismatchLogger({ throwOnMismatch: !suppressChainMismatchError });
|
|
18
|
-
const evmWallet = useFindEvmWallet(primaryWallet
|
|
18
|
+
const evmWallet = useFindEvmWallet(primaryWallet);
|
|
19
19
|
const getConnectorId = useConnectorId();
|
|
20
20
|
/**
|
|
21
21
|
* This will prevent the wagmi Connector from calling handleLogOut when we are the ones calling disconnect
|
|
@@ -31,7 +31,7 @@ const DynamicWagmiConnectorInner = ({ suppressChainMismatchError = false, childr
|
|
|
31
31
|
connectorId,
|
|
32
32
|
handleLogOut,
|
|
33
33
|
preventWagmiSyncFromCallingLogout,
|
|
34
|
-
|
|
34
|
+
wallet: evmWallet,
|
|
35
35
|
}));
|
|
36
36
|
}, [config._internal.connectors, getConnectorId, handleLogOut, evmWallet]);
|
|
37
37
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
2
|
-
export declare const useFindEvmWallet: (primaryWallet: Wallet | null
|
|
2
|
+
export declare const useFindEvmWallet: (primaryWallet: Wallet | null) => Wallet | undefined;
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
|
|
2
5
|
const isEvmWallet = (wallet) => wallet.connector.connectedChain === 'EVM';
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const useFindEvmWallet = (primaryWallet) => {
|
|
7
|
+
const [wallet, setWallet] = useState(undefined);
|
|
8
|
+
const checkForConnectedEvmWallet = (wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
+
if (!isEvmWallet(wallet)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const isConnected = yield wallet.isConnected();
|
|
13
|
+
if (isConnected) {
|
|
14
|
+
setWallet(wallet);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!primaryWallet) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
checkForConnectedEvmWallet(primaryWallet);
|
|
22
|
+
}, [primaryWallet]);
|
|
23
|
+
return wallet;
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
export { useFindEvmWallet };
|