@tomo-inc/wallet-adaptor-base 0.0.20 → 0.0.21

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.
@@ -0,0 +1,402 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import {
3
+ hasInjectedProvider,
4
+ getInjectedProvider,
5
+ walletConfigAdapter,
6
+ connectorDector,
7
+ supportedWalletConfigTypes,
8
+ } from "../wallets/detector";
9
+ import { ProviderProtocol } from "@tomo-inc/wallet-utils";
10
+
11
+ describe("detector", () => {
12
+ let originalWindow: typeof window;
13
+
14
+ beforeEach(() => {
15
+ originalWindow = global.window;
16
+ });
17
+
18
+ afterEach(() => {
19
+ global.window = originalWindow;
20
+ vi.restoreAllMocks();
21
+ });
22
+
23
+ describe("hasInjectedProvider", () => {
24
+ it("should return true when namespace provider exists", () => {
25
+ Object.defineProperty(global, "window", {
26
+ value: {
27
+ ethereum: {
28
+ isMetaMask: true,
29
+ },
30
+ },
31
+ writable: true,
32
+ configurable: true,
33
+ });
34
+
35
+ expect(hasInjectedProvider({ namespace: "ethereum" })).toBe(true);
36
+ });
37
+
38
+ it("should return true when flag provider exists", () => {
39
+ Object.defineProperty(global, "window", {
40
+ value: {
41
+ ethereum: {
42
+ providers: [
43
+ {
44
+ isMetaMask: true,
45
+ },
46
+ ],
47
+ },
48
+ },
49
+ writable: true,
50
+ configurable: true,
51
+ });
52
+
53
+ expect(hasInjectedProvider({ flag: "isMetaMask" })).toBe(true);
54
+ });
55
+
56
+ it("should return false when provider does not exist", () => {
57
+ Object.defineProperty(global, "window", {
58
+ value: {},
59
+ writable: true,
60
+ configurable: true,
61
+ });
62
+
63
+ expect(hasInjectedProvider({ namespace: "ethereum" })).toBe(false);
64
+ expect(hasInjectedProvider({ flag: "isMetaMask" })).toBe(false);
65
+ });
66
+
67
+ it("should return true when nested namespace provider exists", () => {
68
+ const nested = { request: vi.fn() };
69
+ Object.defineProperty(global, "window", {
70
+ value: { ethereum: { wallet: nested } },
71
+ writable: true,
72
+ configurable: true,
73
+ });
74
+ expect(hasInjectedProvider({ namespace: "ethereum.wallet" })).toBe(true);
75
+ });
76
+ });
77
+
78
+ describe("getInjectedProvider", () => {
79
+ it("should throw error when window is undefined", () => {
80
+ Object.defineProperty(global, "window", {
81
+ value: undefined,
82
+ writable: true,
83
+ configurable: true,
84
+ });
85
+
86
+ expect(() => getInjectedProvider({})).toThrow("Window is not defined");
87
+ });
88
+
89
+ it("should return nested namespace provider when available", () => {
90
+ const mockProvider = { request: vi.fn() };
91
+ Object.defineProperty(global, "window", {
92
+ value: { ethereum: { nested: mockProvider } },
93
+ writable: true,
94
+ configurable: true,
95
+ });
96
+ expect(getInjectedProvider({ namespace: "ethereum.nested" })).toBe(mockProvider);
97
+ });
98
+
99
+ it("should return namespace provider when available", () => {
100
+ const mockProvider = { request: vi.fn() };
101
+ Object.defineProperty(global, "window", {
102
+ value: {
103
+ ethereum: mockProvider,
104
+ },
105
+ writable: true,
106
+ configurable: true,
107
+ });
108
+
109
+ expect(getInjectedProvider({ namespace: "ethereum" })).toBe(mockProvider);
110
+ });
111
+
112
+ it("should return flag provider when available", () => {
113
+ const mockProvider = { isMetaMask: true, request: vi.fn() };
114
+ Object.defineProperty(global, "window", {
115
+ value: {
116
+ ethereum: {
117
+ providers: [mockProvider],
118
+ },
119
+ },
120
+ writable: true,
121
+ configurable: true,
122
+ });
123
+
124
+ expect(getInjectedProvider({ flag: "isMetaMask" })).toBe(mockProvider);
125
+ });
126
+
127
+ it("should return first provider from providers array", () => {
128
+ const mockProvider1 = { request: vi.fn() };
129
+ const mockProvider2 = { request: vi.fn() };
130
+ Object.defineProperty(global, "window", {
131
+ value: {
132
+ ethereum: {
133
+ providers: [mockProvider1, mockProvider2],
134
+ },
135
+ },
136
+ writable: true,
137
+ configurable: true,
138
+ });
139
+
140
+ expect(getInjectedProvider({})).toBe(mockProvider1);
141
+ });
142
+
143
+ it("should return window.ethereum as fallback", () => {
144
+ const mockEthereum = { request: vi.fn() };
145
+ Object.defineProperty(global, "window", {
146
+ value: {
147
+ ethereum: mockEthereum,
148
+ },
149
+ writable: true,
150
+ configurable: true,
151
+ });
152
+
153
+ expect(getInjectedProvider({})).toBe(mockEthereum);
154
+ });
155
+ });
156
+
157
+ describe("walletConfigAdapter", () => {
158
+ it("should return wallet config for tomo type", () => {
159
+ const walletConfig = { name: "Test", id: "test" };
160
+ expect(walletConfigAdapter(walletConfig as any, "tomo", [], "")).toBe(walletConfig);
161
+ });
162
+
163
+ it("should return wallet config for wagmi type when not a function", () => {
164
+ const walletConfig = { name: "Test", id: "test" };
165
+ expect(walletConfigAdapter(walletConfig as any, "wagmi", [], "")).toBe(walletConfig);
166
+ });
167
+
168
+ it("should return wallet config as default", () => {
169
+ const walletConfig = { name: "Test", id: "test" };
170
+ expect(walletConfigAdapter(walletConfig as any, "unknown" as any, [], "")).toBe(walletConfig);
171
+ });
172
+
173
+ it("should adapt wagmi CreateConnectorFn to WalletConfig when connectorType is wagmi", () => {
174
+ const createConnector = vi.fn().mockReturnValue({
175
+ id: "injected",
176
+ name: "Injected",
177
+ connect: vi.fn(),
178
+ disconnect: vi.fn(),
179
+ });
180
+ const allWallets: any[] = [
181
+ { id: "injected", name: "Injected", icon: "/injected.png", iconBackground: "#fff", namespace: "eip155" },
182
+ ];
183
+ const result = walletConfigAdapter(createConnector as any, "wagmi", allWallets, "https://base/");
184
+ expect(result.id).toBe("injected");
185
+ expect(result.name).toBe("Injected");
186
+ expect(createConnector).toHaveBeenCalled();
187
+ });
188
+
189
+ it("should find default wallet by name match (metamask/injected style) when id does not match", () => {
190
+ const createConnector = vi.fn().mockReturnValue({
191
+ id: "injected",
192
+ name: "Injected MetaMask",
193
+ connect: vi.fn(),
194
+ disconnect: vi.fn(),
195
+ });
196
+ const allWallets: any[] = [
197
+ { id: "metamask", name: "MetaMask", icon: "/mm.png", iconBackground: "#fff", namespace: "eip155" },
198
+ ];
199
+ const result = walletConfigAdapter(createConnector as any, "wagmi", allWallets, "https://base/");
200
+ expect(result.id).toBe("injected");
201
+ expect(result.name).toBe("Injected MetaMask");
202
+ expect(result.namespace).toBe("eip155");
203
+ expect(result.icon).toContain("/mm.png");
204
+ });
205
+ });
206
+
207
+ describe("connectorDector", () => {
208
+ it("should create connector with EVM provider", () => {
209
+ const mockProvider = { request: vi.fn() };
210
+ Object.defineProperty(global, "window", {
211
+ value: {
212
+ ethereum: mockProvider,
213
+ },
214
+ writable: true,
215
+ configurable: true,
216
+ });
217
+
218
+ const walletConfig = {
219
+ id: "test-wallet",
220
+ name: "Test Wallet",
221
+ icon: "icon.png",
222
+ namespace: "ethereum",
223
+ };
224
+
225
+ const connector = connectorDector(walletConfig as any, "tomo");
226
+ expect(connector.info.name).toBe("Test Wallet");
227
+ expect(connector.connectors.evm).toBeDefined();
228
+ expect(connector.connectors.evm?.protocol).toBe(ProviderProtocol.INJECT);
229
+ expect(connector.connectors.evm?.provider).toBe(mockProvider);
230
+ });
231
+
232
+ it("should create connector with EVM provider using flag", () => {
233
+ const mockProvider = { isMetaMask: true, request: vi.fn() };
234
+ Object.defineProperty(global, "window", {
235
+ value: {
236
+ ethereum: {
237
+ providers: [mockProvider],
238
+ },
239
+ },
240
+ writable: true,
241
+ configurable: true,
242
+ });
243
+
244
+ const walletConfig = {
245
+ id: "test-wallet",
246
+ name: "Test Wallet",
247
+ icon: "icon.png",
248
+ flag: "isMetaMask",
249
+ };
250
+
251
+ const connector = connectorDector(walletConfig as any, "tomo");
252
+ expect(connector.connectors.evm).toBeDefined();
253
+ expect(connector.connectors.evm?.protocol).toBe(ProviderProtocol.INJECT);
254
+ });
255
+
256
+ it("should create connector with Solana provider", () => {
257
+ const mockProvider = { request: vi.fn() };
258
+ Object.defineProperty(global, "window", {
259
+ value: {
260
+ solana: mockProvider,
261
+ },
262
+ writable: true,
263
+ configurable: true,
264
+ });
265
+
266
+ const walletConfig = {
267
+ id: "test-wallet",
268
+ name: "Test Wallet",
269
+ icon: "icon.png",
270
+ solana: {
271
+ namespace: "solana",
272
+ },
273
+ };
274
+
275
+ const connector = connectorDector(walletConfig as any, "tomo");
276
+ expect(connector.connectors.solana).toBeDefined();
277
+ expect(connector.connectors.solana?.protocol).toBe(ProviderProtocol.INJECT);
278
+ });
279
+
280
+ it("should create connector with Aptos provider", () => {
281
+ const mockProvider = { request: vi.fn() };
282
+ Object.defineProperty(global, "window", {
283
+ value: {
284
+ aptos: mockProvider,
285
+ },
286
+ writable: true,
287
+ configurable: true,
288
+ });
289
+
290
+ const walletConfig = {
291
+ id: "test-wallet",
292
+ name: "Test Wallet",
293
+ icon: "icon.png",
294
+ aptos: {
295
+ namespace: "aptos",
296
+ },
297
+ };
298
+
299
+ const connector = connectorDector(walletConfig as any, "tomo");
300
+ expect(connector.connectors.aptos).toBeDefined();
301
+ expect(connector.connectors.aptos?.protocol).toBe(ProviderProtocol.INJECT);
302
+ });
303
+
304
+ it("should create connector with Dogecoin provider", () => {
305
+ const mockProvider = { request: vi.fn() };
306
+ Object.defineProperty(global, "window", {
307
+ value: {
308
+ dogecoin: mockProvider,
309
+ },
310
+ writable: true,
311
+ configurable: true,
312
+ });
313
+
314
+ const walletConfig = {
315
+ id: "test-wallet",
316
+ name: "Test Wallet",
317
+ icon: "icon.png",
318
+ dogecoin: {
319
+ namespace: "dogecoin",
320
+ },
321
+ };
322
+
323
+ const connector = connectorDector(walletConfig as any, "tomo");
324
+ expect(connector.connectors.dogecoin).toBeDefined();
325
+ expect(connector.connectors.dogecoin?.protocol).toBe(ProviderProtocol.INJECT);
326
+ });
327
+
328
+ it("should create connector without providers when not installed", () => {
329
+ Object.defineProperty(global, "window", {
330
+ value: {},
331
+ writable: true,
332
+ configurable: true,
333
+ });
334
+
335
+ const walletConfig = {
336
+ id: "test-wallet",
337
+ name: "Test Wallet",
338
+ icon: "icon.png",
339
+ namespace: "ethereum",
340
+ };
341
+
342
+ const connector = connectorDector(walletConfig as any, "tomo");
343
+ expect(connector.isInstalled).toBe(false);
344
+ expect(connector.connectors.evm?.provider).toBeUndefined();
345
+ });
346
+
347
+ it("should include download URLs in links", () => {
348
+ const walletConfig = {
349
+ id: "test-wallet",
350
+ name: "Test Wallet",
351
+ icon: "icon.png",
352
+ downloadUrls: {
353
+ qrCode: "https://example.com/qr",
354
+ ios: "https://example.com/ios",
355
+ android: "https://example.com/android",
356
+ chrome: "https://example.com/chrome",
357
+ },
358
+ };
359
+
360
+ const connector = connectorDector(walletConfig as any, "tomo");
361
+ expect(connector.info.links.homepage).toBe("https://example.com/qr");
362
+ expect(connector.info.links.ios_install).toBe("https://example.com/ios");
363
+ expect(connector.info.links.android_install).toBe("https://example.com/android");
364
+ expect(connector.info.links.chrome_install).toBe("https://example.com/chrome");
365
+ });
366
+ });
367
+
368
+ describe("supportedWalletConfigTypes", () => {
369
+ it("should have tomo and wagmi types", () => {
370
+ expect(supportedWalletConfigTypes.tomo).toBe(true);
371
+ expect(supportedWalletConfigTypes.wagmi).toBe(true);
372
+ });
373
+ });
374
+
375
+ describe("connectorDector with wagmi type", () => {
376
+ it("should create connector via wagmiConnectorDector when connectorType is wagmi", () => {
377
+ const mockConnector = {
378
+ id: "wagmi-injected",
379
+ name: "Injected",
380
+ connect: vi.fn(),
381
+ disconnect: vi.fn(),
382
+ };
383
+ const wagmiWalletConfig = {
384
+ id: "wagmi-injected",
385
+ name: "Injected",
386
+ icon: "icon.png",
387
+ iconBackground: "#000",
388
+ createConnector: vi.fn().mockReturnValue(mockConnector),
389
+ } as any;
390
+
391
+ const connector = connectorDector(wagmiWalletConfig, "wagmi");
392
+
393
+ expect(connector.info.uuid).toBe("wagmi-injected");
394
+ expect(connector.info.name).toBe("Injected");
395
+ expect(connector.connectors.evm).toBeDefined();
396
+ expect(connector.connectors.evm?.protocol).toBe(ProviderProtocol.INJECT);
397
+ expect(connector.connectors.evm?.provider).toBe(mockConnector);
398
+ expect(connector.isInstalled).toBe(true);
399
+ expect(wagmiWalletConfig.createConnector).toHaveBeenCalled();
400
+ });
401
+ });
402
+ });
@@ -0,0 +1,275 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { loadConnectors, isMobile } from "../index";
3
+
4
+ // Mock dependencies - use vi.hoisted to define variables that can be used in vi.mock
5
+ const { mockEip6963Wallet, mockSolanaWallet, mockDefaultConnector, mockEip6963ConnectorFromConfig } = vi.hoisted(() => {
6
+ const mockEip6963Wallet = {
7
+ info: { name: "EIP6963 Wallet", uuid: "eip6963-1", icon: "icon1.png" },
8
+ connectors: { evm: { provider: {}, protocol: "eip6963" } },
9
+ isInstalled: false,
10
+ };
11
+
12
+ const mockSolanaWallet = {
13
+ info: { name: "Solana Wallet", uuid: "solana-1", icon: "icon2.png" },
14
+ connectors: { solana: { provider: {}, protocol: "inject" } },
15
+ isInstalled: false,
16
+ };
17
+
18
+ const mockDefaultConnector = {
19
+ info: { name: "Default Wallet", uuid: "default-1", icon: "icon3.png" },
20
+ connectors: { evm: { provider: {}, protocol: "eip6963" } },
21
+ isInstalled: false,
22
+ recommoned: true,
23
+ };
24
+
25
+ // Add a connector with same name as detected wallet so it gets marked as installed
26
+ const mockEip6963ConnectorFromConfig = {
27
+ info: { name: "EIP6963 Wallet", uuid: "eip6963-1", icon: "icon1.png" },
28
+ connectors: { evm: { provider: {}, protocol: "eip6963" } },
29
+ isInstalled: false,
30
+ };
31
+
32
+ return { mockEip6963Wallet, mockSolanaWallet, mockDefaultConnector, mockEip6963ConnectorFromConfig };
33
+ });
34
+
35
+ vi.mock("../wallets/wallet-eip6963", () => ({
36
+ eip6963Wallets: vi.fn().mockResolvedValue([mockEip6963Wallet]),
37
+ }));
38
+
39
+ vi.mock("../wallets/wallet-standard", () => ({
40
+ walletStandardWallets: vi.fn().mockResolvedValue({
41
+ solanaWallets: [mockSolanaWallet],
42
+ aptosWallets: [],
43
+ }),
44
+ }));
45
+
46
+ vi.mock("../wallets/wallet-walletconnect", () => ({
47
+ walletConnectWallets: vi.fn().mockResolvedValue([]),
48
+ }));
49
+
50
+ vi.mock("../wallets/defaultConnectors", () => ({
51
+ getDefaultConnectors: vi.fn().mockResolvedValue([mockDefaultConnector, mockEip6963ConnectorFromConfig]),
52
+ }));
53
+
54
+ vi.mock("../wallets", () => ({
55
+ getAllWallets: vi.fn().mockResolvedValue([]),
56
+ walletBaseUrl: "https://web3-assets.tomo.inc",
57
+ }));
58
+
59
+ describe("wallet-adaptor-base", () => {
60
+ beforeEach(() => {
61
+ vi.clearAllMocks();
62
+ });
63
+
64
+ describe("loadConnectors", () => {
65
+ it("should load connectors with default options", async () => {
66
+ const result = await loadConnectors({});
67
+ expect(result.all).toBeDefined();
68
+ expect(result.recommoned).toBeDefined();
69
+ expect(Array.isArray(result.all)).toBe(true);
70
+ expect(Array.isArray(result.recommoned)).toBe(true);
71
+ });
72
+
73
+ it("should filter connectors by chain type", async () => {
74
+ const result = await loadConnectors({ chainType: "evm" });
75
+ expect(result.all).toBeDefined();
76
+ });
77
+
78
+ it("should handle recommoned connectors", async () => {
79
+ const recommonedConnectors = [
80
+ {
81
+ name: "Test Wallet",
82
+ icon: "https://example.com/icon.png",
83
+ id: "test-wallet",
84
+ },
85
+ ];
86
+
87
+ const result = await loadConnectors({
88
+ recommendedConnectors: recommonedConnectors as any,
89
+ connectorTypes: ["tomo"],
90
+ });
91
+
92
+ expect(result.recommoned).toBeDefined();
93
+ });
94
+
95
+ it("should throw error for unsupported connector type", async () => {
96
+ await expect(
97
+ loadConnectors({
98
+ recommendedConnectors: [{}] as any,
99
+ connectorTypes: ["unsupported" as any],
100
+ }),
101
+ ).rejects.toThrow("Unsupported wallet config type: unsupported");
102
+ });
103
+
104
+ it("should merge detected connectors with config connectors", async () => {
105
+ const result = await loadConnectors({});
106
+ // Should include both detected wallets and default connectors
107
+ expect(result.all.length).toBeGreaterThan(0);
108
+ });
109
+
110
+ it("should mark connectors as installed when detected", async () => {
111
+ const result = await loadConnectors({});
112
+ const eip6963Connector = result.all.find((c) => c.info.name === "EIP6963 Wallet");
113
+ if (eip6963Connector) {
114
+ expect(eip6963Connector.isInstalled).toBe(true);
115
+ }
116
+ });
117
+
118
+ it("should sort connectors with recommoned first", async () => {
119
+ const result = await loadConnectors({});
120
+ const recommonedIndex = result.all.findIndex((c) => c.recommoned);
121
+ const nonRecommonedIndex = result.all.findIndex((c) => !c.recommoned);
122
+ if (recommonedIndex !== -1 && nonRecommonedIndex !== -1) {
123
+ expect(recommonedIndex).toBeLessThan(nonRecommonedIndex);
124
+ }
125
+ });
126
+
127
+ it("should sort connectors with installed wallets second", async () => {
128
+ const result = await loadConnectors({});
129
+ // Check that installed wallets come before non-installed
130
+ const installedIndex = result.all.findIndex((c) => c.isInstalled);
131
+ const nonInstalledIndex = result.all.findIndex((c) => !c.isInstalled && !c.recommoned);
132
+ if (installedIndex !== -1 && nonInstalledIndex !== -1) {
133
+ expect(installedIndex).toBeLessThan(nonInstalledIndex);
134
+ }
135
+ });
136
+
137
+ it("should filter by solana chain type", async () => {
138
+ const result = await loadConnectors({ chainType: "solana" });
139
+ expect(result.all.every((c) => c.connectors.solana)).toBe(true);
140
+ });
141
+
142
+ it("should filter by aptos chain type", async () => {
143
+ const { walletStandardWallets } = await import("../wallets/wallet-standard");
144
+ vi.mocked(walletStandardWallets).mockResolvedValueOnce({
145
+ solanaWallets: [],
146
+ aptosWallets: [
147
+ {
148
+ info: { name: "Aptos Wallet", uuid: "aptos-1" },
149
+ connectors: { aptos: { provider: {}, protocol: "inject" } },
150
+ isInstalled: false,
151
+ },
152
+ ],
153
+ suiWallets: [],
154
+ });
155
+
156
+ const result = await loadConnectors({ chainType: "aptos" });
157
+ expect(result.all.every((c) => c.connectors.aptos)).toBe(true);
158
+ });
159
+
160
+ it("should use custom baseUrl", async () => {
161
+ const { getDefaultConnectors } = await import("../wallets/defaultConnectors");
162
+ const { walletConnectWallets } = await import("../wallets/wallet-walletconnect");
163
+
164
+ await loadConnectors({
165
+ options: {
166
+ baseUrl: "https://custom-api.example.com",
167
+ },
168
+ });
169
+
170
+ // Verify custom baseUrl is passed to functions
171
+ expect(vi.mocked(getDefaultConnectors)).toHaveBeenCalledWith("https://custom-api.example.com");
172
+ expect(vi.mocked(walletConnectWallets)).toHaveBeenCalledWith("https://custom-api.example.com");
173
+ });
174
+
175
+ it("should merge providers when connector already exists", async () => {
176
+ const mockWalletConnectWallet = {
177
+ info: { name: "EIP6963 Wallet", uuid: "eip6963-1" },
178
+ connectors: { evm: { provider: { wc: true }, protocol: "walletconnect" } },
179
+ isInstalled: false,
180
+ };
181
+
182
+ const { walletConnectWallets } = await import("../wallets/wallet-walletconnect");
183
+ vi.mocked(walletConnectWallets).mockResolvedValueOnce([mockWalletConnectWallet as any]);
184
+
185
+ const result = await loadConnectors({});
186
+ const connector = result.all.find((c) => c.info.name === "EIP6963 Wallet");
187
+
188
+ if (connector) {
189
+ // Should merge connectors
190
+ expect(connector.connectors.evm).toBeDefined();
191
+ }
192
+ });
193
+
194
+ it("should handle empty recommoned connectors", async () => {
195
+ const result = await loadConnectors({
196
+ recommendedConnectors: [],
197
+ connectorTypes: [],
198
+ });
199
+
200
+ expect(result.recommoned).toEqual([]);
201
+ });
202
+
203
+ it("should handle multiple recommoned connectors", async () => {
204
+ const recommonedConnectors = [
205
+ {
206
+ name: "Wallet 1",
207
+ icon: "icon1.png",
208
+ id: "wallet-1",
209
+ },
210
+ {
211
+ name: "Wallet 2",
212
+ icon: "icon2.png",
213
+ id: "wallet-2",
214
+ },
215
+ ];
216
+
217
+ const result = await loadConnectors({
218
+ recommendedConnectors: recommonedConnectors as any,
219
+ connectorTypes: ["tomo", "tomo"],
220
+ });
221
+
222
+ expect(result.recommoned).toHaveLength(2);
223
+ expect(result.recommoned.every((c) => c.recommoned)).toBe(true);
224
+ });
225
+
226
+ it("should handle WalletConnect wallets", async () => {
227
+ const mockWCWallet = {
228
+ info: { name: "WalletConnect", uuid: "wc-1" },
229
+ providers: { evm: { provider: {}, protocol: "walletconnect" } },
230
+ isInstalled: true,
231
+ };
232
+
233
+ const { walletConnectWallets } = await import("../wallets/wallet-walletconnect");
234
+ vi.mocked(walletConnectWallets).mockResolvedValueOnce([mockWCWallet as any]);
235
+
236
+ const result = await loadConnectors({});
237
+ const wcConnector = result.all.find((c) => c.info.name === "WalletConnect");
238
+
239
+ expect(wcConnector).toBeDefined();
240
+ if (wcConnector) {
241
+ expect(wcConnector.isInstalled).toBe(true);
242
+ }
243
+ });
244
+
245
+ it("should handle all chain type", async () => {
246
+ const result = await loadConnectors({ chainType: "all" });
247
+ // Should include all connectors regardless of chain type
248
+ expect(result.all.length).toBeGreaterThan(0);
249
+ });
250
+
251
+ it("should handle empty detected wallets", async () => {
252
+ const { eip6963Wallets } = await import("../wallets/wallet-eip6963");
253
+ const { walletStandardWallets } = await import("../wallets/wallet-standard");
254
+ const { walletConnectWallets } = await import("../wallets/wallet-walletconnect");
255
+
256
+ vi.mocked(eip6963Wallets).mockResolvedValueOnce([]);
257
+ vi.mocked(walletStandardWallets).mockResolvedValueOnce({
258
+ solanaWallets: [],
259
+ aptosWallets: [],
260
+ suiWallets: [],
261
+ });
262
+ vi.mocked(walletConnectWallets).mockResolvedValueOnce([]);
263
+
264
+ const result = await loadConnectors({});
265
+ // Should still return default connectors
266
+ expect(result.all.length).toBeGreaterThanOrEqual(0);
267
+ });
268
+ });
269
+
270
+ describe("isMobile", () => {
271
+ it("should export isMobile function", () => {
272
+ expect(typeof isMobile).toBe("function");
273
+ });
274
+ });
275
+ });