@dynamic-labs/ethereum 4.8.1 → 4.8.2-preview.0

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +9 -10
  5. package/src/EthereumWalletConnectors.cjs +4 -3
  6. package/src/EthereumWalletConnectors.js +3 -2
  7. package/src/injected/InjectedWalletBase.cjs +2 -2
  8. package/src/injected/InjectedWalletBase.js +2 -2
  9. package/src/metaMask/MetaMaskConnector.cjs +1 -1
  10. package/src/metaMask/MetaMaskConnector.js +2 -2
  11. package/src/walletConnect/WalletConnectConnector/WalletConnectConnector.cjs +286 -0
  12. package/src/walletConnect/{walletConnect.d.ts → WalletConnectConnector/WalletConnectConnector.d.ts} +12 -53
  13. package/src/walletConnect/WalletConnectConnector/WalletConnectConnector.js +282 -0
  14. package/src/walletConnect/WalletConnectConnector/index.d.ts +1 -0
  15. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.cjs +169 -0
  16. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.d.ts +39 -0
  17. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.js +161 -0
  18. package/src/walletConnect/WalletConnectProvider/index.d.ts +1 -0
  19. package/src/walletConnect/index.d.ts +2 -2
  20. package/src/walletConnect/{fetchWalletConnectWallets.cjs → utils/fetchWalletConnectWallets.cjs} +2 -8
  21. package/src/walletConnect/{fetchWalletConnectWallets.d.ts → utils/fetchWalletConnectWallets.d.ts} +0 -1
  22. package/src/walletConnect/{fetchWalletConnectWallets.js → utils/fetchWalletConnectWallets.js} +3 -8
  23. package/src/walletConnect/utils/getWalletConnectConnector.cjs +14 -0
  24. package/src/walletConnect/utils/getWalletConnectConnector.d.ts +2 -0
  25. package/src/walletConnect/utils/getWalletConnectConnector.js +10 -0
  26. package/src/walletConnect/utils/index.d.ts +2 -0
  27. package/src/walletConnect/walletConnect.cjs +0 -504
  28. package/src/walletConnect/walletConnect.js +0 -495
package/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ### [4.8.2-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.8.1...v4.8.2-preview.0) (2025-02-28)
3
+
4
+
5
+ ### Features
6
+
7
+ * add disconnect to wallet action in connect only ([#8152](https://github.com/dynamic-labs/dynamic-auth/issues/8152)) ([4f8fa26](https://github.com/dynamic-labs/dynamic-auth/commit/4f8fa26c293aa249e697cc6494463b3bb545251a))
8
+ * support for onramp options via function, and default support for coinbase ([#8139](https://github.com/dynamic-labs/dynamic-auth/issues/8139)) ([f4dee01](https://github.com/dynamic-labs/dynamic-auth/commit/f4dee0175512de7a15928c577a20cc620863c282))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * embedded widget race condition that would show both embedded and non-embedded widgets at the same time ([4cb1686](https://github.com/dynamic-labs/dynamic-auth/commit/4cb16860cc61f6fcc074eb20ce38f848cdda31f1))
14
+ * filter out networks without a key value when parsing coinbase onramp url ([#8158](https://github.com/dynamic-labs/dynamic-auth/issues/8158)) ([8033299](https://github.com/dynamic-labs/dynamic-auth/commit/80332991551987a29b6ea7c8f66fd373956d875b))
15
+ * **QNTM-2927:** send users back to login on MM cancel ([#8149](https://github.com/dynamic-labs/dynamic-auth/issues/8149)) ([8e92702](https://github.com/dynamic-labs/dynamic-auth/commit/8e9270270220fc781da9c9235f86b29b9c4d2f28))
16
+ * update WC re-connect view on mobile ([45c5241](https://github.com/dynamic-labs/dynamic-auth/commit/45c5241fa8d973b8ad3f8b0e85b5034e429c3c11))
17
+
2
18
  ### [4.8.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.8.0...v4.8.1) (2025-02-25)
3
19
 
4
20
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.8.1";
6
+ var version = "4.8.2-preview.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.8.1";
2
+ var version = "4.8.2-preview.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "4.8.1",
3
+ "version": "4.8.2-preview.0",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -20,18 +20,17 @@
20
20
  "dependencies": {
21
21
  "@coinbase/wallet-sdk": "4.3.0",
22
22
  "@walletconnect/ethereum-provider": "2.18.0",
23
- "@walletconnect/types": "2.18.0",
24
23
  "eventemitter3": "5.0.1",
25
24
  "buffer": "6.0.3",
26
25
  "@metamask/sdk": "0.32.0",
27
- "@dynamic-labs/assert-package-version": "4.8.1",
28
- "@dynamic-labs/embedded-wallet-evm": "4.8.1",
29
- "@dynamic-labs/ethereum-core": "4.8.1",
30
- "@dynamic-labs/logger": "4.8.1",
31
- "@dynamic-labs/types": "4.8.1",
32
- "@dynamic-labs/utils": "4.8.1",
33
- "@dynamic-labs/wallet-book": "4.8.1",
34
- "@dynamic-labs/wallet-connector-core": "4.8.1"
26
+ "@dynamic-labs/assert-package-version": "4.8.2-preview.0",
27
+ "@dynamic-labs/embedded-wallet-evm": "4.8.2-preview.0",
28
+ "@dynamic-labs/ethereum-core": "4.8.2-preview.0",
29
+ "@dynamic-labs/logger": "4.8.2-preview.0",
30
+ "@dynamic-labs/types": "4.8.2-preview.0",
31
+ "@dynamic-labs/utils": "4.8.2-preview.0",
32
+ "@dynamic-labs/wallet-book": "4.8.2-preview.0",
33
+ "@dynamic-labs/wallet-connector-core": "4.8.2-preview.0"
35
34
  },
36
35
  "peerDependencies": {
37
36
  "viem": "^2.21.55"
@@ -10,8 +10,9 @@ require('@dynamic-labs/ethereum-core');
10
10
  require('viem');
11
11
  require('@dynamic-labs/wallet-connector-core');
12
12
  require('@dynamic-labs/wallet-book');
13
- require('./walletConnect/walletConnect.cjs');
14
- var fetchWalletConnectWallets = require('./walletConnect/fetchWalletConnectWallets.cjs');
13
+ require('./walletConnect/WalletConnectProvider/WalletConnectProvider.cjs');
14
+ var fetchWalletConnectWallets = require('./walletConnect/utils/fetchWalletConnectWallets.cjs');
15
+ var getWalletConnectConnector = require('./walletConnect/utils/getWalletConnectConnector.cjs');
15
16
  var FallbackEvmConnector = require('./injected/FallbackEvmConnector.cjs');
16
17
  var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
17
18
  var coinbase = require('./coinbase/coinbase.cjs');
@@ -25,7 +26,7 @@ const EthereumWalletConnectors = (props) => [
25
26
  MetaMaskConnector.MetaMaskConnector,
26
27
  coinbase.Coinbase,
27
28
  FallbackEvmConnector.FallbackEvmConnector,
28
- fetchWalletConnectWallets.getWalletConnectConnector(),
29
+ getWalletConnectConnector.getWalletConnectConnector(),
29
30
  ];
30
31
 
31
32
  exports.EthereumWalletConnectors = EthereumWalletConnectors;
@@ -6,8 +6,9 @@ import '@dynamic-labs/ethereum-core';
6
6
  import 'viem';
7
7
  import '@dynamic-labs/wallet-connector-core';
8
8
  import '@dynamic-labs/wallet-book';
9
- import './walletConnect/walletConnect.js';
10
- import { fetchWalletConnectWallets, getWalletConnectConnector } from './walletConnect/fetchWalletConnectWallets.js';
9
+ import './walletConnect/WalletConnectProvider/WalletConnectProvider.js';
10
+ import { fetchWalletConnectWallets } from './walletConnect/utils/fetchWalletConnectWallets.js';
11
+ import { getWalletConnectConnector } from './walletConnect/utils/getWalletConnectConnector.js';
11
12
  import { FallbackEvmConnector } from './injected/FallbackEvmConnector.js';
12
13
  import { injectedWalletOverrides, fetchInjectedWalletConnector } from './injected/fetchInjectedWalletConnectors.js';
13
14
  import { Coinbase } from './coinbase/coinbase.js';
@@ -7,7 +7,7 @@ var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var utils = require('@dynamic-labs/utils');
8
8
  var ethereumCore = require('@dynamic-labs/ethereum-core');
9
9
  var ethProviderHelper = require('../ethProviderHelper.cjs');
10
- var walletConnect = require('../walletConnect/walletConnect.cjs');
10
+ var WalletConnectConnector = require('../walletConnect/WalletConnectConnector/WalletConnectConnector.cjs');
11
11
 
12
12
  class InjectedWalletBase extends ethereumCore.EthereumWalletConnector {
13
13
  constructor() {
@@ -39,7 +39,7 @@ class InjectedWalletBase extends ethereumCore.EthereumWalletConnector {
39
39
  if (!this.walletConnectorFallback) {
40
40
  return this;
41
41
  }
42
- return new walletConnect.WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
42
+ return new WalletConnectConnector.WalletConnectConnector(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
43
43
  }
44
44
  findProvider() {
45
45
  var _a;
@@ -3,7 +3,7 @@ import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { isMobile } from '@dynamic-labs/utils';
4
4
  import { EthereumWalletConnector } from '@dynamic-labs/ethereum-core';
5
5
  import { EthProviderHelper } from '../ethProviderHelper.js';
6
- import { WalletConnect } from '../walletConnect/walletConnect.js';
6
+ import { WalletConnectConnector } from '../walletConnect/WalletConnectConnector/WalletConnectConnector.js';
7
7
 
8
8
  class InjectedWalletBase extends EthereumWalletConnector {
9
9
  constructor() {
@@ -35,7 +35,7 @@ class InjectedWalletBase extends EthereumWalletConnector {
35
35
  if (!this.walletConnectorFallback) {
36
36
  return this;
37
37
  }
38
- return new WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
38
+ return new WalletConnectConnector(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
39
39
  }
40
40
  findProvider() {
41
41
  var _a;
@@ -149,7 +149,7 @@ class MetaMaskConnector extends InjectedWalletBase.InjectedWalletBase {
149
149
  catch (error) {
150
150
  const isRequestPendingError = isPendingWalletRequestPermissionError.isPendingWalletRequestPermissionError(error);
151
151
  if (!isRequestPendingError) {
152
- throw error;
152
+ reject(utils.MetaMaskError.fromError(error));
153
153
  }
154
154
  else {
155
155
  yield waitForConnection.waitForConnection(this.getProvider());
@@ -4,7 +4,7 @@ import { MetaMaskSDK } from '@metamask/sdk';
4
4
  import { createWalletClient, custom, isHex, toHex } from 'viem';
5
5
  import { getOrMapViemChain } from '@dynamic-labs/ethereum-core';
6
6
  import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
- import { createEventTimeline, PlatformService, isMobile, retryableFn } from '@dynamic-labs/utils';
7
+ import { createEventTimeline, PlatformService, isMobile, MetaMaskError, retryableFn } from '@dynamic-labs/utils';
8
8
  import { logger } from '../utils/logger.js';
9
9
  import { InjectedWalletBase } from '../injected/InjectedWalletBase.js';
10
10
  import { createMetaMaskSDKDisplayUriState } from './utils/createMetaMaskSDKDisplayUriState.js';
@@ -145,7 +145,7 @@ class MetaMaskConnector extends InjectedWalletBase {
145
145
  catch (error) {
146
146
  const isRequestPendingError = isPendingWalletRequestPermissionError(error);
147
147
  if (!isRequestPendingError) {
148
- throw error;
148
+ reject(MetaMaskError.fromError(error));
149
149
  }
150
150
  else {
151
151
  yield waitForConnection(this.getProvider());
@@ -0,0 +1,286 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var viem = require('viem');
8
+ var ethereumCore = require('@dynamic-labs/ethereum-core');
9
+ var utils = require('@dynamic-labs/utils');
10
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
+ var normalizeRpcError = require('../../utils/normalizeRpcError/normalizeRpcError.cjs');
12
+ var WalletConnectProvider = require('../WalletConnectProvider/WalletConnectProvider.cjs');
13
+
14
+ const WC_ACTIVE_ACCOUNT_KEY = 'dynamic-wc2-active-account';
15
+ const WC_CURRENT_CHAIN_KEY = 'dynamic-wc2-current-chain';
16
+ class WalletConnectConnector extends ethereumCore.EthereumWalletConnector {
17
+ constructor(opts) {
18
+ super(opts);
19
+ this.canConnectViaQrCode = true;
20
+ this.isWalletConnect = true;
21
+ this.name = opts.walletName;
22
+ this.deepLinkPreference = opts.deepLinkPreference || 'native';
23
+ // restore the active account and chain from local storage
24
+ const storedAddress = localStorage.getItem(WC_ACTIVE_ACCOUNT_KEY);
25
+ if (storedAddress) {
26
+ this.setActiveAccount(storedAddress);
27
+ }
28
+ const storedChainId = localStorage.getItem(WC_CURRENT_CHAIN_KEY);
29
+ if (storedChainId) {
30
+ this.currentChainId = utils.parseIntSafe(storedChainId);
31
+ }
32
+ // set provider props generic to all wallets
33
+ WalletConnectProvider.WalletConnectProvider.projectId = opts.projectId;
34
+ WalletConnectProvider.WalletConnectProvider.enabledNetworks = opts.evmNetworks;
35
+ WalletConnectProvider.WalletConnectProvider.preferredChains =
36
+ opts.walletConnectPreferredChains || [];
37
+ WalletConnectProvider.WalletConnectProvider.evmNetworkRpcMap = this.evmNetworkRpcMap();
38
+ }
39
+ init() {
40
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
41
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] init called', {
42
+ isInitialized: WalletConnectProvider.WalletConnectProvider.isInitialized,
43
+ });
44
+ // we should only init the provider once as soon as possible
45
+ // the connection is established when a wallet is selected (with getAddress)
46
+ if (WalletConnectProvider.WalletConnectProvider.isInitialized) {
47
+ walletConnectorCore.logger.debug('[WalletConnect] init - already initialized - skipping');
48
+ return;
49
+ }
50
+ walletConnectorCore.logger.debug('[WalletConnect] init');
51
+ yield WalletConnectProvider.WalletConnectProvider.init();
52
+ const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
53
+ if (!provider) {
54
+ throw new utils.DynamicError('WalletConnectProvider is not initialized');
55
+ }
56
+ this.setupWCEventListeners();
57
+ this.walletConnectorEventsEmitter.emit('walletConnectInitialized');
58
+ });
59
+ }
60
+ setupWCEventListeners() {
61
+ walletConnectorCore.logger.debug('[WalletConnect] setupWCEventListeners');
62
+ WalletConnectProvider.WalletConnectProvider.teardownEventListeners();
63
+ WalletConnectProvider.WalletConnectProvider.setupEventListeners({
64
+ onAccountChanged: (account) => {
65
+ walletConnectorCore.logger.debug('[WalletConnect] onAccountChanged', { account });
66
+ this.setWCActiveAccount(account);
67
+ },
68
+ onChainChanged: (chainId) => {
69
+ walletConnectorCore.logger.debug('[WalletConnect] onChainChange', { chainId });
70
+ if (chainId === this.currentChainId) {
71
+ walletConnectorCore.logger.debug(`[WalletConnect] onChainChange - ignoring chainChanged event with same chain id as current chain id: ${chainId}`);
72
+ return;
73
+ }
74
+ this.currentChainId = chainId;
75
+ this.emit('chainChange', { chain: String(chainId) });
76
+ },
77
+ onDisconnect: () => {
78
+ walletConnectorCore.logger.debug('[WalletConnect] onDisconnect');
79
+ this.endSession();
80
+ this.emit('disconnect');
81
+ },
82
+ });
83
+ }
84
+ endSession() {
85
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
86
+ walletConnectorCore.logger.debug('[WalletConnect] endSession');
87
+ localStorage.removeItem(WC_ACTIVE_ACCOUNT_KEY);
88
+ this.setActiveAccount(undefined);
89
+ this.currentChainId = undefined;
90
+ yield WalletConnectProvider.WalletConnectProvider.disconnect();
91
+ });
92
+ }
93
+ getAddress(opts) {
94
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
95
+ walletConnectorCore.logger.debug('[WalletConnect] getAddress', opts);
96
+ if (!WalletConnectProvider.WalletConnectProvider.isInitialized) {
97
+ walletConnectorCore.logger.debug('[WalletConnect] getAddress - WalletConnectProvider is not initialized');
98
+ throw new utils.DynamicError('WalletConnectProvider is not initialized');
99
+ }
100
+ walletConnectorCore.logger.debug('[WalletConnect] getAddress - connecting to WalletConnect');
101
+ const addresses = yield WalletConnectProvider.WalletConnectProvider.connect({
102
+ connectionOpts: opts,
103
+ deepLinkPreference: this.deepLinkPreference,
104
+ deepLinks: this.metadata.deepLinks,
105
+ });
106
+ walletConnectorCore.logger.debug('[WalletConnect] getAddress - connection result', addresses);
107
+ const address = addresses === null || addresses === void 0 ? void 0 : addresses[0];
108
+ this.setWCActiveAccount(address);
109
+ return address;
110
+ });
111
+ }
112
+ getWalletClient(chainId) {
113
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getWalletClient was called - chainId', chainId);
114
+ const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
115
+ if (!provider) {
116
+ walletConnectorCore.logger.debug('[WalletConnect] getWalletClient - provider is not initialized');
117
+ throw new utils.DynamicError('WalletConnectProvider is not initialized');
118
+ }
119
+ const walletClient = viem.createWalletClient({
120
+ account: this.getActiveAccount(),
121
+ chain: ethereumCore.chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
122
+ transport: viem.custom({
123
+ request: (args) => {
124
+ this.deepLinkIfApplicable(args.method);
125
+ return provider.request(args).catch(normalizeRpcError.normalizeRpcError);
126
+ },
127
+ }),
128
+ });
129
+ return walletClient;
130
+ }
131
+ deepLinkIfApplicable(method) {
132
+ const methodsThatRequireDeepLink = [
133
+ 'personal_sign',
134
+ 'eth_sendTransaction',
135
+ 'eth_signTypedData_v4',
136
+ ];
137
+ const deepLink = this.getDeepLink();
138
+ if (utils.isMobile() && deepLink && methodsThatRequireDeepLink.includes(method)) {
139
+ utils.PlatformService.openURL(deepLink);
140
+ }
141
+ }
142
+ signMessage(messageToSign) {
143
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
144
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] signMessage', messageToSign);
145
+ const activeAccount = this.getActiveAccount();
146
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] signMessage - activeAccount', activeAccount);
147
+ if (!activeAccount) {
148
+ return;
149
+ }
150
+ const walletClient = yield this.getWalletClient();
151
+ return walletClient.signMessage({
152
+ account: activeAccount,
153
+ message: messageToSign,
154
+ });
155
+ });
156
+ }
157
+ getConnectedAccounts() {
158
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
159
+ const activeAccount = this.getActiveAccount();
160
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getConnectedAccounts - activeAccount', activeAccount);
161
+ return activeAccount ? [activeAccount.address] : [];
162
+ });
163
+ }
164
+ setWCActiveAccount(account) {
165
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] setWCActiveAccount', account);
166
+ if (account) {
167
+ localStorage.setItem(WC_ACTIVE_ACCOUNT_KEY, account);
168
+ this.setActiveAccount(account);
169
+ this.emit('accountChange', { accounts: [account] });
170
+ }
171
+ else {
172
+ localStorage.removeItem(WC_ACTIVE_ACCOUNT_KEY);
173
+ this.setActiveAccount(undefined);
174
+ }
175
+ }
176
+ get currentChainId() {
177
+ const lsCurrentChain = localStorage.getItem(WC_CURRENT_CHAIN_KEY);
178
+ try {
179
+ return lsCurrentChain ? utils.parseIntSafe(lsCurrentChain) : undefined;
180
+ }
181
+ catch (e) {
182
+ walletConnectorCore.logger.debug('[WalletConnect] getCurrentChainId - error', e);
183
+ return undefined;
184
+ }
185
+ }
186
+ set currentChainId(value) {
187
+ if (value) {
188
+ localStorage.setItem(WC_CURRENT_CHAIN_KEY, value.toString());
189
+ }
190
+ else {
191
+ localStorage.removeItem(WC_CURRENT_CHAIN_KEY);
192
+ }
193
+ }
194
+ getNetwork() {
195
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
196
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork');
197
+ const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
198
+ if (provider === null || provider === void 0 ? void 0 : provider.chainId) {
199
+ const network = provider.chainId;
200
+ this.currentChainId = network;
201
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork - provider network', network);
202
+ return network;
203
+ }
204
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork - no provider found, returning current chain id', {
205
+ currentChainId: this.currentChainId,
206
+ });
207
+ return this.currentChainId;
208
+ });
209
+ }
210
+ providerSwitchNetwork(_a) {
211
+ const _super = Object.create(null, {
212
+ providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
213
+ });
214
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ network, }) {
215
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - network', {
216
+ network,
217
+ switchNetworkOnlyFromWallet: this.switchNetworkOnlyFromWallet,
218
+ });
219
+ const currentNetworkId = yield this.getNetwork();
220
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - currentNetworkId', currentNetworkId);
221
+ if (currentNetworkId && currentNetworkId === network.chainId) {
222
+ return;
223
+ }
224
+ if (this.switchNetworkOnlyFromWallet) {
225
+ throw new utils.DynamicError('Network switching is only supported through the wallet');
226
+ }
227
+ const walletClient = yield this.getWalletClient();
228
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - will switch network');
229
+ yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
230
+ this.currentChainId = network.chainId;
231
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - switched network', network.chainId);
232
+ this.emit('chainChange', { chain: String(network.chainId) });
233
+ });
234
+ }
235
+ supportsNetworkSwitching() {
236
+ return true;
237
+ }
238
+ getSupportedNetworks() {
239
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
240
+ var _a;
241
+ const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
242
+ if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
243
+ return [];
244
+ }
245
+ const chains = [];
246
+ // Some wallet (i.e ZenGo) use namespaces.account to list supported chains
247
+ // while others use keys within the namespaces object
248
+ Object.keys(provider === null || provider === void 0 ? void 0 : provider.session.namespaces).forEach((key) => {
249
+ if (key.startsWith('eip155:')) {
250
+ chains.push(key.split(':')[1]);
251
+ }
252
+ });
253
+ (_a = provider === null || provider === void 0 ? void 0 : provider.session.namespaces.eip155) === null || _a === void 0 ? void 0 : _a.accounts.forEach((account) => chains.push(account.split(':')[1]));
254
+ return chains.length
255
+ ? chains
256
+ : this.evmNetworks.map((network) => network.chainId.toString());
257
+ });
258
+ }
259
+ getDeepLink() {
260
+ var _a;
261
+ const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
262
+ walletConnectorCore.logger.debug('[WalletConnect] getDeepLink', {
263
+ hasSession: Boolean(provider === null || provider === void 0 ? void 0 : provider.session),
264
+ topic: (_a = provider === null || provider === void 0 ? void 0 : provider.session) === null || _a === void 0 ? void 0 : _a.topic,
265
+ uri: provider === null || provider === void 0 ? void 0 : provider.signer.uri,
266
+ });
267
+ if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
268
+ return;
269
+ }
270
+ const deepLink = walletConnectorCore.getDeepLink({
271
+ deepLinks: this.metadata.deepLinks,
272
+ mode: 'regular',
273
+ preference: this.deepLinkPreference,
274
+ uri: provider.signer.uri,
275
+ });
276
+ walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getDeepLink - deepLink', deepLink);
277
+ if (!deepLink) {
278
+ return;
279
+ }
280
+ // we need to include the session topic here because it helps the wallet
281
+ // auto redirect back to the dapp after signing
282
+ return `${deepLink}?sessionTopic=${provider.session.topic}`;
283
+ }
284
+ }
285
+
286
+ exports.WalletConnectConnector = WalletConnectConnector;
@@ -1,45 +1,23 @@
1
- import EthereumProvider from '@walletconnect/ethereum-provider';
2
- import type { SessionTypes } from '@walletconnect/types';
3
1
  import { Account, Transport, Chain as ViemChain } from 'viem';
4
2
  import { EthereumWalletConnector, EthereumWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
5
3
  import { EvmNetwork } from '@dynamic-labs/types';
6
4
  import { DeepLinkVariant, GetAddressOpts, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
7
- export type WalletConnectOpts = EthereumWalletConnectorOpts & {
5
+ export type WalletConnectConnectorOpts = EthereumWalletConnectorOpts & {
8
6
  projectId?: string;
9
7
  walletName: string;
10
8
  deepLinkPreference?: DeepLinkVariant;
11
9
  walletConnectPreferredChains?: `eip155:${number}`[];
12
10
  };
13
- export declare class WalletConnect extends EthereumWalletConnector implements IWalletConnectConnector {
14
- private static provider;
11
+ export declare class WalletConnectConnector extends EthereumWalletConnector implements IWalletConnectConnector {
15
12
  name: string;
16
- session: SessionTypes.Struct | undefined;
17
- isInitialized: boolean;
18
- initializePromise: Promise<void> | undefined;
19
13
  canConnectViaQrCode: boolean;
20
14
  isWalletConnect: boolean;
21
- private projectId?;
22
15
  private deepLinkPreference;
23
- private preferredChains;
24
- private sessionEventHandler;
25
- private sessionDeleteHandler;
26
- private _currentChainId;
27
- supportsNetworkSwitching(): boolean;
28
- constructor(opts: WalletConnectOpts);
29
- /**
30
- * This method is used to get the address of the active account.
31
- * It will re-initialize the provider if the provider is not found.
32
- * @param opts
33
- * @returns
34
- */
35
- getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
16
+ constructor(opts: WalletConnectConnectorOpts);
36
17
  init(): Promise<void>;
37
- private initProvider;
38
- private createInitProviderPromise;
39
- private initConnection;
40
- createProvider(): Promise<EthereumProvider>;
41
- private refreshSession;
42
- private getMappedChainsByPreferredOrder;
18
+ private setupWCEventListeners;
19
+ endSession(): Promise<void>;
20
+ getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
43
21
  getWalletClient(chainId?: string): {
44
22
  account: Account;
45
23
  batch?: {
@@ -7697,36 +7675,17 @@ export declare class WalletConnect extends EthereumWalletConnector implements IW
7697
7675
  uid?: undefined;
7698
7676
  } & import("viem").ExactPartial<Pick<import("viem").PublicActions<Transport, ViemChain, 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<ViemChain, Account>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, ViemChain, Account, import("viem").WalletRpcSchema, import("viem").WalletActions<ViemChain, Account>>) => client) => import("viem").Client<Transport, ViemChain, Account, import("viem").WalletRpcSchema, { [K_1 in keyof client]: client[K_1]; } & import("viem").WalletActions<ViemChain, Account>>;
7699
7677
  };
7700
- private get currentChainId();
7701
- private set currentChainId(value);
7702
- get sessionTopicKey(): string;
7703
- get activeAccountKey(): string;
7704
- get currentChainKey(): string;
7705
- setupEventListeners(): void;
7706
- teardownEventListeners(): void;
7707
- /**
7708
- * WalletConnect V2 will fail to send the sign message request if the chainId
7709
- * is not the same as the one in the session. This method will wait for the
7710
- * chainId to change and then retry the sign message request.
7711
- *
7712
- * Otherwise it will just return the result of the sign message request.
7713
- *
7714
- * @param signMessageFn - Function to sign message with provider
7715
- * @param messageToSign - Message to sign
7716
- * @returns
7717
- */
7718
- protected waitForSignMessage(signMessageFn: (messageToSign: string) => Promise<string | undefined>, messageToSign: string): Promise<string | undefined>;
7719
- getDeepLink(): string | undefined;
7678
+ private deepLinkIfApplicable;
7720
7679
  signMessage(messageToSign: string): Promise<string | undefined>;
7721
- private clearActiveAccount;
7722
- private clearSession;
7680
+ getConnectedAccounts(): Promise<string[]>;
7723
7681
  private setWCActiveAccount;
7724
- private setSession;
7725
- endSession(): Promise<void>;
7682
+ private get currentChainId();
7683
+ private set currentChainId(value);
7726
7684
  getNetwork(): Promise<number | undefined>;
7727
7685
  providerSwitchNetwork({ network, }: {
7728
7686
  network: EvmNetwork;
7729
7687
  }): Promise<void>;
7730
- getConnectedAccounts(): Promise<string[]>;
7688
+ supportsNetworkSwitching(): boolean;
7731
7689
  getSupportedNetworks(): Promise<string[]>;
7690
+ getDeepLink(): string | undefined;
7732
7691
  }