@dynamic-labs/ethereum 4.8.2-preview.0 → 4.8.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.
Files changed (26) hide show
  1. package/CHANGELOG.md +6 -3
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +10 -9
  5. package/src/EthereumWalletConnectors.cjs +3 -4
  6. package/src/EthereumWalletConnectors.js +2 -3
  7. package/src/injected/InjectedWalletBase.cjs +2 -2
  8. package/src/injected/InjectedWalletBase.js +2 -2
  9. package/src/walletConnect/{utils/fetchWalletConnectWallets.cjs → fetchWalletConnectWallets.cjs} +8 -2
  10. package/src/walletConnect/{utils/fetchWalletConnectWallets.d.ts → fetchWalletConnectWallets.d.ts} +1 -0
  11. package/src/walletConnect/{utils/fetchWalletConnectWallets.js → fetchWalletConnectWallets.js} +8 -3
  12. package/src/walletConnect/index.d.ts +2 -2
  13. package/src/walletConnect/walletConnect.cjs +504 -0
  14. package/src/walletConnect/{WalletConnectConnector/WalletConnectConnector.d.ts → walletConnect.d.ts} +53 -12
  15. package/src/walletConnect/walletConnect.js +495 -0
  16. package/src/walletConnect/WalletConnectConnector/WalletConnectConnector.cjs +0 -286
  17. package/src/walletConnect/WalletConnectConnector/WalletConnectConnector.js +0 -282
  18. package/src/walletConnect/WalletConnectConnector/index.d.ts +0 -1
  19. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.cjs +0 -169
  20. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.d.ts +0 -39
  21. package/src/walletConnect/WalletConnectProvider/WalletConnectProvider.js +0 -161
  22. package/src/walletConnect/WalletConnectProvider/index.d.ts +0 -1
  23. package/src/walletConnect/utils/getWalletConnectConnector.cjs +0 -14
  24. package/src/walletConnect/utils/getWalletConnectConnector.d.ts +0 -2
  25. package/src/walletConnect/utils/getWalletConnectConnector.js +0 -10
  26. package/src/walletConnect/utils/index.d.ts +0 -2
@@ -1,286 +0,0 @@
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,282 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../../_virtual/_tslib.js';
3
- import { createWalletClient, custom } from 'viem';
4
- import { EthereumWalletConnector, chainsMap } from '@dynamic-labs/ethereum-core';
5
- import { parseIntSafe, DynamicError, isMobile, PlatformService } from '@dynamic-labs/utils';
6
- import { logger, getDeepLink } from '@dynamic-labs/wallet-connector-core';
7
- import { normalizeRpcError } from '../../utils/normalizeRpcError/normalizeRpcError.js';
8
- import { WalletConnectProvider } from '../WalletConnectProvider/WalletConnectProvider.js';
9
-
10
- const WC_ACTIVE_ACCOUNT_KEY = 'dynamic-wc2-active-account';
11
- const WC_CURRENT_CHAIN_KEY = 'dynamic-wc2-current-chain';
12
- class WalletConnectConnector extends EthereumWalletConnector {
13
- constructor(opts) {
14
- super(opts);
15
- this.canConnectViaQrCode = true;
16
- this.isWalletConnect = true;
17
- this.name = opts.walletName;
18
- this.deepLinkPreference = opts.deepLinkPreference || 'native';
19
- // restore the active account and chain from local storage
20
- const storedAddress = localStorage.getItem(WC_ACTIVE_ACCOUNT_KEY);
21
- if (storedAddress) {
22
- this.setActiveAccount(storedAddress);
23
- }
24
- const storedChainId = localStorage.getItem(WC_CURRENT_CHAIN_KEY);
25
- if (storedChainId) {
26
- this.currentChainId = parseIntSafe(storedChainId);
27
- }
28
- // set provider props generic to all wallets
29
- WalletConnectProvider.projectId = opts.projectId;
30
- WalletConnectProvider.enabledNetworks = opts.evmNetworks;
31
- WalletConnectProvider.preferredChains =
32
- opts.walletConnectPreferredChains || [];
33
- WalletConnectProvider.evmNetworkRpcMap = this.evmNetworkRpcMap();
34
- }
35
- init() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- logger.logVerboseTroubleshootingMessage('[WalletConnect] init called', {
38
- isInitialized: WalletConnectProvider.isInitialized,
39
- });
40
- // we should only init the provider once as soon as possible
41
- // the connection is established when a wallet is selected (with getAddress)
42
- if (WalletConnectProvider.isInitialized) {
43
- logger.debug('[WalletConnect] init - already initialized - skipping');
44
- return;
45
- }
46
- logger.debug('[WalletConnect] init');
47
- yield WalletConnectProvider.init();
48
- const provider = WalletConnectProvider.getProvider();
49
- if (!provider) {
50
- throw new DynamicError('WalletConnectProvider is not initialized');
51
- }
52
- this.setupWCEventListeners();
53
- this.walletConnectorEventsEmitter.emit('walletConnectInitialized');
54
- });
55
- }
56
- setupWCEventListeners() {
57
- logger.debug('[WalletConnect] setupWCEventListeners');
58
- WalletConnectProvider.teardownEventListeners();
59
- WalletConnectProvider.setupEventListeners({
60
- onAccountChanged: (account) => {
61
- logger.debug('[WalletConnect] onAccountChanged', { account });
62
- this.setWCActiveAccount(account);
63
- },
64
- onChainChanged: (chainId) => {
65
- logger.debug('[WalletConnect] onChainChange', { chainId });
66
- if (chainId === this.currentChainId) {
67
- logger.debug(`[WalletConnect] onChainChange - ignoring chainChanged event with same chain id as current chain id: ${chainId}`);
68
- return;
69
- }
70
- this.currentChainId = chainId;
71
- this.emit('chainChange', { chain: String(chainId) });
72
- },
73
- onDisconnect: () => {
74
- logger.debug('[WalletConnect] onDisconnect');
75
- this.endSession();
76
- this.emit('disconnect');
77
- },
78
- });
79
- }
80
- endSession() {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- logger.debug('[WalletConnect] endSession');
83
- localStorage.removeItem(WC_ACTIVE_ACCOUNT_KEY);
84
- this.setActiveAccount(undefined);
85
- this.currentChainId = undefined;
86
- yield WalletConnectProvider.disconnect();
87
- });
88
- }
89
- getAddress(opts) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- logger.debug('[WalletConnect] getAddress', opts);
92
- if (!WalletConnectProvider.isInitialized) {
93
- logger.debug('[WalletConnect] getAddress - WalletConnectProvider is not initialized');
94
- throw new DynamicError('WalletConnectProvider is not initialized');
95
- }
96
- logger.debug('[WalletConnect] getAddress - connecting to WalletConnect');
97
- const addresses = yield WalletConnectProvider.connect({
98
- connectionOpts: opts,
99
- deepLinkPreference: this.deepLinkPreference,
100
- deepLinks: this.metadata.deepLinks,
101
- });
102
- logger.debug('[WalletConnect] getAddress - connection result', addresses);
103
- const address = addresses === null || addresses === void 0 ? void 0 : addresses[0];
104
- this.setWCActiveAccount(address);
105
- return address;
106
- });
107
- }
108
- getWalletClient(chainId) {
109
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getWalletClient was called - chainId', chainId);
110
- const provider = WalletConnectProvider.getProvider();
111
- if (!provider) {
112
- logger.debug('[WalletConnect] getWalletClient - provider is not initialized');
113
- throw new DynamicError('WalletConnectProvider is not initialized');
114
- }
115
- const walletClient = createWalletClient({
116
- account: this.getActiveAccount(),
117
- chain: chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
118
- transport: custom({
119
- request: (args) => {
120
- this.deepLinkIfApplicable(args.method);
121
- return provider.request(args).catch(normalizeRpcError);
122
- },
123
- }),
124
- });
125
- return walletClient;
126
- }
127
- deepLinkIfApplicable(method) {
128
- const methodsThatRequireDeepLink = [
129
- 'personal_sign',
130
- 'eth_sendTransaction',
131
- 'eth_signTypedData_v4',
132
- ];
133
- const deepLink = this.getDeepLink();
134
- if (isMobile() && deepLink && methodsThatRequireDeepLink.includes(method)) {
135
- PlatformService.openURL(deepLink);
136
- }
137
- }
138
- signMessage(messageToSign) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- logger.logVerboseTroubleshootingMessage('[WalletConnect] signMessage', messageToSign);
141
- const activeAccount = this.getActiveAccount();
142
- logger.logVerboseTroubleshootingMessage('[WalletConnect] signMessage - activeAccount', activeAccount);
143
- if (!activeAccount) {
144
- return;
145
- }
146
- const walletClient = yield this.getWalletClient();
147
- return walletClient.signMessage({
148
- account: activeAccount,
149
- message: messageToSign,
150
- });
151
- });
152
- }
153
- getConnectedAccounts() {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- const activeAccount = this.getActiveAccount();
156
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getConnectedAccounts - activeAccount', activeAccount);
157
- return activeAccount ? [activeAccount.address] : [];
158
- });
159
- }
160
- setWCActiveAccount(account) {
161
- logger.logVerboseTroubleshootingMessage('[WalletConnect] setWCActiveAccount', account);
162
- if (account) {
163
- localStorage.setItem(WC_ACTIVE_ACCOUNT_KEY, account);
164
- this.setActiveAccount(account);
165
- this.emit('accountChange', { accounts: [account] });
166
- }
167
- else {
168
- localStorage.removeItem(WC_ACTIVE_ACCOUNT_KEY);
169
- this.setActiveAccount(undefined);
170
- }
171
- }
172
- get currentChainId() {
173
- const lsCurrentChain = localStorage.getItem(WC_CURRENT_CHAIN_KEY);
174
- try {
175
- return lsCurrentChain ? parseIntSafe(lsCurrentChain) : undefined;
176
- }
177
- catch (e) {
178
- logger.debug('[WalletConnect] getCurrentChainId - error', e);
179
- return undefined;
180
- }
181
- }
182
- set currentChainId(value) {
183
- if (value) {
184
- localStorage.setItem(WC_CURRENT_CHAIN_KEY, value.toString());
185
- }
186
- else {
187
- localStorage.removeItem(WC_CURRENT_CHAIN_KEY);
188
- }
189
- }
190
- getNetwork() {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork');
193
- const provider = WalletConnectProvider.getProvider();
194
- if (provider === null || provider === void 0 ? void 0 : provider.chainId) {
195
- const network = provider.chainId;
196
- this.currentChainId = network;
197
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork - provider network', network);
198
- return network;
199
- }
200
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork - no provider found, returning current chain id', {
201
- currentChainId: this.currentChainId,
202
- });
203
- return this.currentChainId;
204
- });
205
- }
206
- providerSwitchNetwork(_a) {
207
- const _super = Object.create(null, {
208
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
209
- });
210
- return __awaiter(this, arguments, void 0, function* ({ network, }) {
211
- logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - network', {
212
- network,
213
- switchNetworkOnlyFromWallet: this.switchNetworkOnlyFromWallet,
214
- });
215
- const currentNetworkId = yield this.getNetwork();
216
- logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - currentNetworkId', currentNetworkId);
217
- if (currentNetworkId && currentNetworkId === network.chainId) {
218
- return;
219
- }
220
- if (this.switchNetworkOnlyFromWallet) {
221
- throw new DynamicError('Network switching is only supported through the wallet');
222
- }
223
- const walletClient = yield this.getWalletClient();
224
- logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - will switch network');
225
- yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
226
- this.currentChainId = network.chainId;
227
- logger.logVerboseTroubleshootingMessage('[WalletConnect] providerSwitchNetwork - switched network', network.chainId);
228
- this.emit('chainChange', { chain: String(network.chainId) });
229
- });
230
- }
231
- supportsNetworkSwitching() {
232
- return true;
233
- }
234
- getSupportedNetworks() {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- var _a;
237
- const provider = WalletConnectProvider.getProvider();
238
- if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
239
- return [];
240
- }
241
- const chains = [];
242
- // Some wallet (i.e ZenGo) use namespaces.account to list supported chains
243
- // while others use keys within the namespaces object
244
- Object.keys(provider === null || provider === void 0 ? void 0 : provider.session.namespaces).forEach((key) => {
245
- if (key.startsWith('eip155:')) {
246
- chains.push(key.split(':')[1]);
247
- }
248
- });
249
- (_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]));
250
- return chains.length
251
- ? chains
252
- : this.evmNetworks.map((network) => network.chainId.toString());
253
- });
254
- }
255
- getDeepLink() {
256
- var _a;
257
- const provider = WalletConnectProvider.getProvider();
258
- logger.debug('[WalletConnect] getDeepLink', {
259
- hasSession: Boolean(provider === null || provider === void 0 ? void 0 : provider.session),
260
- topic: (_a = provider === null || provider === void 0 ? void 0 : provider.session) === null || _a === void 0 ? void 0 : _a.topic,
261
- uri: provider === null || provider === void 0 ? void 0 : provider.signer.uri,
262
- });
263
- if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
264
- return;
265
- }
266
- const deepLink = getDeepLink({
267
- deepLinks: this.metadata.deepLinks,
268
- mode: 'regular',
269
- preference: this.deepLinkPreference,
270
- uri: provider.signer.uri,
271
- });
272
- logger.logVerboseTroubleshootingMessage('[WalletConnect] getDeepLink - deepLink', deepLink);
273
- if (!deepLink) {
274
- return;
275
- }
276
- // we need to include the session topic here because it helps the wallet
277
- // auto redirect back to the dapp after signing
278
- return `${deepLink}?sessionTopic=${provider.session.topic}`;
279
- }
280
- }
281
-
282
- export { WalletConnectConnector };
@@ -1 +0,0 @@
1
- export { WalletConnectConnector } from './WalletConnectConnector';