@reown/appkit-adapter-ethers 1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0 → 1.8.15-viem-upgrade.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reown/appkit-adapter-ethers",
3
- "version": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
3
+ "version": "1.8.15-viem-upgrade.0",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "./dist/esm/src/index.js",
@@ -11,15 +11,15 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "@walletconnect/universal-provider": "2.23.0",
14
+ "@walletconnect/universal-provider": "2.23.1",
15
15
  "valtio": "2.1.7",
16
- "@reown/appkit": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
17
- "@reown/appkit-common": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
18
- "@reown/appkit-controllers": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
19
- "@reown/appkit-polyfills": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
20
- "@reown/appkit-scaffold-ui": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
21
- "@reown/appkit-utils": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0",
22
- "@reown/appkit-wallet": "1.8.15-e95f0d61c614677233e13ea9f055d3f75fcdba81.0"
16
+ "@reown/appkit": "1.8.15-viem-upgrade.0",
17
+ "@reown/appkit-common": "1.8.15-viem-upgrade.0",
18
+ "@reown/appkit-controllers": "1.8.15-viem-upgrade.0",
19
+ "@reown/appkit-polyfills": "1.8.15-viem-upgrade.0",
20
+ "@reown/appkit-scaffold-ui": "1.8.15-viem-upgrade.0",
21
+ "@reown/appkit-utils": "1.8.15-viem-upgrade.0",
22
+ "@reown/appkit-wallet": "1.8.15-viem-upgrade.0"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@ethersproject/sha2": "5.8.0",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@vitest/coverage-v8": "2.1.9",
30
- "@walletconnect/types": "2.23.0",
30
+ "@walletconnect/types": "2.23.1",
31
31
  "vitest": "2.1.9"
32
32
  },
33
33
  "author": "Reown (https://discord.gg/reown)",
@@ -1,612 +0,0 @@
1
- import UniversalProvider from '@walletconnect/universal-provider';
2
- import { JsonRpcProvider, formatEther, getAddress } from 'ethers';
3
- import { WcConstantsUtil } from '@reown/appkit';
4
- import { ConstantsUtil as CommonConstantsUtil, ErrorUtil, ParseUtil, UserRejectedRequestError } from '@reown/appkit-common';
5
- import { ConstantsUtil, PresetsUtil } from '@reown/appkit-common';
6
- import { AssetController, ChainController, ConnectorUtil, CoreHelperUtil, OptionsController, SIWXUtil, StorageUtil, WcHelpersUtil, getPreferredAccountType } from '@reown/appkit-controllers';
7
- import { AdapterBlueprint, ProviderController, WalletConnectConnector } from '@reown/appkit-controllers';
8
- import { HelpersUtil } from '@reown/appkit-utils';
9
- import { BaseProvider, EthersHelpersUtil, InjectedProvider, SafeProvider } from '@reown/appkit-utils/ethers';
10
- import { EthersMethods } from './utils/EthersMethods.js';
11
- export class EthersAdapter extends AdapterBlueprint {
12
- constructor() {
13
- super({
14
- adapterType: CommonConstantsUtil.ADAPTER_TYPES.ETHERS,
15
- namespace: CommonConstantsUtil.CHAIN.EVM
16
- });
17
- this.balancePromises = {};
18
- this.ethersProviders = {};
19
- }
20
- async createEthersConfig() {
21
- const { metadata, enableCoinbase, enableInjected, enableEIP6963 } = OptionsController.state;
22
- if (!metadata) {
23
- return undefined;
24
- }
25
- if (enableInjected !== false) {
26
- const injectedProvider = new InjectedProvider();
27
- await injectedProvider.initialize();
28
- this.ethersProviders.injected = injectedProvider;
29
- }
30
- if (enableCoinbase !== false) {
31
- this.ethersProviders.baseAccount = new BaseProvider();
32
- }
33
- if (CoreHelperUtil.isSafeApp()) {
34
- const safeProvider = new SafeProvider();
35
- await safeProvider.initialize();
36
- this.ethersProviders.safe = safeProvider;
37
- }
38
- return {
39
- ...this.ethersProviders,
40
- EIP6963: enableEIP6963 !== false,
41
- metadata
42
- };
43
- }
44
- async signMessage(params) {
45
- const { message, address, provider } = params;
46
- if (!provider) {
47
- throw new Error('Provider is undefined');
48
- }
49
- try {
50
- const signature = await EthersMethods.signMessage(message, provider, address);
51
- return { signature };
52
- }
53
- catch (error) {
54
- throw new Error('EthersAdapter:signMessage - Sign message failed');
55
- }
56
- }
57
- async sendTransaction(params) {
58
- if (!params.provider) {
59
- throw new Error('Provider is undefined');
60
- }
61
- const address = ChainController.getAccountData(CommonConstantsUtil.CHAIN.EVM)?.address;
62
- if (!address) {
63
- throw new Error('Address is undefined');
64
- }
65
- const tx = await EthersMethods.sendTransaction({
66
- value: Number.isNaN(Number(params.value)) ? BigInt(0) : BigInt(params.value),
67
- to: params.to,
68
- data: params.data ? params.data : '0x',
69
- gas: params.gas ? BigInt(params.gas) : undefined,
70
- gasPrice: params.gasPrice ? BigInt(params.gasPrice) : undefined,
71
- address: address
72
- }, params.provider, address, Number(params.caipNetwork?.id));
73
- return { hash: tx };
74
- }
75
- async writeContract(params) {
76
- if (!params.provider) {
77
- throw new Error('Provider is undefined');
78
- }
79
- const { address } = ParseUtil.parseCaipAddress(params.caipAddress);
80
- const result = await EthersMethods.writeContract(params, params.provider, address, Number(params.caipNetwork?.id));
81
- return { hash: result };
82
- }
83
- async estimateGas(params) {
84
- const { provider, caipNetwork, address } = params;
85
- if (!provider) {
86
- throw new Error('Provider is undefined');
87
- }
88
- try {
89
- const result = await EthersMethods.estimateGas({
90
- data: params.data,
91
- to: params.to,
92
- address: address
93
- }, provider, address, Number(caipNetwork?.id));
94
- return { gas: result };
95
- }
96
- catch (error) {
97
- throw new Error('EthersAdapter:estimateGas - Estimate gas failed');
98
- }
99
- }
100
- parseUnits(params) {
101
- return EthersMethods.parseUnits(params.value, params.decimals);
102
- }
103
- formatUnits(params) {
104
- return EthersMethods.formatUnits(params.value, params.decimals);
105
- }
106
- async syncConnection(params) {
107
- const { id, chainId } = params;
108
- const connector = this.connectors.find(c => c.id === id);
109
- const selectedProvider = connector?.provider;
110
- if (!selectedProvider) {
111
- throw new Error('Provider not found');
112
- }
113
- const accounts = await selectedProvider.request({
114
- method: 'eth_requestAccounts'
115
- });
116
- const requestChainId = await selectedProvider.request({
117
- method: 'eth_chainId'
118
- });
119
- this.listenProviderEvents(id, selectedProvider);
120
- if (!accounts[0]) {
121
- throw new Error('No accounts found');
122
- }
123
- if (!connector?.type) {
124
- throw new Error('Connector type not found');
125
- }
126
- return {
127
- address: this.toChecksummedAddress(accounts[0]),
128
- chainId: Number(requestChainId) || Number(chainId),
129
- provider: selectedProvider,
130
- type: connector.type,
131
- id
132
- };
133
- }
134
- async syncConnectors() {
135
- this.ethersConfig = await this.createEthersConfig();
136
- if (this.ethersConfig?.EIP6963) {
137
- this.listenInjectedConnector(true);
138
- }
139
- const connectors = Object.keys(this.ethersConfig || {}).filter(key => key !== 'metadata' && key !== 'EIP6963');
140
- const connectorPromises = connectors.map(async (connector) => {
141
- const isInjectedConnector = connector === CommonConstantsUtil.CONNECTOR_ID.INJECTED;
142
- if (this.namespace) {
143
- const provider = this.ethersProviders[connector];
144
- this.addConnector({
145
- id: connector,
146
- explorerId: PresetsUtil.ConnectorExplorerIds[connector],
147
- imageUrl: AssetController.state.connectorImages?.[connector],
148
- name: PresetsUtil.ConnectorNamesMap[connector] || 'Unknown',
149
- imageId: PresetsUtil.ConnectorImageIds[connector],
150
- type: PresetsUtil.ConnectorTypesMap[connector] ?? 'EXTERNAL',
151
- info: isInjectedConnector ? undefined : { rdns: connector },
152
- chain: this.namespace,
153
- chains: [],
154
- provider: (await provider?.getProvider())
155
- });
156
- }
157
- });
158
- await Promise.all(connectorPromises);
159
- }
160
- async disconnectAll() {
161
- const connections = await Promise.all(this.connections.map(async (connection) => {
162
- const connector = this.connectors.find(c => HelpersUtil.isLowerCaseMatch(c.id, connection.connectorId));
163
- if (!connector) {
164
- throw new Error('Connector not found');
165
- }
166
- await this.disconnect({
167
- id: connector.id
168
- });
169
- return connection;
170
- }));
171
- return { connections };
172
- }
173
- async syncConnections({ connectToFirstConnector }) {
174
- const caipNetworks = this.getCaipNetworks();
175
- await Promise.all(this.connectors
176
- .filter(c => {
177
- const { hasDisconnected, hasConnected } = HelpersUtil.getConnectorStorageInfo(c.id, this.namespace);
178
- return !hasDisconnected && hasConnected;
179
- })
180
- .map(async (connector) => {
181
- if (connector.id === CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT) {
182
- const accounts = WcHelpersUtil.getWalletConnectAccounts(this.universalProvider, this.namespace);
183
- const caipNetwork = caipNetworks.find(n => n.chainNamespace === this.namespace &&
184
- n.id.toString() === accounts[0]?.chainId?.toString());
185
- if (accounts.length > 0) {
186
- this.addConnection({
187
- connectorId: connector.id,
188
- accounts: accounts.map(account => ({ address: account.address })),
189
- caipNetwork
190
- });
191
- }
192
- }
193
- else {
194
- const { accounts, chainId } = await ConnectorUtil.fetchProviderData(connector);
195
- if (accounts.length > 0 && chainId) {
196
- const caipNetwork = caipNetworks.find(n => n.chainNamespace === this.namespace && n.id.toString() === chainId.toString());
197
- this.addConnection({
198
- connectorId: connector.id,
199
- accounts: accounts.map(address => ({ address })),
200
- caipNetwork
201
- });
202
- if (connector.provider &&
203
- connector.id !== CommonConstantsUtil.CONNECTOR_ID.AUTH &&
204
- connector.id !== CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT) {
205
- this.listenProviderEvents(connector.id, connector.provider);
206
- }
207
- }
208
- }
209
- }));
210
- if (connectToFirstConnector) {
211
- this.emitFirstAvailableConnection();
212
- }
213
- }
214
- async setUniversalProvider(universalProvider) {
215
- this.universalProvider = universalProvider;
216
- const wcConnectorId = CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
217
- WcHelpersUtil.listenWcProvider({
218
- universalProvider,
219
- namespace: CommonConstantsUtil.CHAIN.EVM,
220
- onConnect: accounts => this.onConnect(accounts, wcConnectorId),
221
- onDisconnect: () => this.onDisconnect(wcConnectorId),
222
- onAccountsChanged: accounts => this.onAccountsChanged(accounts, wcConnectorId, false),
223
- onChainChanged: chainId => this.onChainChanged(chainId, wcConnectorId)
224
- });
225
- this.addConnector(new WalletConnectConnector({
226
- provider: universalProvider,
227
- caipNetworks: this.getCaipNetworks(),
228
- namespace: CommonConstantsUtil.CHAIN.EVM
229
- }));
230
- return Promise.resolve();
231
- }
232
- eip6963EventHandler(event) {
233
- if (event.detail) {
234
- const { info, provider } = event.detail;
235
- const existingConnector = this.connectors?.find(c => c.name === info?.name);
236
- if (!existingConnector) {
237
- const type = PresetsUtil.ConnectorTypesMap[CommonConstantsUtil.CONNECTOR_ID.EIP6963];
238
- const id = info?.rdns || info?.name || info?.uuid;
239
- if (type && this.namespace && id) {
240
- this.addConnector({
241
- id,
242
- type,
243
- explorerId: PresetsUtil.ConnectorExplorerIds[info.rdns || ''] ??
244
- PresetsUtil.ConnectorExplorerIds[info.name || ''],
245
- imageUrl: info?.icon,
246
- name: info?.name || 'Unknown',
247
- provider,
248
- info,
249
- chain: this.namespace,
250
- chains: []
251
- });
252
- }
253
- }
254
- }
255
- }
256
- listenInjectedConnector(enableEIP6963) {
257
- if (typeof window !== 'undefined' && enableEIP6963) {
258
- const handler = this.eip6963EventHandler.bind(this);
259
- window.addEventListener(ConstantsUtil.EIP6963_ANNOUNCE_EVENT, handler);
260
- window.dispatchEvent(new Event(ConstantsUtil.EIP6963_REQUEST_EVENT));
261
- }
262
- }
263
- async connect({ id, address, type, chainId, socialUri }) {
264
- try {
265
- const connector = this.connectors.find(c => HelpersUtil.isLowerCaseMatch(c.id, id));
266
- if (!connector) {
267
- throw new Error('Connector not found');
268
- }
269
- const connection = this.getConnection({
270
- address,
271
- connectorId: id,
272
- connections: this.connections,
273
- connectors: this.connectors
274
- });
275
- if (connection) {
276
- const caipNetwork = connection.caipNetwork;
277
- if (!caipNetwork) {
278
- throw new Error('EthersAdapter:connect - could not find the caipNetwork to connect');
279
- }
280
- if (connection.account) {
281
- this.emit('accountChanged', {
282
- address: this.toChecksummedAddress(connection.account.address),
283
- chainId: caipNetwork.id,
284
- connector
285
- });
286
- return {
287
- address: this.toChecksummedAddress(connection.account.address),
288
- chainId: caipNetwork.id,
289
- provider: connector.provider,
290
- type: connector.type,
291
- id
292
- };
293
- }
294
- }
295
- let selectedProvider = connector?.provider;
296
- const ethersProvider = this.ethersProviders[connector.id];
297
- if (ethersProvider) {
298
- await ethersProvider.initialize();
299
- selectedProvider = (await ethersProvider.getProvider());
300
- }
301
- if (!selectedProvider) {
302
- throw new Error('Provider not found');
303
- }
304
- connector.provider = selectedProvider;
305
- let accounts = [];
306
- let requestChainId = undefined;
307
- if (type === ConstantsUtil.CONNECTOR_TYPE_AUTH) {
308
- const { address: _address, accounts: authAccounts } = await SIWXUtil.authConnectorAuthenticate({
309
- authConnector: selectedProvider,
310
- chainNamespace: CommonConstantsUtil.CHAIN.EVM,
311
- chainId,
312
- socialUri,
313
- preferredAccountType: getPreferredAccountType('eip155')
314
- });
315
- const caipNetwork = this.getCaipNetworks().find(n => n.id.toString() === chainId?.toString());
316
- accounts = [_address];
317
- this.addConnection({
318
- connectorId: id,
319
- accounts: authAccounts
320
- ? authAccounts.map(account => ({ address: account.address }))
321
- : accounts.map(account => ({ address: account })),
322
- caipNetwork,
323
- auth: {
324
- name: StorageUtil.getConnectedSocialProvider(),
325
- username: StorageUtil.getConnectedSocialUsername()
326
- }
327
- });
328
- this.emit('accountChanged', {
329
- address: this.toChecksummedAddress(accounts[0]),
330
- chainId: Number(chainId),
331
- connector
332
- });
333
- }
334
- else {
335
- accounts = await selectedProvider.request({
336
- method: 'eth_requestAccounts'
337
- });
338
- requestChainId = await selectedProvider.request({
339
- method: 'eth_chainId'
340
- });
341
- const caipNetwork = this.getCaipNetworks().find(n => n.id.toString() === chainId?.toString());
342
- if (requestChainId !== chainId) {
343
- if (!caipNetwork) {
344
- throw new Error('EthersAdapter:connect - could not find the caipNetwork to switch');
345
- }
346
- try {
347
- await selectedProvider?.request({
348
- method: 'wallet_switchEthereumChain',
349
- params: [{ chainId: EthersHelpersUtil.numberToHexString(caipNetwork.id) }]
350
- });
351
- }
352
- catch (error) {
353
- throw new Error('EthersAdapter:connect - Switch network failed');
354
- }
355
- }
356
- this.emit('accountChanged', {
357
- address: this.toChecksummedAddress(accounts[0]),
358
- chainId: Number(chainId),
359
- connector
360
- });
361
- this.addConnection({
362
- connectorId: id,
363
- accounts: accounts.map(account => ({ address: account })),
364
- caipNetwork
365
- });
366
- if (connector.id !== CommonConstantsUtil.CONNECTOR_ID.WALLET_CONNECT) {
367
- this.listenProviderEvents(id, selectedProvider);
368
- }
369
- }
370
- return {
371
- address: this.toChecksummedAddress(accounts[0]),
372
- chainId: Number(chainId),
373
- provider: selectedProvider,
374
- type: type,
375
- id
376
- };
377
- }
378
- catch (err) {
379
- if (ErrorUtil.isUserRejectedRequestError(err)) {
380
- throw new UserRejectedRequestError(err);
381
- }
382
- throw err;
383
- }
384
- }
385
- async reconnect(params) {
386
- const { id, chainId } = params;
387
- const connector = this.connectors.find(c => c.id === id);
388
- if (connector && connector.type === 'AUTH' && chainId) {
389
- await SIWXUtil.authConnectorAuthenticate({
390
- authConnector: connector.provider,
391
- chainNamespace: CommonConstantsUtil.CHAIN.EVM,
392
- chainId,
393
- preferredAccountType: getPreferredAccountType('eip155')
394
- });
395
- }
396
- }
397
- async getAccounts(params) {
398
- const connector = this.connectors.find(c => c.id === params.id);
399
- const selectedProvider = connector?.provider;
400
- if (!selectedProvider || !connector) {
401
- throw new Error('Provider not found');
402
- }
403
- const connection = this.getConnection({
404
- connectorId: params.id,
405
- connections: this.connections,
406
- connectors: this.connectors
407
- });
408
- if (connection) {
409
- return {
410
- accounts: connection.accounts.map(({ address }) => CoreHelperUtil.createAccount(CommonConstantsUtil.CHAIN.EVM, address, 'eoa'))
411
- };
412
- }
413
- if (params.id === CommonConstantsUtil.CONNECTOR_ID.AUTH) {
414
- const provider = connector['provider'];
415
- if (!provider.user) {
416
- return { accounts: [] };
417
- }
418
- const { accounts, address } = provider.user;
419
- return Promise.resolve({
420
- accounts: (accounts || [{ address, type: 'eoa' }]).map(account => CoreHelperUtil.createAccount(CommonConstantsUtil.CHAIN.EVM, account.address, account.type))
421
- });
422
- }
423
- const accounts = await selectedProvider.request({
424
- method: 'eth_requestAccounts'
425
- });
426
- return {
427
- accounts: accounts.map(account => CoreHelperUtil.createAccount(CommonConstantsUtil.CHAIN.EVM, account, 'eoa'))
428
- };
429
- }
430
- async disconnect(params) {
431
- if (params.id) {
432
- const connector = this.connectors.find(c => HelpersUtil.isLowerCaseMatch(c.id, params.id));
433
- if (!connector) {
434
- throw new Error('Connector not found');
435
- }
436
- const connection = this.getConnection({
437
- connectorId: params.id,
438
- connections: this.connections,
439
- connectors: this.connectors
440
- });
441
- switch (connector.type) {
442
- case ConstantsUtil.CONNECTOR_TYPE_WALLET_CONNECT:
443
- if (connector.provider.session) {
444
- ;
445
- connector.provider.disconnect();
446
- }
447
- break;
448
- case ConstantsUtil.CONNECTOR_TYPE_AUTH:
449
- await connector.provider?.disconnect();
450
- break;
451
- case ConstantsUtil.CONNECTOR_TYPE_ANNOUNCED:
452
- case ConstantsUtil.CONNECTOR_TYPE_EXTERNAL:
453
- await this.revokeProviderPermissions(connector.provider);
454
- break;
455
- default:
456
- throw new Error('Unsupported provider type');
457
- }
458
- if (connector.id) {
459
- this.removeProviderListeners(connector.id);
460
- this.deleteConnection(connector.id);
461
- }
462
- if (this.connections.length === 0) {
463
- this.emit('disconnect');
464
- }
465
- else {
466
- this.emitFirstAvailableConnection();
467
- }
468
- return { connections: connection ? [connection] : [] };
469
- }
470
- return this.disconnectAll();
471
- }
472
- async getBalance(params) {
473
- const address = params.address;
474
- const caipNetwork = this.getCaipNetworks().find(network => network.id.toString() === params.chainId?.toString());
475
- if (!address) {
476
- return Promise.resolve({ balance: '0.00', symbol: 'ETH' });
477
- }
478
- if (caipNetwork && caipNetwork.chainNamespace === CommonConstantsUtil.CHAIN.EVM) {
479
- const caipAddress = `${caipNetwork.caipNetworkId}:${address}`;
480
- const cachedPromise = this.balancePromises[caipAddress];
481
- if (cachedPromise) {
482
- return cachedPromise;
483
- }
484
- const cachedBalance = StorageUtil.getNativeBalanceCacheForCaipAddress(caipAddress);
485
- if (cachedBalance) {
486
- return { balance: cachedBalance.balance, symbol: cachedBalance.symbol };
487
- }
488
- const jsonRpcProvider = new JsonRpcProvider(caipNetwork.rpcUrls.default.http[0], {
489
- chainId: caipNetwork.id,
490
- name: caipNetwork.name
491
- });
492
- if (jsonRpcProvider) {
493
- try {
494
- this.balancePromises[caipAddress] = new Promise(async (resolve) => {
495
- try {
496
- const balance = await jsonRpcProvider.getBalance(address);
497
- const formattedBalance = formatEther(balance);
498
- StorageUtil.updateNativeBalanceCache({
499
- caipAddress,
500
- balance: formattedBalance,
501
- symbol: caipNetwork.nativeCurrency.symbol,
502
- timestamp: Date.now()
503
- });
504
- resolve({ balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol });
505
- }
506
- catch (error) {
507
- resolve({ balance: '0.00', symbol: 'ETH' });
508
- }
509
- }).finally(() => {
510
- delete this.balancePromises[caipAddress];
511
- });
512
- return this.balancePromises[caipAddress] || { balance: '0.00', symbol: 'ETH' };
513
- }
514
- catch (error) {
515
- return { balance: '0.00', symbol: 'ETH' };
516
- }
517
- }
518
- }
519
- return { balance: '0.00', symbol: 'ETH' };
520
- }
521
- async switchNetwork(params) {
522
- const { caipNetwork } = params;
523
- const providerType = ProviderController.getProviderId(caipNetwork.chainNamespace);
524
- const provider = ProviderController.getProvider(caipNetwork.chainNamespace);
525
- if (providerType === 'AUTH' || providerType === 'WALLET_CONNECT') {
526
- await super.switchNetwork(params);
527
- return;
528
- }
529
- if (!provider) {
530
- throw new Error('Provider not found');
531
- }
532
- try {
533
- await provider?.request({
534
- method: 'wallet_switchEthereumChain',
535
- params: [{ chainId: EthersHelpersUtil.numberToHexString(caipNetwork.id) }]
536
- });
537
- }
538
- catch (switchError) {
539
- if (switchError.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID ||
540
- switchError.code === WcConstantsUtil.ERROR_INVALID_CHAIN_ID ||
541
- switchError.code === WcConstantsUtil.ERROR_CODE_DEFAULT ||
542
- switchError?.data?.originalError?.code === WcConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID) {
543
- await EthersHelpersUtil.addEthereumChain(provider, caipNetwork);
544
- }
545
- else if (providerType === 'ANNOUNCED' ||
546
- providerType === 'EXTERNAL' ||
547
- providerType === 'INJECTED') {
548
- throw new Error('Chain is not supported');
549
- }
550
- }
551
- }
552
- getWalletConnectProvider() {
553
- return this.connectors.find(c => c.type === 'WALLET_CONNECT')?.provider;
554
- }
555
- async revokeProviderPermissions(provider) {
556
- try {
557
- const permissions = await provider.request({
558
- method: 'wallet_getPermissions'
559
- });
560
- const ethAccountsPermission = permissions.find(permission => permission.parentCapability === 'eth_accounts');
561
- if (ethAccountsPermission) {
562
- await provider.request({
563
- method: 'wallet_revokePermissions',
564
- params: [{ eth_accounts: {} }]
565
- });
566
- }
567
- }
568
- catch (error) {
569
- console.info('Could not revoke permissions from wallet. Disconnecting...', error);
570
- }
571
- }
572
- async getCapabilities(params) {
573
- const provider = ProviderController.getProvider(CommonConstantsUtil.CHAIN.EVM);
574
- if (!provider) {
575
- throw new Error('Provider is undefined');
576
- }
577
- return await provider.request({ method: 'wallet_getCapabilities', params: [params] });
578
- }
579
- async grantPermissions(params) {
580
- const provider = ProviderController.getProvider(CommonConstantsUtil.CHAIN.EVM);
581
- if (!provider) {
582
- throw new Error('Provider is undefined');
583
- }
584
- return await provider.request({ method: 'wallet_grantPermissions', params });
585
- }
586
- async revokePermissions(params) {
587
- const provider = ProviderController.getProvider(CommonConstantsUtil.CHAIN.EVM);
588
- if (!provider) {
589
- throw new Error('Provider is undefined');
590
- }
591
- return await provider.request({ method: 'wallet_revokePermissions', params: [params] });
592
- }
593
- async walletGetAssets(params) {
594
- const provider = ProviderController.getProvider(CommonConstantsUtil.CHAIN.EVM);
595
- if (!provider) {
596
- throw new Error('Provider is undefined');
597
- }
598
- return await provider.request({
599
- method: 'wallet_getAssets',
600
- params: [params]
601
- });
602
- }
603
- toChecksummedAddress(address) {
604
- try {
605
- return getAddress(address.toLowerCase());
606
- }
607
- catch {
608
- return address;
609
- }
610
- }
611
- }
612
- //# sourceMappingURL=client.js.map