@reown/appkit-adapter-wagmi 1.7.2-rc2 → 1.7.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.
@@ -1,688 +0,0 @@
1
- import { estimateGas, getAccount, getBalance, getConnections, getEnsAvatar, getEnsName, http, signMessage, switchChain, getEnsAddress as wagmiGetEnsAddress, sendTransaction as wagmiSendTransaction, writeContract as wagmiWriteContract, waitForTransactionReceipt, watchAccount, watchPendingTransactions } from '@wagmi/core';
2
- import * as wagmiCore from '@wagmi/core';
3
- import { mainnet } from '@wagmi/core/chains';
4
- import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
5
- import { ConstantsUtil } from '@reown/appkit-common';
6
- import { CaipNetworksUtil } from '@reown/appkit-utils';
7
- import { WagmiAdapter } from '../client';
8
- import { LimitterUtil } from '../utils/LimitterUtil';
9
- import { mockAppKit } from './mocks/AppKit';
10
- vi.mock('@wagmi/core', async () => {
11
- const actual = await vi.importActual('@wagmi/core');
12
- return {
13
- ...actual,
14
- addConnector: vi.fn(),
15
- connect: vi.fn(() => mockConnect()),
16
- disconnect: vi.fn(),
17
- createConfig: vi.fn(() => mockWagmiConfig),
18
- getConnections: vi.fn(),
19
- switchChain: vi.fn(),
20
- getBalance: vi.fn(),
21
- getEnsName: vi.fn(),
22
- getEnsAvatar: vi.fn(),
23
- signMessage: vi.fn(),
24
- estimateGas: vi.fn(),
25
- sendTransaction: vi.fn(),
26
- getEnsAddress: vi.fn(),
27
- writeContract: vi.fn(),
28
- waitForTransactionReceipt: vi.fn(),
29
- getAccount: vi.fn(),
30
- prepareTransactionRequest: vi.fn(),
31
- reconnect: vi.fn(),
32
- watchAccount: vi.fn(),
33
- watchConnections: vi.fn(),
34
- watchPendingTransactions: vi.fn().mockReturnValue(vi.fn())
35
- };
36
- });
37
- const mockProjectId = 'test-project-id';
38
- const mockNetworks = [mainnet];
39
- const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
40
- projectId: mockProjectId,
41
- customNetworkImageUrls: {}
42
- });
43
- const mockWagmiConfig = {
44
- connectors: [
45
- {
46
- id: 'test-connector',
47
- getProvider() {
48
- return Promise.resolve({ connect: vi.fn(), request: vi.fn() });
49
- }
50
- }
51
- ],
52
- _internal: {
53
- connectors: {
54
- setup: vi.fn(),
55
- setState: vi.fn()
56
- }
57
- }
58
- };
59
- const mockConnect = vi.fn(() => ({
60
- chainId: 1,
61
- address: '0x123',
62
- accounts: ['0x123']
63
- }));
64
- describe('WagmiAdapter', () => {
65
- let adapter;
66
- beforeEach(() => {
67
- vi.clearAllMocks();
68
- adapter = new WagmiAdapter({
69
- networks: mockNetworks,
70
- projectId: mockProjectId
71
- });
72
- });
73
- describe('WagmiAdapter - constructor and initialization', () => {
74
- it('should initialize with correct parameters', () => {
75
- expect(adapter.projectId).toBe(mockProjectId);
76
- expect(adapter.adapterType).toBe(ConstantsUtil.ADAPTER_TYPES.WAGMI);
77
- expect(adapter.namespace).toBe(ConstantsUtil.CHAIN.EVM);
78
- });
79
- it('should set wagmi connectors', async () => {
80
- vi.spyOn(wagmiCore, 'watchConnectors').mockImplementation(vi.fn());
81
- vi.spyOn(wagmiCore, 'watchConnectors');
82
- await adapter.syncConnectors({ networks: [mainnet], projectId: 'YOUR_PROJECT_ID' }, mockAppKit);
83
- expect(wagmiCore.watchConnectors).toHaveBeenCalledOnce();
84
- expect(adapter.connectors).toStrictEqual([
85
- {
86
- chain: 'eip155',
87
- chains: [],
88
- explorerId: undefined,
89
- id: 'test-connector',
90
- imageId: undefined,
91
- imageUrl: undefined,
92
- info: { rdns: 'test-connector' },
93
- provider: {
94
- connect: expect.any(Function),
95
- request: expect.any(Function)
96
- },
97
- name: undefined,
98
- type: 'EXTERNAL'
99
- }
100
- ]);
101
- });
102
- it('should not set info property for injected connector', () => {
103
- const mockConnectors = [
104
- {
105
- id: 'Browser Wallet',
106
- name: 'Browser Wallet',
107
- type: 'injected',
108
- info: { rdns: 'Browser Wallet' }
109
- }
110
- ];
111
- adapter.syncConnectors(mockConnectors);
112
- const injectedConnector = mockConnectors.filter((c) => c.id === 'injected')[0];
113
- expect(injectedConnector?.info).toBeUndefined();
114
- });
115
- it('should return reown RPC by default', () => {
116
- expect(adapter.wagmiChains?.[0].rpcUrls.default.http[0]).toBe(`https://rpc.walletconnect.org/v1/?chainId=eip155%3A1&projectId=${mockProjectId}`);
117
- });
118
- it('should return custom RPC if transports is provided', () => {
119
- const adapterWithCustomRpc = new WagmiAdapter({
120
- networks: mockNetworks,
121
- projectId: mockProjectId,
122
- transports: {
123
- [mainnet.id]: http('https://eth.merkle.io')
124
- }
125
- });
126
- expect(adapterWithCustomRpc.wagmiChains?.[0].rpcUrls.default.http[0]).toBe('https://rpc.walletconnect.org/v1/?chainId=eip155%3A1&projectId=test-project-id');
127
- });
128
- it('should add connector with provider', async () => {
129
- const mockConnector = {
130
- id: 'injected',
131
- name: 'Injected Wallet',
132
- type: 'injected',
133
- getProvider() {
134
- return Promise.resolve({ connect: vi.fn(), request: vi.fn() });
135
- }
136
- };
137
- await adapter.addWagmiConnector(mockConnector);
138
- expect(adapter.connectors).toStrictEqual([
139
- {
140
- chain: 'eip155',
141
- chains: [],
142
- explorerId: undefined,
143
- id: 'injected',
144
- imageId: '07ba87ed-43aa-4adf-4540-9e6a2b9cae00',
145
- imageUrl: undefined,
146
- info: undefined,
147
- name: 'Browser Wallet',
148
- provider: {
149
- connect: expect.any(Function),
150
- request: expect.any(Function)
151
- },
152
- type: 'INJECTED'
153
- }
154
- ]);
155
- });
156
- });
157
- describe('WagmiAdapter - signMessage', () => {
158
- it('should sign a message successfully', async () => {
159
- const mockSignature = '0xmocksignature';
160
- vi.mocked(signMessage).mockResolvedValueOnce(mockSignature);
161
- const result = await adapter.signMessage({
162
- message: 'Hello',
163
- address: '0x123'
164
- });
165
- expect(result.signature).toBe(mockSignature);
166
- });
167
- });
168
- describe('WagmiAdapter - sendTransaction', () => {
169
- it('should send transaction successfully', async () => {
170
- const mockTxHash = '0xtxhash';
171
- vi.mocked(getAccount).mockReturnValue({
172
- chainId: 1,
173
- address: '0x123',
174
- addresses: [],
175
- chain: mainnet,
176
- connector: {},
177
- isConnected: true,
178
- isReconnecting: true,
179
- isConnecting: false,
180
- isDisconnected: false,
181
- status: 'reconnecting'
182
- });
183
- vi.mocked(wagmiSendTransaction).mockResolvedValue(mockTxHash);
184
- vi.mocked(waitForTransactionReceipt).mockResolvedValue({});
185
- const result = await adapter.sendTransaction({
186
- address: '0x123',
187
- to: '0x456',
188
- value: BigInt(1000),
189
- gas: BigInt(21000),
190
- gasPrice: BigInt(2000000000),
191
- data: '0x'
192
- });
193
- expect(result.hash).toBe(mockTxHash);
194
- });
195
- });
196
- describe('writeContract', () => {
197
- it('should write contract successfully', async () => {
198
- const mockTxHash = '0xtxhash';
199
- vi.mocked(wagmiWriteContract).mockResolvedValue(mockTxHash);
200
- const result = await adapter.writeContract({
201
- caipNetwork: mockCaipNetworks[0],
202
- caipAddress: 'eip155:1:0x123',
203
- tokenAddress: '0x123',
204
- fromAddress: '0x456',
205
- args: ['0x789', BigInt(1000)],
206
- abi: [],
207
- method: 'transfer',
208
- chainNamespace: 'eip155'
209
- });
210
- expect(result.hash).toBe(mockTxHash);
211
- });
212
- });
213
- describe('WagmiAdapter - getEnsAddress', () => {
214
- it('should resolve ENS address successfully', async () => {
215
- const mockAddress = '0x123';
216
- vi.mocked(wagmiGetEnsAddress).mockResolvedValue(mockAddress);
217
- const result = await adapter.getEnsAddress({
218
- name: 'test.eth',
219
- caipNetwork: mockCaipNetworks[0]
220
- });
221
- expect(result.address).toBe(mockAddress);
222
- });
223
- it('should return false for unresolvable ENS', async () => {
224
- vi.mocked(wagmiGetEnsAddress).mockResolvedValue(null);
225
- const result = await adapter.getEnsAddress({
226
- name: 'nonexistent.eth',
227
- caipNetwork: mockCaipNetworks[0]
228
- });
229
- expect(result.address).toBe(false);
230
- });
231
- });
232
- describe('WagmiAdapter - estimateGas', () => {
233
- it('should estimate gas successfully', async () => {
234
- const mockGas = BigInt(21000);
235
- vi.mocked(estimateGas).mockResolvedValue(mockGas);
236
- const result = await adapter.estimateGas({
237
- address: '0x123',
238
- to: '0x456',
239
- data: '0x',
240
- caipNetwork: mockCaipNetworks[0]
241
- });
242
- expect(result.gas).toBe(mockGas);
243
- });
244
- it('should throw error when estimation fails', async () => {
245
- vi.mocked(estimateGas).mockRejectedValue(new Error());
246
- await expect(adapter.estimateGas({
247
- address: '0x123',
248
- to: '0x456',
249
- data: '0x',
250
- caipNetwork: mockCaipNetworks[0]
251
- })).rejects.toThrow('WagmiAdapter:estimateGas - error estimating gas');
252
- });
253
- });
254
- describe('WagmiAdapter - parseUnits and formatUnits', () => {
255
- it('should parse units correctly', () => {
256
- const result = adapter.parseUnits({
257
- value: '1.5',
258
- decimals: 18
259
- });
260
- expect(result).toBe(BigInt('1500000000000000000'));
261
- });
262
- it('should format units correctly', () => {
263
- const result = adapter.formatUnits({
264
- value: BigInt('1500000000000000000'),
265
- decimals: 18
266
- });
267
- expect(result).toBe('1.5');
268
- });
269
- });
270
- describe('WagmiAdapter - getBalance', () => {
271
- it('should get balance successfully', async () => {
272
- vi.mocked(getBalance).mockResolvedValue({
273
- formatted: '1.5',
274
- symbol: 'ETH'
275
- });
276
- const result = await adapter.getBalance({
277
- address: '0x123',
278
- chainId: 1
279
- });
280
- expect(result).toEqual({
281
- balance: '1.5',
282
- symbol: 'ETH'
283
- });
284
- });
285
- it('should call getBalance once even when multiple adapter requests are sent at the same time', async () => {
286
- const latency = 1000;
287
- const numSimultaneousRequests = 10;
288
- const expectedSentRequests = 1;
289
- vi.mocked(getBalance).mockResolvedValue(new Promise(resolve => {
290
- setTimeout(() => {
291
- resolve({
292
- formatted: '1.5',
293
- symbol: 'ETH'
294
- });
295
- }, latency);
296
- }));
297
- const result = await Promise.all([
298
- ...Array.from({ length: numSimultaneousRequests }).map(() => adapter.getBalance({
299
- address: '0x123',
300
- chainId: 1
301
- }))
302
- ]);
303
- expect(getBalance).toHaveBeenCalledTimes(expectedSentRequests);
304
- expect(result.length).toBe(numSimultaneousRequests);
305
- expect(expectedSentRequests).to.be.lt(numSimultaneousRequests);
306
- for (const balance of result) {
307
- expect(balance).toEqual({
308
- balance: '1.5',
309
- symbol: 'ETH'
310
- });
311
- }
312
- });
313
- it('should return empty balance when network not found', async () => {
314
- const result = await adapter.getBalance({
315
- address: '0x123',
316
- chainId: 999
317
- });
318
- expect(result).toEqual({
319
- balance: '',
320
- symbol: ''
321
- });
322
- });
323
- });
324
- describe('WagmiAdapter - getProfile', () => {
325
- it('should get profile successfully', async () => {
326
- const mockEnsName = 'test.eth';
327
- const mockAvatar = 'https://avatar.com/test.jpg';
328
- vi.mocked(getEnsName).mockResolvedValue(mockEnsName);
329
- vi.mocked(getEnsAvatar).mockResolvedValue(mockAvatar);
330
- const result = await adapter.getProfile({
331
- address: '0x123',
332
- chainId: 1
333
- });
334
- expect(result).toEqual({
335
- profileName: mockEnsName,
336
- profileImage: mockAvatar
337
- });
338
- });
339
- });
340
- describe('WagmiAdapter - connect and disconnect', () => {
341
- it('should connect successfully', async () => {
342
- const result = await adapter.connect({
343
- id: 'test-connector',
344
- provider: {},
345
- type: 'injected',
346
- chainId: 1
347
- });
348
- expect(result.address).toBe('0x123');
349
- expect(result.chainId).toBe(1);
350
- });
351
- it('should disconnect successfully', async () => {
352
- const mockConnections = [
353
- { connector: { id: 'connector1' } },
354
- { connector: { id: 'connector2' } }
355
- ];
356
- vi.spyOn(wagmiCore, 'getConnections').mockReturnValue(mockConnections);
357
- vi.spyOn(wagmiCore, 'createConfig').mockReturnValue({
358
- connectors: mockConnections.map(({ connector }) => connector)
359
- });
360
- const adapter = new WagmiAdapter({
361
- networks: mockNetworks,
362
- projectId: mockProjectId
363
- });
364
- const disconnectSpy = vi.spyOn(wagmiCore, 'disconnect').mockImplementationOnce(vi.fn());
365
- await adapter.disconnect();
366
- expect(disconnectSpy).toHaveBeenCalledTimes(2);
367
- });
368
- it('should authenticate and connect with wagmi when using connectWalletConnect', async () => {
369
- const mockWalletConnectConnector = {
370
- authenticate: vi.fn().mockResolvedValue(true),
371
- provider: {
372
- client: {
373
- core: {
374
- crypto: {
375
- getClientId: vi.fn().mockResolvedValue('mock-client-id')
376
- }
377
- }
378
- }
379
- }
380
- };
381
- const mockWagmiConnector = {
382
- id: 'walletConnect'
383
- };
384
- vi.spyOn(adapter, 'getWalletConnectConnector').mockReturnValue(mockWalletConnectConnector);
385
- vi.spyOn(adapter, 'getWagmiConnector').mockReturnValue(mockWagmiConnector);
386
- const connectSpy = vi.spyOn(wagmiCore, 'connect').mockResolvedValue({});
387
- const result = await adapter.connectWalletConnect(1);
388
- expect(mockWalletConnectConnector.authenticate).toHaveBeenCalled();
389
- expect(connectSpy).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
390
- connector: mockWagmiConnector,
391
- chainId: 1
392
- }));
393
- expect(result.clientId).toBe('mock-client-id');
394
- });
395
- });
396
- describe('WagmiAdapter - switchNetwork', () => {
397
- it('should switch network successfully', async () => {
398
- await adapter.switchNetwork({
399
- caipNetwork: mockCaipNetworks[0]
400
- });
401
- expect(switchChain).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
402
- chainId: 1
403
- }));
404
- });
405
- });
406
- describe('WagmiAdapter - Permissions', () => {
407
- const mockProvider = {
408
- request: vi.fn()
409
- };
410
- beforeEach(() => {
411
- vi.mocked(getConnections).mockReturnValue([
412
- {
413
- connector: {
414
- getProvider: () => Promise.resolve(mockProvider)
415
- }
416
- }
417
- ]);
418
- });
419
- it('should get capabilities from session properties', async () => {
420
- const mockRequest = vi.fn();
421
- const mockConnections = [
422
- {
423
- connector: {
424
- id: 'test-connector',
425
- getProvider: vi.fn().mockReturnValue({
426
- session: {
427
- sessionProperties: {}
428
- },
429
- request: mockRequest
430
- })
431
- }
432
- }
433
- ];
434
- vi.spyOn(wagmiCore, 'getConnections').mockReturnValue(mockConnections);
435
- vi.spyOn(wagmiCore, 'createConfig').mockReturnValue({
436
- connectors: mockConnections.map(({ connector }) => connector)
437
- });
438
- const adapter = new WagmiAdapter({
439
- networks: mockNetworks,
440
- projectId: mockProjectId
441
- });
442
- await adapter.getCapabilities('eip155:1:0x123');
443
- expect(mockRequest).toHaveBeenCalledWith({
444
- method: 'wallet_getCapabilities',
445
- params: ['eip155:1:0x123']
446
- });
447
- });
448
- it('should call provider request with correct params', async () => {
449
- const mockRequest = vi.fn();
450
- const mockConnections = [
451
- {
452
- connector: {
453
- id: 'test-connector',
454
- getProvider: vi.fn().mockReturnValue({
455
- session: {
456
- sessionProperties: {}
457
- },
458
- request: mockRequest
459
- })
460
- }
461
- }
462
- ];
463
- vi.spyOn(wagmiCore, 'getConnections').mockReturnValue(mockConnections);
464
- vi.spyOn(wagmiCore, 'createConfig').mockReturnValue({
465
- connectors: mockConnections.map(({ connector }) => connector)
466
- });
467
- const mockParams = {
468
- pci: 'test-pci',
469
- expiry: 1234567890,
470
- address: '0x123',
471
- permissions: ['eth_accounts']
472
- };
473
- const adapter = new WagmiAdapter({
474
- networks: mockNetworks,
475
- projectId: mockProjectId
476
- });
477
- await adapter.grantPermissions(mockParams);
478
- expect(mockRequest).toHaveBeenCalledWith({
479
- method: 'wallet_grantPermissions',
480
- params: mockParams
481
- });
482
- });
483
- it('should call provider request with correct params', async () => {
484
- const mockParams = {
485
- pci: 'test-pci',
486
- expiry: 1234567890,
487
- address: '0x123',
488
- permissions: ['eth_accounts']
489
- };
490
- const mockRequest = vi.fn();
491
- const mockConnections = [
492
- {
493
- connector: {
494
- id: 'test-connector',
495
- getProvider: vi.fn().mockReturnValue({
496
- session: {
497
- sessionProperties: {}
498
- },
499
- request: mockRequest
500
- })
501
- }
502
- }
503
- ];
504
- vi.spyOn(wagmiCore, 'getConnections').mockReturnValue(mockConnections);
505
- vi.spyOn(wagmiCore, 'createConfig').mockReturnValue({
506
- connectors: mockConnections.map(({ connector }) => connector)
507
- });
508
- const adapter = new WagmiAdapter({
509
- networks: mockNetworks,
510
- projectId: mockProjectId
511
- });
512
- await adapter.revokePermissions(mockParams);
513
- expect(mockRequest).toHaveBeenCalledWith({
514
- method: 'wallet_revokePermissions',
515
- params: mockParams
516
- });
517
- });
518
- });
519
- describe('WagmiAdapter - watchPendingTransactions', () => {
520
- it('should emit pendingTransactions when transactions are pending', async () => {
521
- const adapter = new WagmiAdapter({
522
- networks: mockNetworks,
523
- projectId: mockProjectId,
524
- pendingTransactionsFilter: {
525
- enable: true,
526
- pollingInterval: 5000
527
- }
528
- });
529
- const emitSpy = vi.spyOn(adapter, 'emit');
530
- vi.mocked(watchPendingTransactions).mockImplementation((_, { onTransactions }) => {
531
- onTransactions(['0xtx1', '0xtx2']);
532
- return vi.fn();
533
- });
534
- adapter['setupWatchPendingTransactions']();
535
- expect(emitSpy).toHaveBeenCalledWith('pendingTransactions');
536
- });
537
- it('should limit the amount of pendingTransactions calls', async () => {
538
- const unsubscribe = vi.fn();
539
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
540
- onChange({ address: '0x123', status: 'connected' }, {});
541
- return vi.fn();
542
- });
543
- vi.spyOn(wagmiCore, 'watchPendingTransactions').mockReturnValue(unsubscribe);
544
- new WagmiAdapter({
545
- networks: mockNetworks,
546
- projectId: mockProjectId,
547
- pendingTransactionsFilter: {
548
- enable: true,
549
- pollingInterval: 500
550
- }
551
- });
552
- LimitterUtil.state.pendingTransactions = ConstantsUtil.LIMITS.PENDING_TRANSACTIONS;
553
- await new Promise(resolve => setTimeout(resolve, 100));
554
- expect(unsubscribe).toHaveBeenCalled();
555
- });
556
- });
557
- describe('WagmiAdapter - watchAccount', () => {
558
- let adapter;
559
- beforeAll(() => {
560
- adapter = new WagmiAdapter({
561
- networks: mockNetworks,
562
- projectId: mockProjectId,
563
- pendingTransactionsFilter: {
564
- enable: true,
565
- pollingInterval: 5000
566
- }
567
- });
568
- });
569
- beforeEach(() => {
570
- vi.clearAllMocks();
571
- });
572
- it('should emit accountChanged if previous account status is not connected', async () => {
573
- const currAccount = {
574
- status: 'connected',
575
- address: '0x123',
576
- chainId: 1
577
- };
578
- const prevAccount = {
579
- status: 'connecting',
580
- address: '0x123',
581
- chainId: 1
582
- };
583
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
584
- onChange(currAccount, prevAccount);
585
- return vi.fn();
586
- });
587
- const accountChangedSpy = vi.fn();
588
- adapter.on('accountChanged', accountChangedSpy);
589
- adapter['setupWatchers']();
590
- expect(accountChangedSpy).toHaveBeenCalledWith({
591
- address: currAccount.address,
592
- chainId: currAccount.chainId
593
- });
594
- });
595
- it('should emit accountChanged current address and previous address are not the same', async () => {
596
- const currAccount = {
597
- status: 'connected',
598
- address: '0x123',
599
- chainId: 1
600
- };
601
- const prevAccount = {
602
- status: 'connected',
603
- address: '0x321',
604
- chainId: 1
605
- };
606
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
607
- onChange(currAccount, prevAccount);
608
- return vi.fn();
609
- });
610
- const adapter = new WagmiAdapter({
611
- networks: mockNetworks,
612
- projectId: mockProjectId,
613
- pendingTransactionsFilter: {
614
- enable: true,
615
- pollingInterval: 5000
616
- }
617
- });
618
- const accountChangedSpy = vi.fn();
619
- adapter.on('accountChanged', accountChangedSpy);
620
- adapter['setupWatchers']();
621
- expect(accountChangedSpy).toHaveBeenCalledWith({
622
- address: currAccount.address,
623
- chainId: currAccount.chainId
624
- });
625
- });
626
- it('should not emit accountChanged if current status is not connected', async () => {
627
- const currAccount = {
628
- status: 'connecting',
629
- address: '0x123',
630
- chainId: 1
631
- };
632
- const prevAccount = {
633
- status: 'connected',
634
- address: '0x123',
635
- chainId: 1
636
- };
637
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
638
- onChange(currAccount, prevAccount);
639
- return vi.fn();
640
- });
641
- const accountChangedSpy = vi.fn();
642
- adapter.on('accountChanged', accountChangedSpy);
643
- adapter['setupWatchers']();
644
- expect(accountChangedSpy).not.toHaveBeenCalled();
645
- });
646
- it('should emit disconnect if status is disconnected and previous data is connected', async () => {
647
- const currAccount = {
648
- status: 'disconnected',
649
- address: undefined,
650
- chainId: 1
651
- };
652
- const prevAccount = {
653
- status: 'connected',
654
- address: '0x123',
655
- chainId: 1
656
- };
657
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
658
- onChange(currAccount, prevAccount);
659
- return vi.fn();
660
- });
661
- const disconnectSpy = vi.fn();
662
- adapter.on('disconnect', disconnectSpy);
663
- adapter['setupWatchers']();
664
- expect(disconnectSpy).toHaveBeenCalled();
665
- });
666
- it('should not emit disconnect if previous account data is undefined and current account data is disconnected', async () => {
667
- const currAccount = {
668
- status: 'disconnected',
669
- address: '0x123',
670
- chainId: 1
671
- };
672
- const prevAccount = {
673
- status: 'disconnected',
674
- address: undefined,
675
- chainId: 1
676
- };
677
- vi.mocked(watchAccount).mockImplementation((_, { onChange }) => {
678
- onChange(currAccount, prevAccount);
679
- return vi.fn();
680
- });
681
- const disconnectSpy = vi.fn();
682
- adapter.on('disconnect', disconnectSpy);
683
- adapter['setupWatchers']();
684
- expect(disconnectSpy).not.toHaveBeenCalled();
685
- });
686
- });
687
- });
688
- //# sourceMappingURL=client.test.js.map