@lukso/up-connector 0.5.0 → 0.5.1-dev.e515cef
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/dist/auto-setup.cjs +3 -3
- package/dist/auto-setup.js +2 -2
- package/dist/{chunk-PB7QP3SJ.cjs → chunk-GCYDV7FB.cjs} +159 -91
- package/dist/chunk-GCYDV7FB.cjs.map +1 -0
- package/dist/{chunk-LCF5SJOE.js → chunk-KMCCANMJ.js} +4 -4
- package/dist/{chunk-LCF5SJOE.js.map → chunk-KMCCANMJ.js.map} +1 -1
- package/dist/{chunk-4PC7ZTI7.js → chunk-SAQWNAQ6.js} +138 -70
- package/dist/chunk-SAQWNAQ6.js.map +1 -0
- package/dist/{chunk-QRZDP5RR.cjs → chunk-W7QI6BTA.cjs} +3 -3
- package/dist/{chunk-QRZDP5RR.cjs.map → chunk-W7QI6BTA.cjs.map} +1 -1
- package/dist/connect-modal/index.cjs +4 -2
- package/dist/connect-modal/index.cjs.map +1 -1
- package/dist/connect-modal/index.d.cts +1 -1
- package/dist/connect-modal/index.d.ts +1 -1
- package/dist/connect-modal/index.js +11 -9
- package/dist/index.cjs +24 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +31 -23
- package/dist/index.js.map +1 -1
- package/dist/{wagmi-BwAJkYMM.d.cts → wagmi-DgjkdmGk.d.cts} +77 -21
- package/dist/{wagmi-BwAJkYMM.d.ts → wagmi-DgjkdmGk.d.ts} +77 -21
- package/package.json +5 -5
- package/src/connect-modal/components/connection-view.ts +4 -1
- package/src/connect-modal/components/eoa-connection-view.ts +4 -0
- package/src/connect-modal/connect-modal.types.ts +4 -0
- package/src/connect-modal/index.ts +6 -4
- package/src/connect-modal/services/wagmi.ts +176 -65
- package/src/connect-modal/utils/chainParams.ts +32 -0
- package/src/connector.ts +18 -12
- package/src/index.ts +6 -4
- package/dist/chunk-4PC7ZTI7.js.map +0 -1
- package/dist/chunk-PB7QP3SJ.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
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 type { Config } from '@wagmi/core'\nimport type { ConnectModalSetup } from './connect-modal/index.js'\nimport { setupConnectModal } from './connect-modal/index.js'\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 = 'https://auth-simple.pages.dev'\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":";;;;;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ides zero-config setup for:\n * - Embedded Wallet (passkey-based)\n * - UP Extension (browser extension)\n * - UP Mobile (WalletConnect)\n */\n\nimport type { Config } from '@wagmi/core'\nimport type { ConnectModalSetup } from './connect-modal/index.js'\nimport { setupConnectModal } from './connect-modal/index.js'\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 = 'https://auth-simple.pages.dev'\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":";;;;;AAgBO,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAChC,IAAM,2BAA2B;AAKjC,IAAM,kBAAkB;AAK/B,SAAS,sBAA8B;AAErC,MAAI,OAAO,YAAY,eAAe,QAAQ,KAAK,YAA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B;AAAA,MACrB,KAAK,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,KAAK,YAAY;AACf,cAAM,SAAS,aAAa,QAAQ,OAAO,UAAU;AACrD,eAAO,SAAS,KAAK,MAAM,MAAM,IAAI,CAAC;AAAA,MACxC;AAAA,MACA,KAAK,OAAO,UAAmC;AAC7C,qBAAa,QAAQ,OAAO,YAAY,KAAK,UAAU,KAAK,CAAC;AAAA,MAC/D;AAAA,MACA,MAAM,OAAO;AAAA,IACf,CAAC;AAGD,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG,CAAC;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,KAAK,8CAAoC,KAAK;AACtD,UAAM;AAAA,EACR;AACF;AAKA,SAAS,oBAAoB;AAC3B,QAAM,WAAW,MAAM;AACrB,QAAI,OAAO,WAAW,eAAe,OAAO,cAAc;AACxD,aAAO,OAAO;AAAA,IAChB;AACA,WAAO;AAAA,MACL,SAAS,MAAM;AAAA,MACf,SAAS,MAAM;AAAA,MAAC;AAAA,MAChB,YAAY,MAAM;AAAA,MAAC;AAAA,IACrB;AAAA,EACF,GAAG;AAEH,SAAO;AAAA,IACL,QAAQ,KAAa;AACnB,aAAO,QAAQ,QAAQ,GAAG;AAAA,IAC5B;AAAA,IACA,WAAW,KAAa;AACtB,cAAQ,WAAW,GAAG;AAAA,IACxB;AAAA,IACA,QAAQ,KAAa,OAAe;AAClC,UAAI;AACF,gBAAQ,QAAQ,KAAK,KAAK;AAAA,MAC5B,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -20,14 +20,89 @@ var ConnectModalBase = class extends LitElement {
|
|
|
20
20
|
|
|
21
21
|
// src/connect-modal/connect-modal.ts
|
|
22
22
|
import { withDeviceService as withDeviceService3 } from "@lukso/core/mixins";
|
|
23
|
-
import
|
|
23
|
+
import debug4 from "debug";
|
|
24
24
|
import { html as html5 } from "lit";
|
|
25
25
|
import { property as property4, state as state2 } from "lit/decorators.js";
|
|
26
26
|
|
|
27
27
|
// src/connect-modal/services/wagmi.ts
|
|
28
|
+
import { getChainById } from "@lukso/core/chains";
|
|
28
29
|
import { slug } from "@lukso/core/utils";
|
|
30
|
+
import debug from "debug";
|
|
31
|
+
|
|
32
|
+
// src/connect-modal/utils/chainParams.ts
|
|
33
|
+
function constructAddEthereumChainParameter(chain) {
|
|
34
|
+
return {
|
|
35
|
+
chainName: chain.name,
|
|
36
|
+
nativeCurrency: {
|
|
37
|
+
name: chain.nativeCurrency.name,
|
|
38
|
+
symbol: chain.nativeCurrency.symbol,
|
|
39
|
+
decimals: chain.nativeCurrency.decimals
|
|
40
|
+
},
|
|
41
|
+
rpcUrls: [...chain.rpcUrls.default.http],
|
|
42
|
+
blockExplorerUrls: chain.blockExplorers?.default.url ? [chain.blockExplorers.default.url] : void 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/connect-modal/services/wagmi.ts
|
|
47
|
+
var logInfo = debug("connect-modal:info");
|
|
29
48
|
var UP_EXTENSION_ID = "cloud.universalprofile";
|
|
30
|
-
var
|
|
49
|
+
var WagmiService = class {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.setup = null;
|
|
52
|
+
this.wagmiCore = null;
|
|
53
|
+
}
|
|
54
|
+
configure(setup) {
|
|
55
|
+
this.setup = setup;
|
|
56
|
+
}
|
|
57
|
+
getSetup() {
|
|
58
|
+
return this.setup;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ensure wagmi/core is loaded and return initialized state
|
|
62
|
+
* Returns { core, config } if ready, null otherwise
|
|
63
|
+
*/
|
|
64
|
+
async init() {
|
|
65
|
+
if (!this.setup) return null;
|
|
66
|
+
if (!this.wagmiCore) {
|
|
67
|
+
try {
|
|
68
|
+
this.wagmiCore = await import("@wagmi/core");
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { core: this.wagmiCore, config: this.setup.wagmiConfig };
|
|
74
|
+
}
|
|
75
|
+
async getConnection() {
|
|
76
|
+
const wagmi = await this.init();
|
|
77
|
+
if (!wagmi) return null;
|
|
78
|
+
try {
|
|
79
|
+
return wagmi.core.getConnection(wagmi.config);
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async watchConnection(callback) {
|
|
85
|
+
const wagmi = await this.init();
|
|
86
|
+
if (!wagmi) return null;
|
|
87
|
+
try {
|
|
88
|
+
return wagmi.core.watchConnection(wagmi.config, { onChange: callback });
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async disconnect() {
|
|
94
|
+
const wagmi = await this.init();
|
|
95
|
+
if (!wagmi) return false;
|
|
96
|
+
try {
|
|
97
|
+
await wagmi.core.disconnect(wagmi.config);
|
|
98
|
+
return true;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn("Failed to disconnect from wagmi", error);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var wagmiService = new WagmiService();
|
|
31
106
|
function fromWagmiConnector(connector, connectFn, chainId) {
|
|
32
107
|
let type = "injected";
|
|
33
108
|
const rdns = connector.id;
|
|
@@ -48,7 +123,27 @@ function fromWagmiConnector(connector, connectFn, chainId) {
|
|
|
48
123
|
connect: async () => {
|
|
49
124
|
await connectFn({ connector, chainId });
|
|
50
125
|
},
|
|
51
|
-
getProvider: connector.getProvider ? () => connector.getProvider() : void 0
|
|
126
|
+
getProvider: connector.getProvider ? () => connector.getProvider() : void 0,
|
|
127
|
+
switchChain: connector.switchChain ? async (params) => {
|
|
128
|
+
if (!params.chainId) {
|
|
129
|
+
console.warn("No chainId provided for switchChain, skipping");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let addEthereumChainParameter = params.addEthereumChainParameter;
|
|
133
|
+
if (!addEthereumChainParameter) {
|
|
134
|
+
const chain = getChainById(params.chainId);
|
|
135
|
+
if (chain) {
|
|
136
|
+
addEthereumChainParameter = constructAddEthereumChainParameter(chain);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
await connector.switchChain({
|
|
140
|
+
chainId: params.chainId,
|
|
141
|
+
addEthereumChainParameter
|
|
142
|
+
});
|
|
143
|
+
logInfo(
|
|
144
|
+
`Switched to chainId ${params.chainId} via connector "${connector.name}"`
|
|
145
|
+
);
|
|
146
|
+
} : void 0
|
|
52
147
|
};
|
|
53
148
|
}
|
|
54
149
|
function fromWagmiConnectors(connectors, connectFn, chainId, embeddedWalletId) {
|
|
@@ -102,52 +197,20 @@ function fromWagmiConnectors(connectors, connectFn, chainId, embeddedWalletId) {
|
|
|
102
197
|
result.push(...others);
|
|
103
198
|
return result;
|
|
104
199
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
200
|
+
function setupWagmi(setup) {
|
|
201
|
+
wagmiService.configure(setup);
|
|
107
202
|
}
|
|
108
203
|
function getWagmiSetup() {
|
|
109
|
-
return
|
|
204
|
+
return wagmiService.getSetup();
|
|
110
205
|
}
|
|
111
|
-
async function
|
|
112
|
-
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
const { getAccount } = await import("@wagmi/core");
|
|
117
|
-
const account = getAccount(globalWagmiSetup.wagmiConfig);
|
|
118
|
-
return account;
|
|
119
|
-
} catch (_error) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
206
|
+
async function getConnection() {
|
|
207
|
+
return wagmiService.getConnection();
|
|
122
208
|
}
|
|
123
|
-
async function
|
|
124
|
-
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const { watchAccount } = await import("@wagmi/core");
|
|
129
|
-
const unsubscribe = watchAccount(globalWagmiSetup.wagmiConfig, {
|
|
130
|
-
onChange: (account) => {
|
|
131
|
-
callback(account);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return unsubscribe;
|
|
135
|
-
} catch (_error) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
209
|
+
async function watchConnection(callback) {
|
|
210
|
+
return wagmiService.watchConnection(callback);
|
|
138
211
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
const { disconnect } = await import("@wagmi/core");
|
|
145
|
-
await disconnect(globalWagmiSetup.wagmiConfig);
|
|
146
|
-
return true;
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.warn("Failed to disconnect from wagmi", error);
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
212
|
+
async function disconnect() {
|
|
213
|
+
return wagmiService.disconnect();
|
|
151
214
|
}
|
|
152
215
|
|
|
153
216
|
// src/connect-modal/connect-modal.ts
|
|
@@ -156,7 +219,7 @@ import "@lukso/web-components/dist/components/lukso-modal";
|
|
|
156
219
|
// src/connect-modal/components/eoa-connection-view.ts
|
|
157
220
|
import { Task } from "@lit/task";
|
|
158
221
|
import { withDeviceService, withIntlService } from "@lukso/core/mixins";
|
|
159
|
-
import
|
|
222
|
+
import debug2 from "debug";
|
|
160
223
|
import { html as html2, nothing } from "lit";
|
|
161
224
|
import { property, state } from "lit/decorators.js";
|
|
162
225
|
import { keyed } from "lit/directives/keyed.js";
|
|
@@ -200,7 +263,7 @@ var renderPlaceholder = (style2) => html`<div class="${cn("bg-neutral-90 dark:bg
|
|
|
200
263
|
import "@lukso/web-components/dist/components/lukso-button";
|
|
201
264
|
import "@lukso/web-components/dist/components/lukso-icon";
|
|
202
265
|
import "@lukso/web-components/dist/components/lukso-tag";
|
|
203
|
-
var
|
|
266
|
+
var logInfo2 = debug2("connect-modal:info");
|
|
204
267
|
var EoaConnectionView = class extends withIntlService(
|
|
205
268
|
withDeviceService(ConnectModalBase)
|
|
206
269
|
) {
|
|
@@ -329,8 +392,10 @@ var EoaConnectionView = class extends withIntlService(
|
|
|
329
392
|
const connector = wallet.connector;
|
|
330
393
|
if (connector) {
|
|
331
394
|
try {
|
|
332
|
-
|
|
395
|
+
logInfo2("Connecting via connector:", connector);
|
|
333
396
|
this.isConnecting = true;
|
|
397
|
+
const setup = getWagmiSetup();
|
|
398
|
+
await connector.switchChain?.({ chainId: setup?.chainId });
|
|
334
399
|
await connector.connect();
|
|
335
400
|
this.dispatchEvent(
|
|
336
401
|
new CustomEvent("on-connect", {
|
|
@@ -359,13 +424,13 @@ var EoaConnectionView = class extends withIntlService(
|
|
|
359
424
|
const connector = this.walletConnectConnector;
|
|
360
425
|
if (connector) {
|
|
361
426
|
try {
|
|
362
|
-
|
|
427
|
+
logInfo2("Connecting via WalletConnect connector:", connector);
|
|
363
428
|
this.isConnecting = true;
|
|
364
429
|
const connectPromise = connector.connect();
|
|
365
430
|
const provider = await connector.getProvider?.();
|
|
366
431
|
if (provider) {
|
|
367
432
|
const handleDisplayUri = (displayUri) => {
|
|
368
|
-
|
|
433
|
+
logInfo2("WalletConnect URI received:", displayUri);
|
|
369
434
|
const encodedUri = encodeURIComponent(displayUri);
|
|
370
435
|
if (wallet.mobile?.native) {
|
|
371
436
|
window.location.href = `${wallet.mobile.native}wc?uri=${encodedUri}`;
|
|
@@ -502,7 +567,7 @@ import "@lukso/web-components/dist/components/lukso-button";
|
|
|
502
567
|
import "@lukso/web-components/dist/components/lukso-icon";
|
|
503
568
|
import { browserInfo } from "@lukso/core/utils";
|
|
504
569
|
import { cn as cn2 } from "@lukso/web-components/tools";
|
|
505
|
-
import
|
|
570
|
+
import debug3 from "debug";
|
|
506
571
|
|
|
507
572
|
// src/connect-modal/utils/walletConnectDeepLinkUrl.ts
|
|
508
573
|
var walletConnectDeepLinkUrl = (data, options) => {
|
|
@@ -529,7 +594,7 @@ var walletConnectDeepLinkUrl = (data, options) => {
|
|
|
529
594
|
};
|
|
530
595
|
|
|
531
596
|
// src/connect-modal/components/connection-view.ts
|
|
532
|
-
var
|
|
597
|
+
var logInfo3 = debug3("connect-modal:info");
|
|
533
598
|
var ConnectionView = class extends withIntlService2(
|
|
534
599
|
withDeviceService2(ConnectModalBase)
|
|
535
600
|
) {
|
|
@@ -544,7 +609,7 @@ var ConnectionView = class extends withIntlService2(
|
|
|
544
609
|
this.handleConnectEmbedded = async () => {
|
|
545
610
|
const connector = this.embeddedWalletConnector;
|
|
546
611
|
try {
|
|
547
|
-
|
|
612
|
+
logInfo3("Connecting via connector:", connector);
|
|
548
613
|
await connector?.connect();
|
|
549
614
|
this.dispatchEvent(
|
|
550
615
|
new CustomEvent("on-connect", {
|
|
@@ -574,9 +639,11 @@ var ConnectionView = class extends withIntlService2(
|
|
|
574
639
|
}
|
|
575
640
|
if (connector) {
|
|
576
641
|
try {
|
|
577
|
-
|
|
642
|
+
logInfo3("Connecting via connector:", connector);
|
|
578
643
|
this.isConnecting = true;
|
|
579
644
|
this.connectingRdns = connector.rdns;
|
|
645
|
+
const setup = getWagmiSetup();
|
|
646
|
+
await connector.switchChain?.({ chainId: setup?.chainId });
|
|
580
647
|
await connector.connect();
|
|
581
648
|
this.dispatchEvent(
|
|
582
649
|
new CustomEvent("on-connect", {
|
|
@@ -606,16 +673,16 @@ var ConnectionView = class extends withIntlService2(
|
|
|
606
673
|
const connector = this.walletConnectConnector;
|
|
607
674
|
if (connector) {
|
|
608
675
|
try {
|
|
609
|
-
|
|
676
|
+
logInfo3("Connecting via connector:", connector);
|
|
610
677
|
this.isConnecting = true;
|
|
611
678
|
this.connectingRdns = connector.rdns;
|
|
612
679
|
const connectPromise = connector.connect();
|
|
613
680
|
const provider = await connector.getProvider?.();
|
|
614
681
|
if (provider) {
|
|
615
682
|
const handleDisplayUri = (displayUri) => {
|
|
616
|
-
|
|
683
|
+
logInfo3("WalletConnect original URI:", displayUri);
|
|
617
684
|
const deepLink = walletConnectDeepLinkUrl(displayUri);
|
|
618
|
-
|
|
685
|
+
logInfo3("Mobile App Deep Link:", deepLink);
|
|
619
686
|
if (this.device.isMobile) {
|
|
620
687
|
window.open(deepLink, "_blank");
|
|
621
688
|
} else {
|
|
@@ -898,7 +965,7 @@ __decorateClass([
|
|
|
898
965
|
customElements.define("qr-code-view", QrCodeView);
|
|
899
966
|
|
|
900
967
|
// src/connect-modal/connect-modal.ts
|
|
901
|
-
var
|
|
968
|
+
var logInfo4 = debug4("connect-modal:info");
|
|
902
969
|
var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
903
970
|
constructor() {
|
|
904
971
|
super(...arguments);
|
|
@@ -976,9 +1043,9 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
|
976
1043
|
}
|
|
977
1044
|
}
|
|
978
1045
|
async loadConnectors() {
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
if (!
|
|
1046
|
+
const globalWagmiSetup = getWagmiSetup();
|
|
1047
|
+
logInfo4("Global wagmi setup:", globalWagmiSetup);
|
|
1048
|
+
if (!globalWagmiSetup) {
|
|
982
1049
|
console.warn(
|
|
983
1050
|
"No global wagmi setup found! Call setupConnectModal() first."
|
|
984
1051
|
);
|
|
@@ -986,9 +1053,9 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
|
986
1053
|
return;
|
|
987
1054
|
}
|
|
988
1055
|
try {
|
|
989
|
-
const { wagmiConfig, chainId, embeddedWalletId } =
|
|
1056
|
+
const { wagmiConfig, chainId, embeddedWalletId } = globalWagmiSetup;
|
|
990
1057
|
const wagmiConnectors = wagmiConfig?.connectors || [];
|
|
991
|
-
|
|
1058
|
+
logInfo4("Initial connectors:", wagmiConnectors);
|
|
992
1059
|
const wagmiCore = await import("@wagmi/core").catch((error) => {
|
|
993
1060
|
throw new Error("@wagmi/core is required when using wagmi connectors", {
|
|
994
1061
|
cause: error
|
|
@@ -1005,7 +1072,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
|
1005
1072
|
chainId,
|
|
1006
1073
|
embeddedWalletId
|
|
1007
1074
|
);
|
|
1008
|
-
|
|
1075
|
+
logInfo4("Converted connectors:", this.connectors);
|
|
1009
1076
|
} catch (error) {
|
|
1010
1077
|
console.warn("Failed to load connectors", error);
|
|
1011
1078
|
this.connectors = [];
|
|
@@ -1019,7 +1086,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
|
1019
1086
|
handleOnConnectSuccess(event) {
|
|
1020
1087
|
event.stopPropagation();
|
|
1021
1088
|
const connector = event.detail.connector;
|
|
1022
|
-
|
|
1089
|
+
logInfo4("Connection success:", connector);
|
|
1023
1090
|
this.open = false;
|
|
1024
1091
|
this.dispatchEvent(
|
|
1025
1092
|
new CustomEvent("on-connect", {
|
|
@@ -1037,7 +1104,7 @@ var ConnectModal = class extends withDeviceService3(ConnectModalBase) {
|
|
|
1037
1104
|
handleOnConnectError(event) {
|
|
1038
1105
|
event.stopPropagation();
|
|
1039
1106
|
const error = event.detail.error;
|
|
1040
|
-
|
|
1107
|
+
logInfo4("Connection error:", error);
|
|
1041
1108
|
this.dispatchEvent(
|
|
1042
1109
|
new CustomEvent("on-error", {
|
|
1043
1110
|
detail: { error },
|
|
@@ -1120,13 +1187,14 @@ customElements.define("connect-modal", ConnectModal);
|
|
|
1120
1187
|
|
|
1121
1188
|
export {
|
|
1122
1189
|
ConnectModalBase,
|
|
1190
|
+
wagmiService,
|
|
1123
1191
|
fromWagmiConnector,
|
|
1124
1192
|
fromWagmiConnectors,
|
|
1125
|
-
|
|
1193
|
+
setupWagmi,
|
|
1126
1194
|
getWagmiSetup,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1195
|
+
getConnection,
|
|
1196
|
+
watchConnection,
|
|
1197
|
+
disconnect,
|
|
1130
1198
|
ConnectModal
|
|
1131
1199
|
};
|
|
1132
|
-
//# sourceMappingURL=chunk-
|
|
1200
|
+
//# sourceMappingURL=chunk-SAQWNAQ6.js.map
|