@lukso/up-connector 0.8.5-dev.2df3eae → 0.8.5-dev.caea45e

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/src/auto-setup.ts CHANGED
@@ -1,362 +1,17 @@
1
1
  /**
2
2
  * Auto-setup utilities for LUKSO products
3
3
  *
4
- * Provides zero-config setup for:
5
- * - Embedded Wallet (passkey-based)
6
- * - UP Extension (browser extension)
7
- * - UP Mobile (WalletConnect)
8
- */
9
-
10
- import { setupConnectModal } from '@lukso/up-modal/connect-modal'
11
- import type { Config } from '@wagmi/core'
12
-
13
- /**
14
- * Embedded wallet constants
15
- */
16
- export const EMBEDDED_WALLET_ID = 'dev.lukso.auth'
17
- export const EMBEDDED_WALLET_URL_DEV = 'http://localhost:9100'
18
- export const EMBEDDED_WALLET_URL_PROD =
19
- 'https://feed.api.universalprofile.cloud'
20
-
21
- /**
22
- * UP Extension ID
23
- */
24
- export const UP_EXTENSION_ID = 'cloud.universalprofile'
25
-
26
- /**
27
- * Get default wallet URL based on environment
28
- */
29
- function getDefaultWalletUrl(): string {
30
- // Check for environment variable (CI builds)
31
- if (typeof process !== 'undefined' && process.env?.WALLET_URL) {
32
- return process.env.WALLET_URL
33
- }
34
-
35
- // Check if we're in production (browser)
36
- if (typeof window !== 'undefined') {
37
- const isLocalhost =
38
- window.location.hostname === 'localhost' ||
39
- window.location.hostname === '127.0.0.1'
40
- return isLocalhost ? EMBEDDED_WALLET_URL_DEV : EMBEDDED_WALLET_URL_PROD
41
- }
42
-
43
- // Default to dev
44
- return EMBEDDED_WALLET_URL_DEV
45
- }
46
-
47
- export interface LuksoConnectorConfig {
48
- /**
49
- * Embedded wallet configuration
50
- */
51
- embeddedWallet?: {
52
- /**
53
- * Enable embedded wallet option (default: true)
54
- */
55
- enabled?: boolean
56
-
57
- /**
58
- * URL to the wallet service
59
- * @default 'http://localhost:9100'
60
- */
61
- url?: string
62
-
63
- /**
64
- * Storage key for UP Provider state
65
- * @default 'up-provider'
66
- */
67
- storageKey?: string
68
-
69
- /**
70
- * Display name for the wallet
71
- * @default 'Create Passkey Wallet'
72
- */
73
- name?: string
74
- }
75
-
76
- /**
77
- * WalletConnect configuration for mobile app
78
- */
79
- walletConnect?: {
80
- /**
81
- * Enable WalletConnect (default: true)
82
- */
83
- enabled?: boolean
84
-
85
- /**
86
- * WalletConnect Project ID
87
- * @default LUKSO's default project ID
88
- */
89
- projectId?: string
90
-
91
- /**
92
- * Show QR code modal on mobile devices (default: false)
93
- */
94
- showQrModal?: boolean
95
- }
96
-
97
- /**
98
- * Chain configuration
99
- */
100
- chains?: {
101
- /**
102
- * Default chain ID
103
- * @default 42 (LUKSO mainnet)
104
- */
105
- defaultChainId?: number
106
-
107
- /**
108
- * Enable testnet (default: true)
109
- */
110
- enableTestnet?: boolean
111
- }
112
-
113
- /**
114
- * Storage configuration
115
- */
116
- storage?: {
117
- /**
118
- * Storage key prefix for wagmi state
119
- * @default 'up-wagmi'
120
- */
121
- key?: string
122
- }
123
-
124
- /**
125
- * Pass an existing wagmi config instead of auto-creating one
126
- */
127
- wagmiConfig?: any
128
- }
129
-
130
- const DEFAULT_CONFIG: Required<LuksoConnectorConfig> = {
131
- embeddedWallet: {
132
- enabled: true,
133
- url: getDefaultWalletUrl(),
134
- storageKey: 'up-provider',
135
- name: 'UE Embedded Wallet',
136
- },
137
- walletConnect: {
138
- enabled: true,
139
- projectId: '7d1af65dc2722192d9914b5d6eaeb421', // LUKSO's default
140
- showQrModal: false,
141
- },
142
- chains: {
143
- defaultChainId: 42, // LUKSO mainnet
144
- enableTestnet: true,
145
- },
146
- storage: {
147
- key: 'up-wagmi',
148
- },
149
- wagmiConfig: undefined,
150
- }
151
-
152
- /**
153
- * Auto-setup LUKSO connector with sensible defaults
154
- *
155
- * This function creates a wagmi config and sets up the connect modal
156
- * with support for:
157
- * - Embedded Wallet (passkey-based)
158
- * - UP Extension (auto-detected via EIP-6963)
159
- * - UP Mobile (WalletConnect)
160
- *
161
- * @example
162
- * ```typescript
163
- * // Zero config - uses all defaults
164
- * setupLuksoConnector()
165
- *
166
- * // Custom configuration
167
- * setupLuksoConnector({
168
- * embeddedWallet: {
169
- * url: 'https://wallet.example.com'
170
- * },
171
- * chains: {
172
- * defaultChainId: 4201 // LUKSO Testnet
173
- * }
174
- * })
175
- * ```
176
- */
177
- export async function setupLuksoConnector(
178
- config: LuksoConnectorConfig = {}
179
- ): Promise<{ wagmiConfig: Config }> {
180
- const cfg = {
181
- embeddedWallet: {
182
- ...DEFAULT_CONFIG.embeddedWallet,
183
- ...config.embeddedWallet,
184
- } as Required<typeof DEFAULT_CONFIG.embeddedWallet>,
185
- walletConnect: {
186
- ...DEFAULT_CONFIG.walletConnect,
187
- ...config.walletConnect,
188
- } as Required<typeof DEFAULT_CONFIG.walletConnect>,
189
- chains: {
190
- ...DEFAULT_CONFIG.chains,
191
- ...config.chains,
192
- } as Required<typeof DEFAULT_CONFIG.chains>,
193
- storage: {
194
- ...DEFAULT_CONFIG.storage,
195
- ...config.storage,
196
- } as Required<typeof DEFAULT_CONFIG.storage>,
197
- wagmiConfig: config.wagmiConfig,
198
- }
199
-
200
- // IMPORTANT: Create UP Provider BEFORE wagmi config
201
- // The UP Provider registers via EIP-6963, and wagmi's injected() will detect it
202
- // This matches the order in demo-app: UP Provider first, then wagmi config
203
-
204
- // Step 1: Create UP Provider (if enabled)
205
- if (cfg.embeddedWallet?.enabled) {
206
- await createUPProvider(cfg.embeddedWallet)
207
- }
208
-
209
- // Step 2: Create or use provided wagmi config
210
- const wagmiConfig = cfg.wagmiConfig || (await createWagmiConfig(cfg))
211
-
212
- // Note: Wagmi will auto-reconnect in the background
213
- // The connector's watchWagmiAccount will detect the connection when it completes
214
-
215
- // Step 3: Setup connect modal
216
- // The UP Provider is already registered via EIP-6963 and will appear in wagmi connectors
217
- // Use the embedded wallet ID to identify it in the connector list
218
- setupConnectModal({
219
- wagmiConfig,
220
- chainId: cfg.chains.defaultChainId,
221
- embeddedWalletId: cfg.embeddedWallet.enabled
222
- ? EMBEDDED_WALLET_ID
223
- : undefined,
224
- })
225
-
226
- return { wagmiConfig }
227
- }
228
-
229
- /**
230
- * Create wagmi config with LUKSO chains and connectors
231
- */
232
- async function createWagmiConfig(cfg: any): Promise<any> {
233
- try {
234
- // Dynamic imports to keep dependencies optional
235
- const [
236
- { createConfig, createStorage, injected },
237
- { walletConnect },
238
- { createClient, http },
239
- { lukso, luksoTestnet },
240
- ] = await Promise.all([
241
- import('@wagmi/core'),
242
- import('@wagmi/connectors'),
243
- import('viem'),
244
- import('viem/chains'),
245
- ])
246
-
247
- // Create storage adapter
248
- const storage = createStorage({
249
- key: cfg.storage.key,
250
- storage: getDefaultStorage(),
251
- })
252
-
253
- // Build chains array
254
- const chains = cfg.chains.enableTestnet
255
- ? ([luksoTestnet, lukso] as const)
256
- : ([lukso] as const)
257
-
258
- // Build connectors array
259
- const connectors = []
260
-
261
- // Add WalletConnect if enabled
262
- if (cfg.walletConnect.enabled) {
263
- connectors.push(
264
- walletConnect({
265
- projectId: cfg.walletConnect.projectId,
266
- showQrModal: cfg.walletConnect.showQrModal,
267
- })
268
- )
269
- }
270
-
271
- // Add injected (for UP Extension and other EIP-6963 wallets)
272
- connectors.push(injected())
273
-
274
- // Create wagmi config
275
- return createConfig({
276
- storage,
277
- multiInjectedProviderDiscovery: true, // Enable EIP-6963
278
- connectors,
279
- chains,
280
- client({ chain }: any) {
281
- return createClient({ chain, transport: http() })
282
- },
283
- })
284
- } catch (error) {
285
- console.error('Failed to create wagmi config:', error)
286
- throw new Error(
287
- 'Failed to create wagmi config. Make sure @wagmi/core, @wagmi/connectors, and viem are installed.'
288
- )
289
- }
290
- }
291
-
292
- /**
293
- * Create UP Provider (registers via EIP-6963)
294
- */
295
- async function createUPProvider(config: {
296
- url: string
297
- storageKey: string
298
- name: string
299
- }): Promise<void> {
300
- // Validate URL - throw error if explicitly set to empty string
301
- if (config.url != null && config.url.trim() === '') {
302
- throw new Error(
303
- 'UP Provider URL is defined but empty. Please set WALLET_URL environment variable to a valid URL or leave it undefined.'
304
- )
305
- }
306
-
307
- try {
308
- const { createClientUPProvider } = await import('@lukso/up-provider')
309
-
310
- // Create UP Provider - it automatically registers via EIP-6963
311
- createClientUPProvider({
312
- url: config.url,
313
- mode: 'iframe',
314
- get: async () => {
315
- const stored = localStorage.getItem(config.storageKey)
316
- return stored ? JSON.parse(stored) : {}
317
- },
318
- set: async (value: Record<string, unknown>) => {
319
- localStorage.setItem(config.storageKey, JSON.stringify(value))
320
- },
321
- name: config.name,
322
- })
323
-
324
- // Wait for EIP-6963 registration
325
- await new Promise((resolve) => setTimeout(resolve, 100))
326
- } catch (error) {
327
- console.warn('⚠️ Failed to create UP Provider:', error)
328
- throw error
329
- }
330
- }
331
-
332
- /**
333
- * Default storage adapter (localStorage with error handling)
334
- */
335
- function getDefaultStorage() {
336
- const storage = (() => {
337
- if (typeof window !== 'undefined' && window.localStorage) {
338
- return window.localStorage
339
- }
340
- return {
341
- getItem: () => null,
342
- setItem: () => {},
343
- removeItem: () => {},
344
- }
345
- })()
346
-
347
- return {
348
- getItem(key: string) {
349
- return storage.getItem(key)
350
- },
351
- removeItem(key: string) {
352
- storage.removeItem(key)
353
- },
354
- setItem(key: string, value: string) {
355
- try {
356
- storage.setItem(key, value)
357
- } catch {
358
- // Silence QuotaExceededError, SecurityError, etc.
359
- }
360
- },
361
- }
362
- }
4
+ * Re-exports the canonical implementation from @lukso/up-modal.
5
+ * setupLuksoConnector now returns a LuksoConnector instance with
6
+ * showSignInModal() / closeModal() instead of a plain { wagmiConfig } object.
7
+ */
8
+
9
+ export type { LuksoConnectorConfig } from '@lukso/up-modal'
10
+ export {
11
+ EMBEDDED_WALLET_ID,
12
+ EMBEDDED_WALLET_URL_DEV,
13
+ EMBEDDED_WALLET_URL_PROD,
14
+ LuksoConnector,
15
+ setupLuksoConnector,
16
+ UP_EXTENSION_ID,
17
+ } from '@lukso/up-modal'
package/src/index.ts CHANGED
@@ -33,6 +33,7 @@ export {
33
33
  EMBEDDED_WALLET_ID,
34
34
  EMBEDDED_WALLET_URL_DEV,
35
35
  EMBEDDED_WALLET_URL_PROD,
36
+ LuksoConnector,
36
37
  setupLuksoConnector,
37
38
  UP_EXTENSION_ID,
38
39
  } from './auto-setup.js'
@@ -1,178 +0,0 @@
1
- // src/auto-setup.ts
2
- import { setupConnectModal } from "@lukso/up-modal/connect-modal";
3
- var EMBEDDED_WALLET_ID = "dev.lukso.auth";
4
- var EMBEDDED_WALLET_URL_DEV = "http://localhost:9100";
5
- var EMBEDDED_WALLET_URL_PROD = "https://feed.api.universalprofile.cloud";
6
- var UP_EXTENSION_ID = "cloud.universalprofile";
7
- function getDefaultWalletUrl() {
8
- if (typeof process !== "undefined" && process.env?.WALLET_URL) {
9
- return process.env.WALLET_URL;
10
- }
11
- if (typeof window !== "undefined") {
12
- const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
13
- return isLocalhost ? EMBEDDED_WALLET_URL_DEV : EMBEDDED_WALLET_URL_PROD;
14
- }
15
- return EMBEDDED_WALLET_URL_DEV;
16
- }
17
- var DEFAULT_CONFIG = {
18
- embeddedWallet: {
19
- enabled: true,
20
- url: getDefaultWalletUrl(),
21
- storageKey: "up-provider",
22
- name: "UE Embedded Wallet"
23
- },
24
- walletConnect: {
25
- enabled: true,
26
- projectId: "7d1af65dc2722192d9914b5d6eaeb421",
27
- // LUKSO's default
28
- showQrModal: false
29
- },
30
- chains: {
31
- defaultChainId: 42,
32
- // LUKSO mainnet
33
- enableTestnet: true
34
- },
35
- storage: {
36
- key: "up-wagmi"
37
- },
38
- wagmiConfig: void 0
39
- };
40
- async function setupLuksoConnector(config = {}) {
41
- const cfg = {
42
- embeddedWallet: {
43
- ...DEFAULT_CONFIG.embeddedWallet,
44
- ...config.embeddedWallet
45
- },
46
- walletConnect: {
47
- ...DEFAULT_CONFIG.walletConnect,
48
- ...config.walletConnect
49
- },
50
- chains: {
51
- ...DEFAULT_CONFIG.chains,
52
- ...config.chains
53
- },
54
- storage: {
55
- ...DEFAULT_CONFIG.storage,
56
- ...config.storage
57
- },
58
- wagmiConfig: config.wagmiConfig
59
- };
60
- if (cfg.embeddedWallet?.enabled) {
61
- await createUPProvider(cfg.embeddedWallet);
62
- }
63
- const wagmiConfig = cfg.wagmiConfig || await createWagmiConfig(cfg);
64
- setupConnectModal({
65
- wagmiConfig,
66
- chainId: cfg.chains.defaultChainId,
67
- embeddedWalletId: cfg.embeddedWallet.enabled ? EMBEDDED_WALLET_ID : void 0
68
- });
69
- return { wagmiConfig };
70
- }
71
- async function createWagmiConfig(cfg) {
72
- try {
73
- const [
74
- { createConfig, createStorage, injected },
75
- { walletConnect },
76
- { createClient, http },
77
- { lukso, luksoTestnet }
78
- ] = await Promise.all([
79
- import("@wagmi/core"),
80
- import("@wagmi/connectors"),
81
- import("viem"),
82
- import("viem/chains")
83
- ]);
84
- const storage = createStorage({
85
- key: cfg.storage.key,
86
- storage: getDefaultStorage()
87
- });
88
- const chains = cfg.chains.enableTestnet ? [luksoTestnet, lukso] : [lukso];
89
- const connectors = [];
90
- if (cfg.walletConnect.enabled) {
91
- connectors.push(
92
- walletConnect({
93
- projectId: cfg.walletConnect.projectId,
94
- showQrModal: cfg.walletConnect.showQrModal
95
- })
96
- );
97
- }
98
- connectors.push(injected());
99
- return createConfig({
100
- storage,
101
- multiInjectedProviderDiscovery: true,
102
- // Enable EIP-6963
103
- connectors,
104
- chains,
105
- client({ chain }) {
106
- return createClient({ chain, transport: http() });
107
- }
108
- });
109
- } catch (error) {
110
- console.error("Failed to create wagmi config:", error);
111
- throw new Error(
112
- "Failed to create wagmi config. Make sure @wagmi/core, @wagmi/connectors, and viem are installed."
113
- );
114
- }
115
- }
116
- async function createUPProvider(config) {
117
- if (config.url != null && config.url.trim() === "") {
118
- throw new Error(
119
- "UP Provider URL is defined but empty. Please set WALLET_URL environment variable to a valid URL or leave it undefined."
120
- );
121
- }
122
- try {
123
- const { createClientUPProvider } = await import("@lukso/up-provider");
124
- createClientUPProvider({
125
- url: config.url,
126
- mode: "iframe",
127
- get: async () => {
128
- const stored = localStorage.getItem(config.storageKey);
129
- return stored ? JSON.parse(stored) : {};
130
- },
131
- set: async (value) => {
132
- localStorage.setItem(config.storageKey, JSON.stringify(value));
133
- },
134
- name: config.name
135
- });
136
- await new Promise((resolve) => setTimeout(resolve, 100));
137
- } catch (error) {
138
- console.warn("\u26A0\uFE0F Failed to create UP Provider:", error);
139
- throw error;
140
- }
141
- }
142
- function getDefaultStorage() {
143
- const storage = (() => {
144
- if (typeof window !== "undefined" && window.localStorage) {
145
- return window.localStorage;
146
- }
147
- return {
148
- getItem: () => null,
149
- setItem: () => {
150
- },
151
- removeItem: () => {
152
- }
153
- };
154
- })();
155
- return {
156
- getItem(key) {
157
- return storage.getItem(key);
158
- },
159
- removeItem(key) {
160
- storage.removeItem(key);
161
- },
162
- setItem(key, value) {
163
- try {
164
- storage.setItem(key, value);
165
- } catch {
166
- }
167
- }
168
- };
169
- }
170
-
171
- export {
172
- EMBEDDED_WALLET_ID,
173
- EMBEDDED_WALLET_URL_DEV,
174
- EMBEDDED_WALLET_URL_PROD,
175
- UP_EXTENSION_ID,
176
- setupLuksoConnector
177
- };
178
- //# sourceMappingURL=chunk-LXK6OUTM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/auto-setup.ts"],"sourcesContent":["/**\n * Auto-setup utilities for LUKSO products\n *\n * Provides zero-config setup for:\n * - Embedded Wallet (passkey-based)\n * - UP Extension (browser extension)\n * - UP Mobile (WalletConnect)\n */\n\nimport { setupConnectModal } from '@lukso/up-modal/connect-modal'\nimport type { Config } from '@wagmi/core'\n\n/**\n * Embedded wallet constants\n */\nexport const EMBEDDED_WALLET_ID = 'dev.lukso.auth'\nexport const EMBEDDED_WALLET_URL_DEV = 'http://localhost:9100'\nexport const EMBEDDED_WALLET_URL_PROD =\n 'https://feed.api.universalprofile.cloud'\n\n/**\n * UP Extension ID\n */\nexport const UP_EXTENSION_ID = 'cloud.universalprofile'\n\n/**\n * Get default wallet URL based on environment\n */\nfunction getDefaultWalletUrl(): string {\n // Check for environment variable (CI builds)\n if (typeof process !== 'undefined' && process.env?.WALLET_URL) {\n return process.env.WALLET_URL\n }\n\n // Check if we're in production (browser)\n if (typeof window !== 'undefined') {\n const isLocalhost =\n window.location.hostname === 'localhost' ||\n window.location.hostname === '127.0.0.1'\n return isLocalhost ? EMBEDDED_WALLET_URL_DEV : EMBEDDED_WALLET_URL_PROD\n }\n\n // Default to dev\n return EMBEDDED_WALLET_URL_DEV\n}\n\nexport interface LuksoConnectorConfig {\n /**\n * Embedded wallet configuration\n */\n embeddedWallet?: {\n /**\n * Enable embedded wallet option (default: true)\n */\n enabled?: boolean\n\n /**\n * URL to the wallet service\n * @default 'http://localhost:9100'\n */\n url?: string\n\n /**\n * Storage key for UP Provider state\n * @default 'up-provider'\n */\n storageKey?: string\n\n /**\n * Display name for the wallet\n * @default 'Create Passkey Wallet'\n */\n name?: string\n }\n\n /**\n * WalletConnect configuration for mobile app\n */\n walletConnect?: {\n /**\n * Enable WalletConnect (default: true)\n */\n enabled?: boolean\n\n /**\n * WalletConnect Project ID\n * @default LUKSO's default project ID\n */\n projectId?: string\n\n /**\n * Show QR code modal on mobile devices (default: false)\n */\n showQrModal?: boolean\n }\n\n /**\n * Chain configuration\n */\n chains?: {\n /**\n * Default chain ID\n * @default 42 (LUKSO mainnet)\n */\n defaultChainId?: number\n\n /**\n * Enable testnet (default: true)\n */\n enableTestnet?: boolean\n }\n\n /**\n * Storage configuration\n */\n storage?: {\n /**\n * Storage key prefix for wagmi state\n * @default 'up-wagmi'\n */\n key?: string\n }\n\n /**\n * Pass an existing wagmi config instead of auto-creating one\n */\n wagmiConfig?: any\n}\n\nconst DEFAULT_CONFIG: Required<LuksoConnectorConfig> = {\n embeddedWallet: {\n enabled: true,\n url: getDefaultWalletUrl(),\n storageKey: 'up-provider',\n name: 'UE Embedded Wallet',\n },\n walletConnect: {\n enabled: true,\n projectId: '7d1af65dc2722192d9914b5d6eaeb421', // LUKSO's default\n showQrModal: false,\n },\n chains: {\n defaultChainId: 42, // LUKSO mainnet\n enableTestnet: true,\n },\n storage: {\n key: 'up-wagmi',\n },\n wagmiConfig: undefined,\n}\n\n/**\n * Auto-setup LUKSO connector with sensible defaults\n *\n * This function creates a wagmi config and sets up the connect modal\n * with support for:\n * - Embedded Wallet (passkey-based)\n * - UP Extension (auto-detected via EIP-6963)\n * - UP Mobile (WalletConnect)\n *\n * @example\n * ```typescript\n * // Zero config - uses all defaults\n * setupLuksoConnector()\n *\n * // Custom configuration\n * setupLuksoConnector({\n * embeddedWallet: {\n * url: 'https://wallet.example.com'\n * },\n * chains: {\n * defaultChainId: 4201 // LUKSO Testnet\n * }\n * })\n * ```\n */\nexport async function setupLuksoConnector(\n config: LuksoConnectorConfig = {}\n): Promise<{ wagmiConfig: Config }> {\n const cfg = {\n embeddedWallet: {\n ...DEFAULT_CONFIG.embeddedWallet,\n ...config.embeddedWallet,\n } as Required<typeof DEFAULT_CONFIG.embeddedWallet>,\n walletConnect: {\n ...DEFAULT_CONFIG.walletConnect,\n ...config.walletConnect,\n } as Required<typeof DEFAULT_CONFIG.walletConnect>,\n chains: {\n ...DEFAULT_CONFIG.chains,\n ...config.chains,\n } as Required<typeof DEFAULT_CONFIG.chains>,\n storage: {\n ...DEFAULT_CONFIG.storage,\n ...config.storage,\n } as Required<typeof DEFAULT_CONFIG.storage>,\n wagmiConfig: config.wagmiConfig,\n }\n\n // IMPORTANT: Create UP Provider BEFORE wagmi config\n // The UP Provider registers via EIP-6963, and wagmi's injected() will detect it\n // This matches the order in demo-app: UP Provider first, then wagmi config\n\n // Step 1: Create UP Provider (if enabled)\n if (cfg.embeddedWallet?.enabled) {\n await createUPProvider(cfg.embeddedWallet)\n }\n\n // Step 2: Create or use provided wagmi config\n const wagmiConfig = cfg.wagmiConfig || (await createWagmiConfig(cfg))\n\n // Note: Wagmi will auto-reconnect in the background\n // The connector's watchWagmiAccount will detect the connection when it completes\n\n // Step 3: Setup connect modal\n // The UP Provider is already registered via EIP-6963 and will appear in wagmi connectors\n // Use the embedded wallet ID to identify it in the connector list\n setupConnectModal({\n wagmiConfig,\n chainId: cfg.chains.defaultChainId,\n embeddedWalletId: cfg.embeddedWallet.enabled\n ? EMBEDDED_WALLET_ID\n : undefined,\n })\n\n return { wagmiConfig }\n}\n\n/**\n * Create wagmi config with LUKSO chains and connectors\n */\nasync function createWagmiConfig(cfg: any): Promise<any> {\n try {\n // Dynamic imports to keep dependencies optional\n const [\n { createConfig, createStorage, injected },\n { walletConnect },\n { createClient, http },\n { lukso, luksoTestnet },\n ] = await Promise.all([\n import('@wagmi/core'),\n import('@wagmi/connectors'),\n import('viem'),\n import('viem/chains'),\n ])\n\n // Create storage adapter\n const storage = createStorage({\n key: cfg.storage.key,\n storage: getDefaultStorage(),\n })\n\n // Build chains array\n const chains = cfg.chains.enableTestnet\n ? ([luksoTestnet, lukso] as const)\n : ([lukso] as const)\n\n // Build connectors array\n const connectors = []\n\n // Add WalletConnect if enabled\n if (cfg.walletConnect.enabled) {\n connectors.push(\n walletConnect({\n projectId: cfg.walletConnect.projectId,\n showQrModal: cfg.walletConnect.showQrModal,\n })\n )\n }\n\n // Add injected (for UP Extension and other EIP-6963 wallets)\n connectors.push(injected())\n\n // Create wagmi config\n return createConfig({\n storage,\n multiInjectedProviderDiscovery: true, // Enable EIP-6963\n connectors,\n chains,\n client({ chain }: any) {\n return createClient({ chain, transport: http() })\n },\n })\n } catch (error) {\n console.error('Failed to create wagmi config:', error)\n throw new Error(\n 'Failed to create wagmi config. Make sure @wagmi/core, @wagmi/connectors, and viem are installed.'\n )\n }\n}\n\n/**\n * Create UP Provider (registers via EIP-6963)\n */\nasync function createUPProvider(config: {\n url: string\n storageKey: string\n name: string\n}): Promise<void> {\n // Validate URL - throw error if explicitly set to empty string\n if (config.url != null && config.url.trim() === '') {\n throw new Error(\n 'UP Provider URL is defined but empty. Please set WALLET_URL environment variable to a valid URL or leave it undefined.'\n )\n }\n\n try {\n const { createClientUPProvider } = await import('@lukso/up-provider')\n\n // Create UP Provider - it automatically registers via EIP-6963\n createClientUPProvider({\n url: config.url,\n mode: 'iframe',\n get: async () => {\n const stored = localStorage.getItem(config.storageKey)\n return stored ? JSON.parse(stored) : {}\n },\n set: async (value: Record<string, unknown>) => {\n localStorage.setItem(config.storageKey, JSON.stringify(value))\n },\n name: config.name,\n })\n\n // Wait for EIP-6963 registration\n await new Promise((resolve) => setTimeout(resolve, 100))\n } catch (error) {\n console.warn('⚠️ Failed to create UP Provider:', error)\n throw error\n }\n}\n\n/**\n * Default storage adapter (localStorage with error handling)\n */\nfunction getDefaultStorage() {\n const storage = (() => {\n if (typeof window !== 'undefined' && window.localStorage) {\n return window.localStorage\n }\n return {\n getItem: () => null,\n setItem: () => {},\n removeItem: () => {},\n }\n })()\n\n return {\n getItem(key: string) {\n return storage.getItem(key)\n },\n removeItem(key: string) {\n storage.removeItem(key)\n },\n setItem(key: string, value: string) {\n try {\n storage.setItem(key, value)\n } catch {\n // Silence QuotaExceededError, SecurityError, etc.\n }\n },\n }\n}\n"],"mappings":";AASA,SAAS,yBAAyB;AAM3B,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAChC,IAAM,2BACX;AAKK,IAAM,kBAAkB;AAK/B,SAAS,sBAA8B;AAErC,MAAI,OAAO,YAAY,eAAe,QAAQ,KAAK,YAAY;AAC7D,WAAO,QAAQ,IAAI;AAAA,EACrB;AAGA,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,cACJ,OAAO,SAAS,aAAa,eAC7B,OAAO,SAAS,aAAa;AAC/B,WAAO,cAAc,0BAA0B;AAAA,EACjD;AAGA,SAAO;AACT;AAqFA,IAAM,iBAAiD;AAAA,EACrD,gBAAgB;AAAA,IACd,SAAS;AAAA,IACT,KAAK,oBAAoB;AAAA,IACzB,YAAY;AAAA,IACZ,MAAM;AAAA,EACR;AAAA,EACA,eAAe;A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