thirdweb 5.29.2-nightly-eff710738ce3d4341257e5912311c95b28a34b5d-20240614173600 → 5.29.3-nightly-ffaff744f72d2cb22896e7501677b48f76ea857a-20240614184424

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 (81) hide show
  1. package/dist/cjs/exports/react-native/wallets.js +34 -0
  2. package/dist/cjs/exports/react-native/wallets.js.map +1 -0
  3. package/dist/cjs/exports/wallets/smart.js +2 -2
  4. package/dist/cjs/exports/wallets/smart.js.map +1 -1
  5. package/dist/cjs/exports/wallets.js +3 -2
  6. package/dist/cjs/exports/wallets.js.map +1 -1
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/cjs/wallets/coinbase/coinbase-wallet.js +87 -0
  9. package/dist/cjs/wallets/coinbase/coinbase-wallet.js.map +1 -0
  10. package/dist/cjs/wallets/coinbase/coinbaseMobileSDK.js +17 -2
  11. package/dist/cjs/wallets/coinbase/coinbaseMobileSDK.js.map +1 -1
  12. package/dist/cjs/wallets/coinbase/coinbaseSDKWallet.js +12 -20
  13. package/dist/cjs/wallets/coinbase/coinbaseSDKWallet.js.map +1 -1
  14. package/dist/cjs/wallets/create-wallet.js +10 -173
  15. package/dist/cjs/wallets/create-wallet.js.map +1 -1
  16. package/dist/cjs/wallets/in-app/core/wallet/index.js +1 -1
  17. package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
  18. package/dist/cjs/wallets/manager/index.js +2 -2
  19. package/dist/cjs/wallets/manager/index.js.map +1 -1
  20. package/dist/cjs/wallets/native/create-wallet.js +174 -0
  21. package/dist/cjs/wallets/native/create-wallet.js.map +1 -0
  22. package/dist/cjs/wallets/smart/smart-wallet.js +103 -0
  23. package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -0
  24. package/dist/esm/exports/react-native/wallets.js +23 -0
  25. package/dist/esm/exports/react-native/wallets.js.map +1 -0
  26. package/dist/esm/exports/wallets/smart.js +1 -1
  27. package/dist/esm/exports/wallets/smart.js.map +1 -1
  28. package/dist/esm/exports/wallets.js +2 -1
  29. package/dist/esm/exports/wallets.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/wallets/coinbase/coinbase-wallet.js +83 -0
  32. package/dist/esm/wallets/coinbase/coinbase-wallet.js.map +1 -0
  33. package/dist/esm/wallets/coinbase/coinbaseMobileSDK.js +16 -1
  34. package/dist/esm/wallets/coinbase/coinbaseMobileSDK.js.map +1 -1
  35. package/dist/esm/wallets/coinbase/coinbaseSDKWallet.js +10 -19
  36. package/dist/esm/wallets/coinbase/coinbaseSDKWallet.js.map +1 -1
  37. package/dist/esm/wallets/create-wallet.js +8 -170
  38. package/dist/esm/wallets/create-wallet.js.map +1 -1
  39. package/dist/esm/wallets/in-app/core/wallet/index.js +1 -1
  40. package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
  41. package/dist/esm/wallets/manager/index.js +1 -1
  42. package/dist/esm/wallets/manager/index.js.map +1 -1
  43. package/dist/esm/wallets/native/create-wallet.js +169 -0
  44. package/dist/esm/wallets/native/create-wallet.js.map +1 -0
  45. package/dist/esm/wallets/smart/smart-wallet.js +99 -0
  46. package/dist/esm/wallets/smart/smart-wallet.js.map +1 -0
  47. package/dist/types/exports/react-native/wallets.d.ts +46 -0
  48. package/dist/types/exports/react-native/wallets.d.ts.map +1 -0
  49. package/dist/types/exports/wallets/smart.d.ts +1 -1
  50. package/dist/types/exports/wallets/smart.d.ts.map +1 -1
  51. package/dist/types/exports/wallets.d.ts +2 -1
  52. package/dist/types/exports/wallets.d.ts.map +1 -1
  53. package/dist/types/version.d.ts +1 -1
  54. package/dist/types/wallets/coinbase/coinbase-wallet.d.ts +15 -0
  55. package/dist/types/wallets/coinbase/coinbase-wallet.d.ts.map +1 -0
  56. package/dist/types/wallets/coinbase/coinbaseMobileSDK.d.ts +7 -7
  57. package/dist/types/wallets/coinbase/coinbaseMobileSDK.d.ts.map +1 -1
  58. package/dist/types/wallets/coinbase/coinbaseSDKWallet.d.ts +6 -2
  59. package/dist/types/wallets/coinbase/coinbaseSDKWallet.d.ts.map +1 -1
  60. package/dist/types/wallets/create-wallet.d.ts +0 -21
  61. package/dist/types/wallets/create-wallet.d.ts.map +1 -1
  62. package/dist/types/wallets/manager/index.d.ts.map +1 -1
  63. package/dist/types/wallets/native/create-wallet.d.ts +36 -0
  64. package/dist/types/wallets/native/create-wallet.d.ts.map +1 -0
  65. package/dist/types/wallets/smart/smart-wallet.d.ts +24 -0
  66. package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -0
  67. package/package.json +2 -1
  68. package/src/exports/react-native/wallets.ts +100 -0
  69. package/src/exports/wallets/smart.ts +1 -1
  70. package/src/exports/wallets.ts +1 -1
  71. package/src/version.ts +1 -1
  72. package/src/wallets/coinbase/coinbase-wallet.ts +108 -0
  73. package/src/wallets/coinbase/coinbaseMobileSDK.ts +23 -1
  74. package/src/wallets/coinbase/coinbaseSDKWallet.ts +10 -21
  75. package/src/wallets/create-wallet.ts +8 -213
  76. package/src/wallets/in-app/core/wallet/index.ts +1 -1
  77. package/src/wallets/manager/index.ts +1 -1
  78. package/src/wallets/native/create-wallet.ts +224 -0
  79. package/src/wallets/smart/smart-wallet-integration.test.ts +1 -1
  80. package/src/wallets/smart/smart-wallet-zksync.test.ts +1 -1
  81. package/src/wallets/smart/smart-wallet.ts +123 -0
@@ -26,7 +26,6 @@ import {
26
26
  stringToHex,
27
27
  uint8ArrayToHex,
28
28
  } from "../../utils/encoding/hex.js";
29
- import { isReactNative } from "../../utils/platform.js";
30
29
  import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
31
30
  import { COINBASE } from "../constants.js";
32
31
  import type {
@@ -128,20 +127,13 @@ export type CoinbaseSDKWalletConnectionOptions = {
128
127
  // this should be ok since all the creation options are provided at build time
129
128
  let _provider: ProviderInterface | undefined;
130
129
 
131
- async function getCoinbaseProvider(
130
+ /**
131
+ * @internal
132
+ */
133
+ export async function getCoinbaseWebProvider(
132
134
  options?: CreateWalletArgs<typeof COINBASE>[1],
133
135
  ): Promise<ProviderInterface> {
134
136
  if (!_provider) {
135
- if (isReactNative()) {
136
- const { initMobileProvider } = require("./coinbaseMobileSDK.js");
137
- const mobileProvider = initMobileProvider({
138
- chain: options?.chains ? options.chains[0] : undefined,
139
- ...options?.mobileConfig,
140
- });
141
- _provider = mobileProvider;
142
- return mobileProvider;
143
- }
144
-
145
137
  const client = new CoinbaseWalletSDK({
146
138
  appName: options?.appMetadata?.name || getDefaultAppMetadata().name,
147
139
  appChainIds: options?.chains
@@ -186,7 +178,7 @@ export async function coinbaseSDKWalletGetCapabilities(args: {
186
178
  }
187
179
 
188
180
  const config = wallet.getConfig();
189
- const provider = await getCoinbaseProvider(config);
181
+ const provider = await getCoinbaseWebProvider(config);
190
182
  try {
191
183
  return (await provider.request({
192
184
  method: "wallet_getCapabilities",
@@ -212,7 +204,7 @@ export async function coinbaseSDKWalletSendCalls(args: {
212
204
  const { wallet, params } = args;
213
205
 
214
206
  const config = wallet.getConfig();
215
- const provider = await getCoinbaseProvider(config);
207
+ const provider = await getCoinbaseWebProvider(config);
216
208
 
217
209
  try {
218
210
  return (await provider.request({
@@ -238,7 +230,7 @@ export async function coinbaseSDKWalletShowCallsStatus(args: {
238
230
  }) {
239
231
  const { wallet, bundleId } = args;
240
232
 
241
- const provider = await getCoinbaseProvider(wallet.getConfig());
233
+ const provider = await getCoinbaseWebProvider(wallet.getConfig());
242
234
 
243
235
  try {
244
236
  return await provider.request({
@@ -265,7 +257,7 @@ export async function coinbaseSDKWalletGetCallsStatus(args: {
265
257
  const { wallet, bundleId } = args;
266
258
 
267
259
  const config = wallet.getConfig();
268
- const provider = await getCoinbaseProvider(config);
260
+ const provider = await getCoinbaseWebProvider(config);
269
261
 
270
262
  return provider.request({
271
263
  method: "wallet_getCallsStatus",
@@ -402,10 +394,9 @@ function onConnect(
402
394
  */
403
395
  export async function connectCoinbaseWalletSDK(
404
396
  options: WalletConnectionOption<typeof COINBASE>,
405
- createOptions: CreateWalletArgs<typeof COINBASE>[1],
406
397
  emitter: WalletEmitter<typeof COINBASE>,
398
+ provider: ProviderInterface,
407
399
  ): Promise<ReturnType<typeof onConnect>> {
408
- const provider = await getCoinbaseProvider(createOptions);
409
400
  const accounts = (await provider.request({
410
401
  method: "eth_requestAccounts",
411
402
  })) as string[];
@@ -443,11 +434,9 @@ export async function connectCoinbaseWalletSDK(
443
434
  */
444
435
  export async function autoConnectCoinbaseWalletSDK(
445
436
  options: WalletConnectionOption<typeof COINBASE>,
446
- createOptions: CreateWalletArgs<typeof COINBASE>[1],
447
437
  emitter: WalletEmitter<typeof COINBASE>,
438
+ provider: ProviderInterface,
448
439
  ): Promise<ReturnType<typeof onConnect>> {
449
- const provider = await getCoinbaseProvider(createOptions);
450
-
451
440
  // connected accounts
452
441
  const addresses = (await provider.request({
453
442
  method: "eth_accounts",
@@ -8,17 +8,16 @@ import type {
8
8
  CreateWalletArgs,
9
9
  InjectedConnectOptions,
10
10
  WalletAutoConnectionOption,
11
- WalletConnectionOption,
12
11
  WalletId,
13
12
  } from "./wallet-types.js";
14
13
 
15
14
  import { trackConnect } from "../analytics/track.js";
16
15
  import type { ThirdwebClient } from "../client/client.js";
17
- import { getContract } from "../contract/contract.js";
18
- import { isContractDeployed } from "../utils/bytecode/is-contract-deployed.js";
16
+ import { coinbaseWalletSDK } from "./coinbase/coinbase-wallet.js";
17
+ import { getCoinbaseWebProvider } from "./coinbase/coinbaseSDKWallet.js";
19
18
  import { COINBASE } from "./constants.js";
20
19
  import { logoutAuthenticatedUser } from "./in-app/core/authentication/index.js";
21
- import { DEFAULT_ACCOUNT_FACTORY } from "./smart/lib/constants.js";
20
+ import { smartWallet } from "./smart/smart-wallet.js";
22
21
  import type { WCConnectOptions } from "./wallet-connect/types.js";
23
22
  import { createWalletEmitter } from "./wallet-emitter.js";
24
23
 
@@ -69,9 +68,11 @@ export function createWallet<const ID extends WalletId>(
69
68
  * -> if no injected coinbase found, we'll use the coinbase SDK
70
69
  */
71
70
  case COINBASE: {
72
- return coinbaseWalletSDK(
73
- creationOptions as CreateWalletArgs<typeof COINBASE>[1],
74
- ) as Wallet<ID>;
71
+ const options = creationOptions as CreateWalletArgs<typeof COINBASE>[1];
72
+ return coinbaseWalletSDK({
73
+ createOptions: options,
74
+ providerFactory: () => getCoinbaseWebProvider(options),
75
+ }) as Wallet<ID>;
75
76
  }
76
77
 
77
78
  /**
@@ -290,118 +291,6 @@ export function walletConnect() {
290
291
  return createWallet("walletConnect");
291
292
  }
292
293
 
293
- /**
294
- * Creates a smart wallet.
295
- * @param createOptions - The options for creating the wallet.
296
- * @returns The created smart wallet.
297
- * @example
298
- * ```ts
299
- * import { smartWallet } from "thirdweb/wallets";
300
- *
301
- * const wallet = smartWallet({
302
- * chain: sepolia,
303
- * gasless: true,
304
- * });
305
- *
306
- * const account = await wallet.connect({
307
- * client,
308
- * personalAccount: account,
309
- * });
310
- * ```
311
- * @wallet
312
- */
313
- export function smartWallet(
314
- createOptions: CreateWalletArgs<"smart">[1],
315
- ): Wallet<"smart"> {
316
- const emitter = createWalletEmitter<"smart">();
317
- let account: Account | undefined = undefined;
318
- let chain: Chain | undefined = undefined;
319
- let lastConnectOptions: WalletConnectionOption<"smart"> | undefined;
320
-
321
- const _smartWallet: Wallet<"smart"> = {
322
- id: "smart",
323
- subscribe: emitter.subscribe,
324
- getChain: () => chain,
325
- getConfig: () => createOptions,
326
- getAccount: () => account,
327
- autoConnect: async (options) => {
328
- const { connectSmartWallet } = await import("./smart/index.js");
329
- const [connectedAccount, connectedChain] = await connectSmartWallet(
330
- _smartWallet,
331
- options,
332
- createOptions,
333
- );
334
- // set the states
335
- lastConnectOptions = options;
336
- account = connectedAccount;
337
- chain = connectedChain;
338
- trackConnect({
339
- client: options.client,
340
- walletType: "smart",
341
- walletAddress: account.address,
342
- });
343
- // return account
344
- return account;
345
- },
346
- connect: async (options) => {
347
- const { connectSmartWallet } = await import("./smart/index.js");
348
- const [connectedAccount, connectedChain] = await connectSmartWallet(
349
- _smartWallet,
350
- options,
351
- createOptions,
352
- );
353
- // set the states
354
- lastConnectOptions = options;
355
- account = connectedAccount;
356
- chain = connectedChain;
357
- trackConnect({
358
- client: options.client,
359
- walletType: "smart",
360
- walletAddress: account.address,
361
- });
362
- // return account
363
- emitter.emit("accountChanged", account);
364
- return account;
365
- },
366
- disconnect: async () => {
367
- account = undefined;
368
- chain = undefined;
369
- const { disconnectSmartWallet } = await import("./smart/index.js");
370
- await disconnectSmartWallet(_smartWallet);
371
- emitter.emit("disconnect", undefined);
372
- },
373
- switchChain: async (newChain: Chain) => {
374
- if (!lastConnectOptions) {
375
- throw new Error("Cannot switch chain without a previous connection");
376
- }
377
- // check if factory is deployed
378
- const factory = getContract({
379
- address: createOptions.factoryAddress || DEFAULT_ACCOUNT_FACTORY,
380
- chain: newChain,
381
- client: lastConnectOptions.client,
382
- });
383
- const isDeployed = await isContractDeployed(factory);
384
- if (!isDeployed) {
385
- throw new Error(
386
- `Factory contract not deployed on chain: ${newChain.id}`,
387
- );
388
- }
389
- const { connectSmartWallet } = await import("./smart/index.js");
390
- const [connectedAccount, connectedChain] = await connectSmartWallet(
391
- _smartWallet,
392
- { ...lastConnectOptions, chain: newChain },
393
- createOptions,
394
- );
395
- // set the states
396
- account = connectedAccount;
397
- chain = connectedChain;
398
- emitter.emit("chainChanged", newChain);
399
- },
400
- };
401
-
402
- return _smartWallet;
403
- }
404
-
405
294
  /**
406
295
  * Creates an in-app wallet.
407
296
  * @param createOptions - configuration options
@@ -545,97 +434,3 @@ export function inAppWallet(
545
434
  },
546
435
  };
547
436
  }
548
-
549
- /**
550
- * internal helper functions
551
- */
552
-
553
- function coinbaseWalletSDK(
554
- createOptions?: CreateWalletArgs<typeof COINBASE>[1],
555
- ): Wallet<typeof COINBASE> {
556
- const emitter = createWalletEmitter<typeof COINBASE>();
557
- let account: Account | undefined = undefined;
558
- let chain: Chain | undefined = undefined;
559
-
560
- function reset() {
561
- account = undefined;
562
- chain = undefined;
563
- }
564
-
565
- let handleDisconnect = async () => {};
566
-
567
- let handleSwitchChain = async (newChain: Chain) => {
568
- chain = newChain;
569
- };
570
-
571
- const unsubscribeChainChanged = emitter.subscribe(
572
- "chainChanged",
573
- (newChain) => {
574
- chain = newChain;
575
- },
576
- );
577
-
578
- const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
579
- reset();
580
- unsubscribeChainChanged();
581
- unsubscribeDisconnect();
582
- });
583
-
584
- emitter.subscribe("accountChanged", (_account) => {
585
- account = _account;
586
- });
587
-
588
- return {
589
- id: COINBASE,
590
- subscribe: emitter.subscribe,
591
- getChain: () => chain,
592
- getConfig: () => createOptions,
593
- getAccount: () => account,
594
- autoConnect: async (options) => {
595
- const { autoConnectCoinbaseWalletSDK } = await import(
596
- "./coinbase/coinbaseSDKWallet.js"
597
- );
598
- const [connectedAccount, connectedChain, doDisconnect, doSwitchChain] =
599
- await autoConnectCoinbaseWalletSDK(options, createOptions, emitter);
600
- // set the states
601
- account = connectedAccount;
602
- chain = connectedChain;
603
- handleDisconnect = doDisconnect;
604
- handleSwitchChain = doSwitchChain;
605
- trackConnect({
606
- client: options.client,
607
- walletType: COINBASE,
608
- walletAddress: account.address,
609
- });
610
- // return account
611
- return account;
612
- },
613
- connect: async (options) => {
614
- const { connectCoinbaseWalletSDK } = await import(
615
- "./coinbase/coinbaseSDKWallet.js"
616
- );
617
- const [connectedAccount, connectedChain, doDisconnect, doSwitchChain] =
618
- await connectCoinbaseWalletSDK(options, createOptions, emitter);
619
-
620
- // set the states
621
- account = connectedAccount;
622
- chain = connectedChain;
623
- handleDisconnect = doDisconnect;
624
- handleSwitchChain = doSwitchChain;
625
- trackConnect({
626
- client: options.client,
627
- walletType: COINBASE,
628
- walletAddress: account.address,
629
- });
630
- // return account
631
- return account;
632
- },
633
- disconnect: async () => {
634
- reset();
635
- await handleDisconnect();
636
- },
637
- switchChain: async (newChain) => {
638
- await handleSwitchChain(newChain);
639
- },
640
- };
641
- }
@@ -85,7 +85,7 @@ async function convertToSmartAccount(options: {
85
85
  chain?: Chain;
86
86
  }) {
87
87
  const [{ smartWallet }, { connectSmartWallet }] = await Promise.all([
88
- import("../../../create-wallet.js"),
88
+ import("../../../smart/smart-wallet.js"),
89
89
  import("../../../smart/index.js"),
90
90
  ]);
91
91
 
@@ -4,8 +4,8 @@ import { hasSmartAccount } from "../../react/web/utils/isSmartWallet.js";
4
4
  import { computedStore } from "../../reactive/computedStore.js";
5
5
  import { effect } from "../../reactive/effect.js";
6
6
  import { createStore } from "../../reactive/store.js";
7
- import { smartWallet } from "../create-wallet.js";
8
7
  import type { Account, Wallet } from "../interfaces/wallet.js";
8
+ import { smartWallet } from "../smart/smart-wallet.js";
9
9
  import type { SmartWalletOptions } from "../smart/types.js";
10
10
  import type { AsyncStorage } from "../storage/AsyncStorage.js";
11
11
  import { deleteConnectParamsFromStorage } from "../storage/walletStorage.js";
@@ -0,0 +1,224 @@
1
+ // TODO: figure out how to define the type without tuple args type and using function overloads
2
+
3
+ import { trackConnect } from "../../analytics/track.js";
4
+ import type { Chain } from "../../chains/types.js";
5
+ import type { WCSupportedWalletIds } from "../__generated__/wallet-ids.js";
6
+ import { coinbaseWalletSDK } from "../coinbase/coinbase-wallet.js";
7
+ import { getCoinbaseMobileProvider } from "../coinbase/coinbaseMobileSDK.js";
8
+ import { COINBASE } from "../constants.js";
9
+ import type { Account, Wallet } from "../interfaces/wallet.js";
10
+ import { smartWallet } from "../smart/smart-wallet.js";
11
+ import type { WCConnectOptions } from "../wallet-connect/types.js";
12
+ import { createWalletEmitter } from "../wallet-emitter.js";
13
+ import type {
14
+ CreateWalletArgs,
15
+ WalletAutoConnectionOption,
16
+ WalletId,
17
+ } from "../wallet-types.js";
18
+
19
+ /**
20
+ * Creates a wallet based on the provided ID and arguments.
21
+ * @param args - The arguments for creating the wallet.
22
+ * @returns - The created wallet.
23
+ * @example
24
+ * ```ts
25
+ * import { createWallet } from "thirdweb/wallets";
26
+ *
27
+ * const metamaskWallet = createWallet("io.metamask");
28
+ *
29
+ * const account = await metamaskWallet.connect({
30
+ * client,
31
+ * });
32
+ * ```
33
+ * @wallet
34
+ */
35
+ export function createWallet<const ID extends WalletId>(
36
+ ...args: CreateWalletArgs<ID>
37
+ ): Wallet<ID> {
38
+ const [id, creationOptions] = args;
39
+
40
+ switch (id) {
41
+ /**
42
+ * SMART WALLET
43
+ */
44
+ case "smart": {
45
+ // same as web
46
+ return smartWallet(
47
+ creationOptions as CreateWalletArgs<"smart">[1],
48
+ ) as Wallet<ID>;
49
+ }
50
+ /**
51
+ * IN-APP WALLET
52
+ */
53
+ case "embedded":
54
+ case "inApp": {
55
+ // TODO pass RN connector
56
+ throw new Error("TODO");
57
+ // return inAppWallet(
58
+ // creationOptions as CreateWalletArgs<"inApp">[1],
59
+ // ) as Wallet<ID>;
60
+ }
61
+
62
+ /**
63
+ * COINBASE WALLET VIA SDK
64
+ * -> if no injected coinbase found, we'll use the coinbase SDK
65
+ */
66
+ case COINBASE: {
67
+ const options = creationOptions as CreateWalletArgs<typeof COINBASE>[1];
68
+ return coinbaseWalletSDK({
69
+ createOptions: options,
70
+ providerFactory: () => getCoinbaseMobileProvider(options),
71
+ }) as Wallet<ID>;
72
+ }
73
+
74
+ /**
75
+ * WALLET CONNECT AND INJECTED WALLETS + walletConnect standalone
76
+ * TODO extract into a core + inject storage and link open callback
77
+ */
78
+ default: {
79
+ const emitter = createWalletEmitter<ID>();
80
+ let account: Account | undefined = undefined;
81
+ let chain: Chain | undefined = undefined;
82
+
83
+ const unsubscribeChain = emitter.subscribe("chainChanged", (newChain) => {
84
+ chain = newChain;
85
+ });
86
+
87
+ function reset() {
88
+ account = undefined;
89
+ chain = undefined;
90
+ }
91
+
92
+ let handleDisconnect = async () => {};
93
+
94
+ const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
95
+ reset();
96
+ unsubscribeChain();
97
+ unsubscribeDisconnect();
98
+ });
99
+
100
+ emitter.subscribe("accountChanged", (_account) => {
101
+ account = _account;
102
+ });
103
+
104
+ let handleSwitchChain: (chain: Chain) => Promise<void> = async () => {
105
+ throw new Error("Not implemented yet");
106
+ };
107
+
108
+ const wallet: Wallet<ID> = {
109
+ id,
110
+ subscribe: emitter.subscribe,
111
+ getConfig: () => args[1],
112
+ getChain: () => chain,
113
+ getAccount: () => account,
114
+ autoConnect: async (
115
+ options: WalletAutoConnectionOption<WCSupportedWalletIds>,
116
+ ) => {
117
+ if (options && "client" in options) {
118
+ const { autoConnectWC } = await import(
119
+ "../wallet-connect/controller.js"
120
+ );
121
+
122
+ const [
123
+ connectedAccount,
124
+ connectedChain,
125
+ doDisconnect,
126
+ doSwitchChain,
127
+ ] = await autoConnectWC(
128
+ options,
129
+ emitter,
130
+ wallet.id as WCSupportedWalletIds,
131
+ );
132
+ // set the states
133
+ account = connectedAccount;
134
+ chain = connectedChain;
135
+ handleDisconnect = doDisconnect;
136
+ handleSwitchChain = doSwitchChain;
137
+ trackConnect({
138
+ client: options.client,
139
+ walletType: id,
140
+ walletAddress: account.address,
141
+ });
142
+ // return account
143
+ return account;
144
+ }
145
+ throw new Error("Failed to auto connect");
146
+ },
147
+ connect: async (options) => {
148
+ async function wcConnect(wcOptions: WCConnectOptions) {
149
+ const { connectWC } = await import(
150
+ "../wallet-connect/controller.js"
151
+ );
152
+
153
+ const [
154
+ connectedAccount,
155
+ connectedChain,
156
+ doDisconnect,
157
+ doSwitchChain,
158
+ ] = await connectWC(
159
+ wcOptions,
160
+ emitter,
161
+ wallet.id as WCSupportedWalletIds | "walletConnect",
162
+ );
163
+ // set the states
164
+ account = connectedAccount;
165
+ chain = connectedChain;
166
+ handleDisconnect = doDisconnect;
167
+ handleSwitchChain = doSwitchChain;
168
+ trackConnect({
169
+ client: wcOptions.client,
170
+ walletType: id,
171
+ walletAddress: account.address,
172
+ });
173
+ return account;
174
+ }
175
+
176
+ if (id === "walletConnect") {
177
+ const { client, chain: _chain, ...walletConnectOptions } = options;
178
+
179
+ return wcConnect({
180
+ client,
181
+ chain: _chain,
182
+ walletConnect: {
183
+ ...walletConnectOptions,
184
+ },
185
+ });
186
+ }
187
+
188
+ if (options && "client" in options) {
189
+ return wcConnect(options);
190
+ }
191
+ throw new Error("Failed to connect");
192
+ },
193
+ // these get overridden in connect and autoConnect
194
+ disconnect: async () => {
195
+ reset();
196
+ await handleDisconnect();
197
+ },
198
+ switchChain: (c) => handleSwitchChain(c),
199
+ };
200
+ return wallet;
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Creates a wallet that allows connecting to any wallet that supports the WalletConnect protocol.
207
+ * @returns The created smart wallet.
208
+ * @example
209
+ * ```ts
210
+ * import { walletConnect } from "thirdweb/wallets";
211
+ *
212
+ * const wallet = walletConnect();
213
+ *
214
+ * const account = await wallet.connect({
215
+ * client
216
+ * });
217
+ * ```
218
+ * @wallet
219
+ */
220
+ export function walletConnect() {
221
+ return createWallet("walletConnect");
222
+ }
223
+
224
+ // TODO in-app wallet
@@ -18,9 +18,9 @@ import { estimateGasCost } from "../../transaction/actions/estimate-gas-cost.js"
18
18
  import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
19
19
  import { sendBatchTransaction } from "../../transaction/actions/send-batch-transaction.js";
20
20
  import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
21
- import { smartWallet } from "../create-wallet.js";
22
21
  import type { Account, Wallet } from "../interfaces/wallet.js";
23
22
  import { generateAccount } from "../utils/generateAccount.js";
23
+ import { smartWallet } from "./smart-wallet.js";
24
24
 
25
25
  let wallet: Wallet;
26
26
  let smartAccount: Account;
@@ -7,9 +7,9 @@ import { getContract } from "../../contract/contract.js";
7
7
  import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
8
8
  import { sendTransaction } from "../../transaction/actions/send-transaction.js";
9
9
  import { prepareTransaction } from "../../transaction/prepare-transaction.js";
10
- import { smartWallet } from "../create-wallet.js";
11
10
  import type { Account, Wallet } from "../interfaces/wallet.js";
12
11
  import { privateKeyToAccount } from "../private-key.js";
12
+ import { smartWallet } from "./smart-wallet.js";
13
13
 
14
14
  let wallet: Wallet;
15
15
  let smartAccount: Account;