@ic-pay/icpay-widget 1.1.55 → 1.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/styles.ts","../src/utils/sdk.ts","../src/components/progress-bar.ts","../src/components/transak-onramp-modal.ts","../src/components/premium-content.ts","../src/error-handling.ts","../src/components/token-selector.ts","../src/components/wallet-selector-modal.ts","../src/utils/pnp.ts","../src/components/tip-jar.ts","../src/components/article-paywall.ts","../src/components/coffee-shop.ts","../src/components/donation-thermometer.ts","../src/components/pay-button.ts","../src/components/amount-input.ts"],"sourcesContent":["import { css } from 'lit';\nimport type { ThemeConfig } from './types';\n\nexport const baseStyles = css`\n :host {\n --icpay-primary: #f9fafb;\n --icpay-secondary: #e5e7eb;\n --icpay-accent: #9ca3af;\n --icpay-text: #f9fafb;\n --icpay-muted: #9ca3af;\n --icpay-surface: #1f2937;\n --icpay-surface-alt: #374151;\n --icpay-border: #4b5563;\n --icpay-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: block;\n font-family: var(--icpay-font);\n }\n\n .icpay-card {\n background: var(--icpay-surface);\n border: 1px solid var(--icpay-border);\n border-radius: 16px;\n box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35);\n }\n\n .icpay-section {\n padding: 20px;\n }\n\n .pay-button {\n width: 100%;\n background: linear-gradient(135deg, var(--icpay-primary) 0%, var(--icpay-secondary) 100%);\n color: #111827;\n border: 1px solid #d1d5db;\n border-radius: 16px;\n padding: 16px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.3s ease;\n box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);\n }\n\n .pay-button:hover {\n transform: translateY(-2px);\n box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);\n background: linear-gradient(135deg, #ffffff 0%, #f3f4f6 100%);\n }\n\n .pay-button.processing {\n background: #6b7280;\n color: #f9fafb;\n border-color: #6b7280;\n cursor: not-allowed;\n animation: pulse 2s infinite;\n }\n\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.7; }\n }\n`;\n\n\nexport function applyThemeVars(host: HTMLElement, theme?: ThemeConfig | null): void {\n if (!host || !theme) return;\n const primary = theme.primaryColor || undefined;\n const secondary = theme.secondaryColor || undefined;\n const set = (k: string, v?: string) => { if (v) host.style.setProperty(k, v); };\n set('--icpay-primary', primary);\n set('--icpay-secondary', secondary);\n\n const parseHex = (hex?: string) => {\n if (!hex) return null;\n const h = hex.replace('#', '');\n const full = h.length === 3 ? h.split('').map(c=>c+c).join('') : h;\n const bigint = parseInt(full, 16);\n const r = (bigint >> 16) & 255;\n const g = (bigint >> 8) & 255;\n const b = bigint & 255;\n return { r, g, b };\n };\n const luminance = (hex?: string) => {\n const rgb = parseHex(hex);\n if (!rgb) return 0;\n const toLin = (c: number) => {\n const s = c / 255;\n return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);\n };\n return 0.2126 * toLin(rgb.r) + 0.7152 * toLin(rgb.g) + 0.0722 * toLin(rgb.b);\n };\n\n const basis = primary || secondary;\n const isLight = luminance(basis) > 0.6;\n const surface = theme.surfaceColor || (isLight ? '#f3f4f6' : '#1f2937');\n const surfaceAlt = theme.surfaceAltColor || (isLight ? '#e5e7eb' : '#374151');\n const border = theme.borderColor || (isLight ? '#d1d5db' : '#4b5563');\n const text = theme.textColor || (isLight ? '#111827' : '#f9fafb');\n const accent = theme.accentColor || secondary || primary || (isLight ? '#6b7280' : '#9ca3af');\n const muted = theme.mutedTextColor || (isLight ? '#6b7280' : '#9ca3af');\n\n set('--icpay-accent', accent);\n set('--icpay-text', text);\n set('--icpay-muted', muted);\n set('--icpay-surface', surface);\n set('--icpay-surface-alt', surfaceAlt);\n set('--icpay-border', border);\n}\n\n\n","import { Icpay, PriceCalculationResult, IcpayConfig } from '@ic-pay/icpay-sdk';\nimport type { CommonConfig } from '../types';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Debug logger utility for widget\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\nexport type WidgetSdk = {\n client: InstanceType<typeof Icpay>;\n quoteUsd(usdAmount: number, ledgerCanisterId: string): Promise<PriceCalculationResult>;\n sendUsd(usdAmount: number, ledgerCanisterId: string, metadata?: Record<string, any>): Promise<any>;\n startOnrampUsd(usdAmount: number, ledgerCanisterId: string, metadata?: Record<string, any>): Promise<any>;\n notifyIntentUntilComplete(paymentIntentId: string, intervalMs?: number, orderId?: string): { stop: () => void };\n};\n\nexport function createSdk(config: CommonConfig): WidgetSdk {\n if (!isBrowser) {\n // Return a mock SDK for SSR\n return {\n client: {} as any,\n quoteUsd: async () => ({ tokenAmountDecimals: '0' } as any),\n sendUsd: async () => ({ transactionId: '0', status: 'pending' } as any),\n startOnrampUsd: async () => ({ transactionId: '0', status: 'pending', metadata: { onramp: { sessionId: null } } } as any),\n notifyIntentUntilComplete: () => ({ stop: () => {} })\n };\n }\n\n debugLog(config.debug || false, 'Creating SDK with config:', config);\n\n // Filter out undefined values to avoid constructor errors\n const sdkConfig: IcpayConfig = {\n publishableKey: config.publishableKey,\n };\n // Default to enabling SDK events for the widget unless explicitly set in config\n if ((config as any).enableEvents !== undefined) {\n (sdkConfig as any).enableEvents = (config as any).enableEvents;\n } else {\n (sdkConfig as any).enableEvents = true;\n }\n\n if (config.apiUrl) sdkConfig.apiUrl = config.apiUrl;\n if (config.icHost) sdkConfig.icHost = config.icHost;\n if (config.actorProvider) sdkConfig.actorProvider = config.actorProvider;\n if (config.connectedWallet) sdkConfig.connectedWallet = config.connectedWallet;\n // Propagate kill switch to SDK (defaults to true inside SDK)\n if (config.onrampDisabled !== undefined) (sdkConfig as any).onrampDisabled = config.onrampDisabled;\n\n // Pass debug configuration to SDK if specified\n if (config.debug !== undefined) {\n sdkConfig.debug = config.debug;\n }\n\n debugLog(config.debug || false, 'Filtered SDK config:', sdkConfig);\n try {\n debugLog(config.debug || false, 'typeof Icpay:', typeof Icpay);\n const client = new Icpay(sdkConfig);\n\n // Re-emit SDK instance events on window so UI components can listen globally\n if (isBrowser) {\n const clientAny = client as any;\n const forward = (type: string) => {\n clientAny.addEventListener(type, (e: any) => {\n window.dispatchEvent(new CustomEvent(type, { detail: e?.detail ?? e }));\n });\n };\n [\n 'icpay-sdk-error',\n 'icpay-sdk-transaction-created',\n 'icpay-sdk-transaction-updated',\n 'icpay-sdk-transaction-completed',\n 'icpay-sdk-transaction-failed',\n 'icpay-sdk-method-start',\n 'icpay-sdk-method-success',\n 'icpay-sdk-method-error'\n ].forEach(forward);\n }\n\n async function quoteUsd(usdAmount: number, ledgerCanisterId: string) {\n return client.calculateTokenAmountFromUSD({ usdAmount, ledgerCanisterId });\n }\n\n async function sendUsd(usdAmount: number, ledgerCanisterId: string, metadata?: Record<string, any>) {\n // Merge global config.metadata with call-specific metadata\n const mergedMeta = { ...(config as any).metadata, ...(metadata || {}) } as Record<string, any>;\n return (client as any).createPaymentUsd({ usdAmount, ledgerCanisterId, metadata: mergedMeta });\n }\n\n async function startOnrampUsd(usdAmount: number, ledgerCanisterId: string, metadata?: Record<string, any>) {\n // Trigger onramp flow through SDK; SDK returns onramp data in metadata.onramp\n const mergedMeta = { ...(config as any).metadata, ...(metadata || {}) } as Record<string, any>;\n return (client as any).createPaymentUsd({ usdAmount, ledgerCanisterId, metadata: mergedMeta, onrampPayment: true });\n }\n\n\n function notifyIntentUntilComplete(paymentIntentId: string, intervalMs?: number, orderId?: string) {\n return (client as any).notifyPaymentIntentOnRamp({ paymentIntentId, intervalMs, orderId });\n }\n\n return { client, quoteUsd, sendUsd, startOnrampUsd, notifyIntentUntilComplete };\n } catch (error) {\n debugLog(config.debug || false, 'Error creating SDK:', error);\n throw error;\n }\n}\n\n\n","import { LitElement, html, css } from 'lit';\nimport { applyThemeVars } from '../styles';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n// Debug logger utility (mirrors other widgets)\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(message, data);\n } else {\n console.log(message);\n }\n }\n}\n\ntype StepStatus = 'pending' | 'loading' | 'completed' | 'error';\n\ntype Step = {\n key: string;\n label: string;\n tooltip: string;\n status: StepStatus;\n timestamp?: string;\n errorMessage?: string;\n};\n\nconst DEFAULT_STEPS: Step[] = [\n {\n key: 'wallet',\n label: 'Connect Wallet',\n tooltip: 'Awaiting wallet connection',\n status: 'pending'\n },\n {\n key: 'init',\n label: 'Initialising ICPay',\n tooltip: 'Initializing payment',\n status: 'pending'\n },\n {\n key: 'await',\n label: 'Awaiting payment confirmation',\n tooltip: 'Preparing payment',\n status: 'pending'\n },\n {\n key: 'transfer',\n label: 'Transferring funds',\n tooltip: 'Submitting payment',\n status: 'pending'\n },\n {\n key: 'verify',\n label: 'Verifying payment',\n tooltip: 'Confirming payment',\n status: 'pending'\n },\n {\n key: 'confirm',\n label: 'Payment confirmed',\n tooltip: 'Payment completed',\n status: 'pending'\n }\n];\n\n\n@customElement('icpay-progress-bar')\nexport class ICPayProgressBar extends LitElement {\n static styles = css`\n :host {\n display: block;\n font-family: var(--icpay-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);\n color: var(--icpay-text-primary, #ffffff);\n\n /* Theme variables for better composability */\n --icpay-bg-primary: #1f2937;\n --icpay-bg-secondary: rgba(255, 255, 255, 0.05);\n --icpay-bg-secondary-hover: rgba(255, 255, 255, 0.08);\n --icpay-bg-success: rgba(16, 185, 129, 0.1);\n --icpay-bg-error: rgba(239, 68, 68, 0.1);\n\n --icpay-text-primary: #ffffff;\n --icpay-text-secondary: #9ca3af;\n --icpay-text-muted: #6b7280;\n\n --icpay-border-primary: rgba(255, 255, 255, 0.1);\n --icpay-border-secondary: rgba(255, 255, 255, 0.2);\n --icpay-border-success: rgba(16, 185, 129, 0.3);\n --icpay-border-error: rgba(239, 68, 68, 0.3);\n\n --icpay-accent-primary: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);\n --icpay-accent-success: linear-gradient(135deg, #10b981 0%, #059669 100%);\n --icpay-accent-error: #ef4444;\n\n --icpay-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);\n --icpay-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);\n --icpay-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);\n --icpay-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);\n\n --icpay-radius-sm: 6px;\n --icpay-radius-md: 8px;\n --icpay-radius-lg: 12px;\n --icpay-radius-xl: 16px;\n\n --icpay-spacing-xs: 4px;\n --icpay-spacing-sm: 8px;\n --icpay-spacing-md: 12px;\n --icpay-spacing-lg: 16px;\n --icpay-spacing-xl: 24px;\n }\n\n .modal-overlay {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(0, 0, 0, 0.5);\n backdrop-filter: blur(8px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1000;\n opacity: 0;\n visibility: hidden;\n transition: opacity 0.3s ease, visibility 0.3s ease;\n }\n\n .modal-content {\n transition: opacity 0.4s ease, transform 0.4s ease;\n opacity: 1;\n transform: translateY(0);\n }\n\n .modal-content.transitioning {\n opacity: 0;\n transform: translateY(20px);\n }\n\n .wallet-selector-container {\n width: 100%;\n }\n\n .wallet-selector-title {\n color: var(--icpay-text-primary);\n margin: 0 48px var(--icpay-spacing-lg) 0;\n font-size: 18px;\n font-weight: 600;\n }\n\n .wallet-options {\n display: flex;\n flex-direction: column;\n gap: var(--icpay-spacing-sm);\n }\n\n .wallet-option {\n width: 100%;\n padding: 12px 16px;\n background: rgba(255, 255, 255, 0.05);\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 8px;\n display: flex;\n align-items: center;\n gap: 12px;\n cursor: pointer;\n transition: all 0.3s ease;\n box-sizing: border-box;\n }\n\n .wallet-option:hover {\n background: rgba(255, 255, 255, 0.08);\n border-color: rgba(255, 255, 255, 0.2);\n }\n\n .wallet-icon {\n width: 48px;\n height: 48px;\n border-radius: 12px;\n background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n\n .wallet-icon img {\n width: 40px;\n height: 40px;\n object-fit: cover;\n border-radius: 12px;\n }\n\n .wallet-icon-placeholder {\n color: #ffffff;\n font-size: 12px;\n font-weight: bold;\n }\n\n .wallet-label {\n font-weight: 500;\n font-size: 14px;\n color: #ffffff;\n }\n\n .modal-overlay.active {\n opacity: 1;\n visibility: visible;\n }\n\n .modal-container {\n background: var(--icpay-bg-primary);\n border: 1px solid var(--icpay-border-primary);\n border-radius: var(--icpay-radius-lg);\n padding: var(--icpay-spacing-xl);\n max-width: 400px;\n width: 90%;\n box-shadow: var(--icpay-shadow-xl);\n transform: translateY(20px);\n transition: transform 0.3s ease;\n position: relative;\n }\n\n .modal-overlay.active .modal-container {\n transform: translateY(0);\n }\n\n .close-button {\n position: absolute;\n top: var(--icpay-spacing-lg);\n right: var(--icpay-spacing-lg);\n width: 32px;\n height: 32px;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--icpay-text-secondary);\n cursor: pointer;\n border: none;\n background: transparent;\n font-size: 20px;\n transition: all 0.2s;\n z-index: 10;\n }\n\n .close-button:hover {\n color: var(--icpay-text-primary);\n }\n\n .progress-header { text-align: left; margin-bottom: var(--icpay-spacing-lg); }\n .progress-title {\n font-size: 18px;\n font-weight: 600;\n margin: 0 48px var(--icpay-spacing-sm) 0;\n color: var(--icpay-text-primary);\n }\n .progress-subtitle { color: var(--icpay-text-secondary); font-size: 14px; }\n .progress-steps {\n margin-bottom: var(--icpay-spacing-xl);\n display: flex;\n flex-direction: column;\n gap: var(--icpay-spacing-sm);\n }\n .step {\n width: 100%;\n padding: 12px 16px;\n background: rgba(255, 255, 255, 0.05);\n border: 1px solid rgba(255, 255, 255, 0.1);\n border-radius: 8px;\n display: flex;\n align-items: center;\n gap: 12px;\n opacity: 0.3;\n transition: all 0.3s ease;\n cursor: default;\n box-sizing: border-box;\n }\n .step.active {\n opacity: 1;\n background: rgba(255, 255, 255, 0.05);\n border-color: rgba(255, 255, 255, 0.1);\n }\n .step.completed {\n opacity: 0.7;\n background: rgba(16, 185, 129, 0.1);\n border-color: rgba(16, 185, 129, 0.3);\n }\n\n .step.error {\n opacity: 1;\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n }\n .step-icon {\n width: 48px;\n height: 48px;\n border-radius: 12px;\n background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s ease;\n position: relative;\n flex-shrink: 0;\n }\n .step.active .step-icon {\n background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);\n box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);\n }\n .step.completed .step-icon {\n background: linear-gradient(135deg, #10b981 0%, #059669 100%);\n }\n\n .step.error .step-icon {\n background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);\n }\n .step-icon svg {\n width: 20px;\n height: 20px;\n stroke: var(--icpay-text-primary);\n transition: stroke 0.3s ease;\n }\n .step-content {\n flex: 1;\n display: flex;\n flex-direction: column;\n gap: 0;\n }\n .step-title {\n font-weight: 500;\n font-size: 14px;\n color: #ffffff;\n transition: color 0.3s ease;\n margin: 0;\n }\n .step-description {\n font-size: 12px;\n color: #9ca3af;\n margin: 0;\n }\n\n .step-error-message {\n font-size: 11px;\n color: #fca5a5;\n margin-top: 4px;\n padding: 4px 8px;\n background: rgba(239, 68, 68, 0.1);\n border-radius: 4px;\n border-left: 3px solid #ef4444;\n }\n .loading-spinner {\n display: none;\n width: 20px;\n height: 20px;\n border: 2px solid rgba(255, 255, 255, 0.2);\n border-top-color: var(--icpay-text-primary);\n border-radius: 50%;\n animation: spin 1s linear infinite;\n position: absolute;\n }\n .step.active .loading-spinner { display: block; }\n\n .error-container {\n text-align: center;\n }\n\n .error-icon-large {\n width: 64px;\n height: 64px;\n margin: 0 auto var(--icpay-spacing-lg);\n background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);\n border-radius: var(--icpay-radius-xl);\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n .error-icon-large svg {\n width: 32px;\n height: 32px;\n stroke: var(--icpay-text-primary);\n stroke-width: 2;\n }\n\n .error-title {\n font-size: 20px;\n font-weight: 600;\n margin-bottom: var(--icpay-spacing-sm);\n color: var(--icpay-text-primary);\n }\n\n .error-message-text {\n color: var(--icpay-text-secondary);\n margin-bottom: var(--icpay-spacing-xl);\n font-size: 14px;\n }\n\n .error-details {\n background: rgba(239, 68, 68, 0.1);\n border: 1px solid rgba(239, 68, 68, 0.3);\n border-radius: var(--icpay-radius-md);\n padding: var(--icpay-spacing-lg);\n margin-bottom: var(--icpay-spacing-xl);\n text-align: left;\n }\n\n .error-detail-item {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: var(--icpay-spacing-sm);\n }\n\n .error-detail-item:last-child {\n margin-bottom: 0;\n }\n\n .error-detail-label {\n font-size: 14px;\n color: var(--icpay-text-secondary);\n font-weight: 500;\n }\n\n .error-detail-value {\n font-size: 14px;\n color: var(--icpay-text-primary);\n font-weight: 600;\n }\n\n .error-actions {\n display: flex;\n gap: var(--icpay-spacing-sm);\n justify-content: center;\n }\n\n .insufficient-funds-container {\n width: 100%;\n }\n\n .payment-summary {\n background: rgba(255, 255, 255, 0.1);\n border-radius: var(--icpay-radius-md);\n padding: var(--icpay-spacing-lg);\n margin-bottom: var(--icpay-spacing-lg);\n text-align: center;\n }\n\n .payment-amount {\n font-size: 16px;\n font-weight: 600;\n color: var(--icpay-text-primary);\n }\n\n .error-notification {\n background: rgba(255, 255, 255, 0.05);\n border: 1px solid #f59e0b;\n border-radius: var(--icpay-radius-md);\n padding: var(--icpay-spacing-lg);\n margin-bottom: var(--icpay-spacing-xl);\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--icpay-spacing-lg);\n }\n\n .error-content {\n display: flex;\n align-items: center;\n gap: var(--icpay-spacing-md);\n flex: 1;\n }\n\n .error-icon-small {\n width: 20px;\n height: 20px;\n color: #f59e0b;\n flex-shrink: 0;\n }\n\n .error-icon-small svg {\n width: 100%;\n height: 100%;\n }\n\n .error-text {\n font-size: 14px;\n font-weight: 500;\n color: #f59e0b;\n }\n\n .add-funds-btn {\n background: rgba(255, 255, 255, 0.1);\n border: 1px solid rgba(255, 255, 255, 0.2);\n border-radius: var(--icpay-radius-sm);\n padding: 8px 16px;\n color: var(--icpay-text-primary);\n font-size: 14px;\n font-weight: 500;\n cursor: pointer;\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n\n .add-funds-btn:hover {\n background: rgba(255, 255, 255, 0.15);\n border-color: rgba(255, 255, 255, 0.3);\n }\n\n .error-message {\n display: flex;\n align-items: flex-start;\n gap: var(--icpay-spacing-md);\n padding: var(--icpay-spacing-lg);\n background: var(--icpay-bg-error);\n border: 1px solid var(--icpay-border-error);\n border-radius: var(--icpay-radius-md);\n margin-top: var(--icpay-spacing-sm);\n }\n\n .error-icon {\n flex-shrink: 0;\n width: 20px;\n height: 20px;\n background: var(--icpay-accent-error);\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--icpay-text-primary);\n font-size: 12px;\n font-weight: bold;\n }\n\n .error-content h4 {\n margin: 0 0 4px 0;\n font-size: 14px;\n font-weight: 600;\n color: var(--icpay-text-primary);\n }\n\n .error-content p {\n margin: 0;\n font-size: 12px;\n color: #fca5a5;\n line-height: 1.4;\n }\n\n .success-container { text-align: center; }\n .success-icon {\n width: 64px;\n height: 64px;\n margin: 0 auto var(--icpay-spacing-lg);\n background: var(--icpay-accent-success);\n border-radius: var(--icpay-radius-xl);\n display: flex;\n align-items: center;\n justify-content: center;\n }\n .success-icon svg {\n width: 32px;\n height: 32px;\n stroke: var(--icpay-text-primary);\n stroke-width: 2;\n }\n .success-title {\n font-size: 20px;\n font-weight: 600;\n margin-bottom: var(--icpay-spacing-sm);\n color: var(--icpay-text-primary);\n }\n .success-message {\n color: var(--icpay-text-secondary);\n margin-bottom: 20px;\n font-size: 14px;\n }\n .success-actions {\n display: flex;\n gap: var(--icpay-spacing-sm);\n justify-content: center;\n }\n .btn {\n padding: 10px 20px;\n border-radius: var(--icpay-radius-md);\n font-size: 14px;\n font-weight: 500;\n cursor: pointer;\n transition: all 0.3s ease;\n text-decoration: none;\n display: inline-flex;\n align-items: center;\n gap: var(--icpay-spacing-sm);\n }\n .btn-primary {\n background: var(--icpay-accent-primary);\n color: var(--icpay-text-primary);\n border: none;\n }\n .btn-primary:hover {\n transform: translateY(-1px);\n box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);\n }\n .btn-secondary {\n background: transparent;\n color: var(--icpay-text-secondary);\n border: 1px solid var(--icpay-border-primary);\n }\n .btn-secondary:hover {\n background: var(--icpay-bg-secondary);\n border-color: var(--icpay-border-secondary);\n color: var(--icpay-text-primary);\n }\n\n .confetti {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1001;\n }\n\n .confetti-piece {\n position: absolute;\n width: 8px;\n height: 8px;\n background: #0066FF;\n animation: confetti-fall 3s linear forwards;\n }\n\n @keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n\n .spinner {\n width: 16px;\n height: 16px;\n border: 2px solid transparent;\n border-top: 2px solid #ffffff;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n @keyframes confetti-fall {\n 0% {\n transform: translateY(-100vh) rotate(0deg);\n opacity: 1;\n }\n 100% {\n transform: translateY(100vh) rotate(720deg);\n opacity: 0;\n }\n }\n `;\n\n @property({ type: Boolean }) open = false;\n @property({ type: Array }) steps: Step[] = DEFAULT_STEPS;\n @property({ type: Number }) amount = 0;\n @property({ type: String }) currency = '';\n @property({ type: String }) ledgerSymbol = '';\n @property({ type: Boolean }) debug = false;\n @state() private activeIndex = 0;\n @state() private completed = false;\n @state() private failed = false;\n @state() private errorMessage: string | null = null;\n @state() private showSuccess = false;\n @state() private showConfetti = false;\n @state() private currentSteps: Step[] = [];\n @state() private currentAmount = 0;\n @state() private currentCurrency = '';\n @state() private currentLedgerSymbol = '';\n @state() private confirmLoadingStartedAt: number | null = null;\n private progressionTimer: number | null = null;\n @state() private currentWalletType: string | null = null;\n @state() private showWalletSelector = false;\n @state() private isTransitioning = false;\n\n @property({ type: Object }) theme?: { primaryColor?: string; secondaryColor?: string };\n\n connectedCallback(): void {\n super.connectedCallback();\n try { applyThemeVars(this, this.theme as any); } catch {}\n this.currentSteps = [...this.steps];\n\n // Initialize dynamic values from properties\n this.currentAmount = this.amount;\n this.currentCurrency = this.currency;\n this.currentLedgerSymbol = this.ledgerSymbol;\n\n // Attach global listeners for ICPay SDK events\n this.attachSDKEventListeners();\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.detachSDKEventListeners();\n this.stopAutomaticProgression();\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('theme')) {\n try { applyThemeVars(this, this.theme as any); } catch {}\n }\n }\n\n private attachSDKEventListeners() {\n // Core payment flow events\n window.addEventListener('icpay-sdk-method-start', this.onMethodStart as EventListener);\n window.addEventListener('icpay-sdk-method-success', this.onMethodSuccess as EventListener);\n window.addEventListener('icpay-sdk-method-error', this.onMethodError as EventListener);\n\n // Transaction lifecycle events\n window.addEventListener('icpay-sdk-transaction-created', this.onTransactionCreated as EventListener);\n window.addEventListener('icpay-sdk-transaction-updated', this.onTransactionUpdated as EventListener);\n window.addEventListener('icpay-sdk-transaction-completed', this.onTransactionCompleted as EventListener);\n window.addEventListener('icpay-sdk-transaction-failed', this.onTransactionFailed as EventListener);\n window.addEventListener('icpay-sdk-transaction-mismatched', this.onTransactionMismatched as EventListener);\n\n // Additional SDK events\n window.addEventListener('icpay-sdk-error', this.onSDKError as EventListener);\n window.addEventListener('icpay-sdk-wallet-connected', this.onWalletConnected as EventListener);\n window.addEventListener('icpay-sdk-wallet-disconnected', this.onWalletDisconnected as EventListener);\n window.addEventListener('icpay-sdk-balance-check', this.onBalanceCheck as EventListener);\n window.addEventListener('icpay-sdk-ledger-verified', this.onLedgerVerified as EventListener);\n\n // Custom widget events for better integration\n window.addEventListener('icpay-pay', this.onWidgetPayment as EventListener);\n window.addEventListener('icpay-error', this.onWidgetError as EventListener);\n window.addEventListener('icpay-unlock', this.onWidgetUnlock as EventListener);\n window.addEventListener('icpay-tip', this.onWidgetTip as EventListener);\n window.addEventListener('icpay-donation', this.onWidgetDonation as EventListener);\n window.addEventListener('icpay-coffee', this.onWidgetCoffee as EventListener);\n }\n\n private detachSDKEventListeners() {\n // Core payment flow events\n window.removeEventListener('icpay-sdk-method-start', this.onMethodStart as EventListener);\n window.removeEventListener('icpay-sdk-method-success', this.onMethodSuccess as EventListener);\n window.removeEventListener('icpay-sdk-method-error', this.onMethodError as EventListener);\n\n // Transaction lifecycle events\n window.removeEventListener('icpay-sdk-transaction-created', this.onTransactionCreated as EventListener);\n window.removeEventListener('icpay-sdk-transaction-updated', this.onTransactionUpdated as EventListener);\n window.removeEventListener('icpay-sdk-transaction-completed', this.onTransactionCompleted as EventListener);\n window.removeEventListener('icpay-sdk-transaction-failed', this.onTransactionFailed as EventListener);\n window.removeEventListener('icpay-sdk-transaction-mismatched', this.onTransactionMismatched as EventListener);\n\n // Additional SDK events\n window.removeEventListener('icpay-sdk-error', this.onSDKError as EventListener);\n window.removeEventListener('icpay-sdk-wallet-connected', this.onWalletConnected as EventListener);\n window.removeEventListener('icpay-sdk-wallet-disconnected', this.onWalletDisconnected as EventListener);\n window.removeEventListener('icpay-sdk-balance-check', this.onBalanceCheck as EventListener);\n window.removeEventListener('icpay-sdk-ledger-verified', this.onLedgerVerified as EventListener);\n\n // Custom widget events\n window.removeEventListener('icpay-pay', this.onWidgetPayment as EventListener);\n window.removeEventListener('icpay-error', this.onWidgetError as EventListener);\n window.removeEventListener('icpay-unlock', this.onWidgetUnlock as EventListener);\n window.removeEventListener('icpay-tip', this.onWidgetTip as EventListener);\n window.removeEventListener('icpay-donation', this.onWidgetDonation as EventListener);\n window.removeEventListener('icpay-coffee', this.onWidgetCoffee as EventListener);\n }\n\n private onMethodStart = (e: any) => {\n const methodName = e?.detail?.name || '';\n const methodType = e?.detail?.type || '';\n\n debugLog(this.debug, 'ICPay Progress: Method start event received:', e.detail);\n\n // Handle different payment methods (top-level starts)\n if (methodName === 'createPayment' || methodName === 'createPaymentUsd' ||\n methodName === 'sendUsd' || methodName === 'pay' ||\n methodName === 'unlock' || methodName === 'tip' ||\n methodName === 'donate' || methodName === 'order') {\n\n this.open = true;\n this.activeIndex = 0;\n this.completed = false;\n this.failed = false;\n this.errorMessage = null;\n this.showSuccess = false;\n this.showConfetti = false;\n\n // Do not show an internal wallet selector; parent widgets handle wallet modal\n this.showWalletSelector = false;\n this.isTransitioning = false;\n\n // Reset all steps to pending\n this.currentSteps = this.currentSteps.map(step => ({ ...step, status: 'pending' as StepStatus }));\n\n // Step 0: Wallet connect loading (rename if onramp)\n if (methodType === 'onramp') {\n // Update wallet step copy for onramp flow\n const idx = this.getStepIndexByKey('wallet');\n if (idx >= 0) {\n this.currentSteps[idx] = {\n ...this.currentSteps[idx],\n label: 'Transak Started',\n tooltip: 'Awaiting Transak information',\n } as any;\n }\n }\n this.setLoadingByKey('wallet');\n\n // Update amount and currency if provided in event\n if (e?.detail?.amount !== undefined) {\n this.currentAmount = e.detail.amount;\n this.amount = e.detail.amount;\n debugLog(this.debug, 'ICPay Progress: Amount updated to:', e.detail.amount);\n }\n if (e?.detail?.currency) {\n this.currentCurrency = e.detail.currency;\n this.currency = e.detail.currency;\n debugLog(this.debug, 'ICPay Progress: Currency updated to:', e.detail.currency);\n }\n if (e?.detail?.ledgerSymbol) {\n this.currentLedgerSymbol = e.detail.ledgerSymbol;\n this.ledgerSymbol = e.detail.ledgerSymbol;\n debugLog(this.debug, 'ICPay Progress: Current state after method start:', {\n activeIndex: this.activeIndex,\n currentAmount: this.currentAmount,\n currentCurrency: this.currentCurrency,\n currentLedgerSymbol: this.currentLedgerSymbol\n });\n }\n\n // Waiting for wallet confirmation event to proceed\n debugLog(this.debug, 'ICPay Progress: Waiting for wallet confirmation before starting progression');\n\n this.requestUpdate();\n }\n\n // Mid-flow granular starts for internal SDK steps (independent of top-level starts)\n if (!this.failed && !this.completed) {\n if (methodName === 'sendFundsToLedger') {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.completeByKey('await');\n this.setLoadingByKey('transfer');\n } else if (methodName === 'notifyLedgerTransaction') {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.completeByKey('await');\n this.completeByKey('transfer');\n this.setLoadingByKey('verify');\n }\n }\n };\n\n private startAutomaticProgression() {\n // Clear any existing progression timer\n if (this.progressionTimer) {\n clearInterval(this.progressionTimer);\n }\n\n // Start from step 1 (second step) since step 0 is already completed\n this.activeIndex = 1;\n this.updateStepStatus(this.activeIndex, 'loading');\n\n debugLog(this.debug, 'ICPay Progress: Starting automatic progression from step:', this.activeIndex);\n\n // Progress through steps every 3 seconds\n this.progressionTimer = setInterval(() => {\n if (this.failed || this.completed) {\n this.stopAutomaticProgression();\n return;\n }\n\n debugLog(this.debug, 'ICPay Progress: Processing step:', this.activeIndex);\n\n // Complete current step\n this.updateStepStatus(this.activeIndex, 'completed');\n\n // Move to next step if available\n if (this.activeIndex < this.currentSteps.length - 1) {\n this.activeIndex++;\n this.updateStepStatus(this.activeIndex, 'loading');\n debugLog(this.debug, 'ICPay Progress: Auto-progressed to step:', this.activeIndex);\n } else {\n // All steps completed, stop progression and wait for transaction completion\n this.stopAutomaticProgression();\n debugLog(this.debug, 'ICPay Progress: All steps completed, waiting for transaction completion');\n }\n\n this.requestUpdate();\n }, 3000);\n }\n\n private stopAutomaticProgression() {\n if (this.progressionTimer) {\n clearInterval(this.progressionTimer);\n this.progressionTimer = null;\n }\n }\n\n private onMethodSuccess = (e: any) => {\n const methodName = e?.detail?.name || '';\n if (methodName === 'createPayment' || methodName === 'createPaymentUsd' ||\n methodName === 'sendUsd' || methodName === 'pay' ||\n methodName === 'unlock' || methodName === 'tip' ||\n methodName === 'donate' || methodName === 'order') {\n\n // Dispatch method success event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-method-success', {\n detail: { methodName, step: this.activeIndex },\n bubbles: true\n }));\n }\n\n // Map SDK method successes to step completions (mid-flow methods)\n if (!this.failed && !this.completed) {\n if (methodName === 'getLedgerBalance') {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.setLoadingByKey('await');\n } else if (methodName === 'sendFundsToLedger') {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.completeByKey('await');\n this.completeByKey('transfer');\n this.setLoadingByKey('verify');\n } else if (methodName === 'notifyLedgerTransaction') {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.completeByKey('await');\n this.completeByKey('transfer');\n this.completeByKey('verify');\n this.setLoadingByKey('confirm');\n }\n }\n };\n\n private onTransactionCreated = (e: any) => {\n const transactionId = e?.detail?.transactionId || e?.detail?.id;\n\n debugLog(this.debug, 'ICPay Progress: Transaction created event received:', e.detail);\n\n // Await -> completed on intent created; start transfer loading\n if (!this.failed && !this.completed) {\n this.completeByKey('wallet');\n this.completeByKey('init');\n this.completeByKey('await');\n this.setLoadingByKey('transfer');\n }\n\n // Dispatch transaction created event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-transaction-created', {\n detail: { transactionId, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onTransactionUpdated = (e: any) => {\n const status = e?.detail?.status || 'pending';\n const transactionId = e?.detail?.transactionId || e?.detail?.id;\n\n debugLog(this.debug, 'ICPay Progress: Transaction updated event received:', e.detail);\n\n // When pending turns to confirmed, we will complete progression in onTransactionCompleted\n if (!this.failed && !this.completed && status === 'pending') {\n // Keep current step loading\n }\n\n // Dispatch transaction updated event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-transaction-updated', {\n detail: { status, transactionId, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onTransactionCompleted = (e: any) => {\n const transactionId = e?.detail?.transactionId || e?.detail?.id;\n const status = e?.detail?.status || 'completed';\n\n debugLog(this.debug, 'ICPay Progress: Transaction completed event received:', e.detail);\n debugLog(this.debug, 'ICPay Progress: Current state when transaction completed:', {\n activeIndex: this.activeIndex,\n completed: this.completed,\n failed: this.failed,\n showSuccess: this.showSuccess\n });\n\n // Ensure remaining steps are completed in sequence before final success\n this.completeByKey('transfer');\n this.completeByKey('await');\n this.completeByKey('init');\n this.completeByKey('verify');\n this.completeByKey('confirm');\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n\n // Dispatch completion event\n this.dispatchEvent(new CustomEvent('icpay-progress-completed', {\n detail: {\n transactionId,\n status,\n amount: this.currentAmount || this.amount,\n currency: this.currentCurrency || this.currency,\n ledgerSymbol: this.currentLedgerSymbol || this.ledgerSymbol\n },\n bubbles: true\n }));\n\n // Auto-close after 2 seconds if user hasn't closed it manually\n /*setTimeout(() => {\n if (this.open && this.showSuccess && !this.failed) {\n this.open = false;\n }\n }, 2000);*/\n\n // Only hide confetti after 3 seconds\n setTimeout(() => {\n this.showConfetti = false;\n }, 3000);\n };\n\n private onTransactionFailed = (e: any) => {\n const errorMessage = e?.detail?.message || e?.detail?.error?.message || 'Transaction failed';\n const errorCode = e?.detail?.error?.code || e?.detail?.code || 'UNKNOWN_ERROR';\n const transactionId = e?.detail?.transactionId || e?.detail?.id;\n\n debugLog(this.debug, 'ICPay Progress: Transaction failed event received:', e.detail);\n\n // Mark as failed and keep modal open with error message\n this.failed = true;\n this.errorMessage = this.transformErrorMessage(errorMessage);\n this.showSuccess = false;\n this.updateStepStatus(this.activeIndex, 'error', errorMessage);\n this.stopAutomaticProgression();\n this.open = true;\n\n // Dispatch transaction failed event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-failed', {\n detail: { errorMessage, errorCode, transactionId, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onTransactionMismatched = (e: any) => {\n const requestedAmount = e?.detail?.requestedAmount;\n const paidAmount = e?.detail?.paidAmount;\n const transactionId = e?.detail?.transactionId || e?.detail?.id;\n\n //debugLog(this.debug, 'ICPay Progress: Transaction mismatched event received:', e.detail);\n\n // Treat as failure with specific message\n this.failed = true;\n const requested = requestedAmount != null ? String(requestedAmount) : 'unknown';\n const paid = paidAmount != null ? String(paidAmount) : 'unknown';\n this.errorMessage = `Amount mismatch. Requested ${requested}, paid ${paid}.`;\n this.showSuccess = false;\n this.updateStepStatus(this.activeIndex, 'error', this.errorMessage);\n this.stopAutomaticProgression();\n this.open = true;\n\n // Dispatch failed event with mismatch context\n this.dispatchEvent(new CustomEvent('icpay-progress-failed', {\n detail: { errorMessage: this.errorMessage, errorCode: 'MISMATCHED_AMOUNT', transactionId, step: this.activeIndex, requestedAmount, paidAmount },\n bubbles: true\n }));\n };\n\n private onMethodError = (e: any) => {\n const methodName = e?.detail?.name || '';\n const errorMessage = e?.detail?.error?.message || e?.detail?.message || 'An error occurred';\n const errorCode = e?.detail?.error?.code || e?.detail?.code || 'METHOD_ERROR';\n\n debugLog(this.debug, 'ICPay Progress: Method error event received:', e.detail);\n\n if (methodName?.startsWith('createPayment') || methodName === 'sendUsd' ||\n methodName === 'pay' || methodName === 'unlock' ||\n methodName === 'tip' || methodName === 'donate' ||\n methodName === 'order') {\n // Mark as failed and keep modal open with error message\n this.failed = true;\n this.errorMessage = this.transformErrorMessage(errorMessage);\n this.showSuccess = false;\n this.updateStepStatus(this.activeIndex, 'error', errorMessage);\n this.stopAutomaticProgression();\n this.open = true;\n\n // Dispatch method error event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-error', {\n detail: { methodName, errorMessage, errorCode, step: this.activeIndex },\n bubbles: true\n }));\n }\n };\n\n private onSDKError = (e: any) => {\n const errorMessage = e?.detail?.message || 'SDK error occurred';\n const errorCode = e?.detail?.code || 'SDK_ERROR';\n\n debugLog(this.debug, 'ICPay Progress: SDK error event received:', e.detail);\n\n // Mark as failed and keep modal open with error message\n this.failed = true;\n this.errorMessage = this.transformErrorMessage(errorMessage);\n this.showSuccess = false;\n this.updateStepStatus(this.activeIndex, 'error', errorMessage);\n this.stopAutomaticProgression();\n this.open = true;\n\n // Dispatch SDK error event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-sdk-error', {\n detail: { errorMessage, errorCode, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWalletConnected = (e: any) => {\n const walletType = e?.detail?.walletType || 'unknown';\n\n debugLog(this.debug, 'ICPay Progress: Wallet connected event received:', e.detail);\n\n // Complete wallet step and set init to loading\n this.completeByKey('wallet');\n this.setLoadingByKey('init');\n\n // Start transition from wallet selector to progress bar\n this.startTransitionToProgress();\n\n // Dispatch wallet connected event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-wallet-connected', {\n detail: { walletType, step: this.activeIndex },\n bubbles: true\n }));\n this.currentWalletType = walletType;\n };\n\n private onWalletDisconnected = (e: any) => {\n const walletType = e?.detail?.walletType || 'unknown';\n\n debugLog(this.debug, 'ICPay Progress: Wallet disconnected event received:', e.detail);\n\n // Dispatch wallet disconnected event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-wallet-disconnected', {\n detail: { walletType, step: this.activeIndex },\n bubbles: true\n }));\n this.currentWalletType = null;\n };\n\n private onBalanceCheck = (e: any) => {\n const hasBalance = e?.detail?.hasBalance || false;\n const balance = e?.detail?.balance || 0;\n\n debugLog(this.debug, 'ICPay Progress: Balance check event received:', e.detail);\n\n // Handle insufficient balance error\n if (!hasBalance) {\n this.failed = true;\n this.errorMessage = 'Insufficient balance for transaction';\n this.updateStepStatus(this.activeIndex, 'error', 'Insufficient balance for transaction');\n this.stopAutomaticProgression();\n this.showWalletSelector = false; // Ensure we're in progress view for error\n\n // Dispatch insufficient balance event\n this.dispatchEvent(new CustomEvent('icpay-progress-insufficient-balance', {\n detail: { balance, required: this.currentAmount || this.amount, step: this.activeIndex },\n bubbles: true\n }));\n }\n };\n\n private onLedgerVerified = (e: any) => {\n const ledgerId = e?.detail?.ledgerId || e?.detail?.canisterId;\n const symbol = e?.detail?.symbol || 'unknown';\n\n debugLog(this.debug, 'ICPay Progress: Ledger verified event received:', e.detail);\n\n // Update ledger symbol if provided\n if (symbol && symbol !== 'unknown') {\n this.currentLedgerSymbol = symbol;\n this.ledgerSymbol = symbol;\n }\n\n // Dispatch ledger verified event\n this.dispatchEvent(new CustomEvent('icpay-progress-ledger-verified', {\n detail: { ledgerId, symbol, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n // Widget-specific event handlers for better integration\n private onWidgetPayment = (e: any) => {\n const amount = e?.detail?.amount;\n const currency = e?.detail?.currency;\n const ledgerSymbol = e?.detail?.ledgerSymbol;\n\n debugLog(this.debug, 'ICPay Progress: Widget payment event received:', e.detail);\n\n // Update dynamic values if provided\n if (amount !== undefined) {\n this.currentAmount = amount;\n this.amount = amount;\n }\n if (currency) {\n this.currentCurrency = currency;\n this.currency = currency;\n }\n if (ledgerSymbol) {\n this.currentLedgerSymbol = ledgerSymbol;\n this.ledgerSymbol = ledgerSymbol;\n }\n\n // Advance steps to success state (event-driven, no auto progression)\n if (!this.failed) {\n for (let i = this.activeIndex; i < this.currentSteps.length; i++) {\n this.updateStepStatus(i, 'completed');\n }\n this.activeIndex = this.currentSteps.length - 1;\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n }\n\n // Dispatch widget payment event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-payment', {\n detail: { amount, currency, ledgerSymbol, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWidgetError = (e: any) => {\n const errorMessage = e?.detail?.message || 'Widget error occurred';\n const errorCode = e?.detail?.code || 'WIDGET_ERROR';\n\n debugLog(this.debug, 'ICPay Progress: Widget error event received:', e.detail);\n\n // Mark as failed and keep modal open with error message\n this.failed = true;\n this.errorMessage = this.transformErrorMessage(errorMessage);\n this.showSuccess = false;\n this.updateStepStatus(this.activeIndex, 'error', errorMessage);\n this.stopAutomaticProgression();\n this.open = true;\n\n // Dispatch widget error event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-error', {\n detail: { errorMessage, errorCode, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWidgetUnlock = (e: any) => {\n const amount = e?.detail?.amount;\n const currency = e?.detail?.currency;\n\n debugLog(this.debug, 'ICPay Progress: Widget unlock event received:', e.detail);\n\n // Complete steps and show success\n if (!this.failed) {\n for (let i = this.activeIndex; i < this.currentSteps.length; i++) {\n this.updateStepStatus(i, 'completed');\n }\n this.activeIndex = this.currentSteps.length - 1;\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n }\n\n // Dispatch widget unlock event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-unlock', {\n detail: { amount, currency, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWidgetTip = (e: any) => {\n const amount = e?.detail?.amount;\n const currency = e?.detail?.currency;\n\n debugLog(this.debug, 'ICPay Progress: Widget tip event received:', e.detail);\n\n // Complete steps and show success\n if (!this.failed) {\n for (let i = this.activeIndex; i < this.currentSteps.length; i++) {\n this.updateStepStatus(i, 'completed');\n }\n this.activeIndex = this.currentSteps.length - 1;\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n }\n\n // Dispatch widget tip event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-tip', {\n detail: { amount, currency, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWidgetDonation = (e: any) => {\n const amount = e?.detail?.amount;\n const currency = e?.detail?.currency;\n\n debugLog(this.debug, 'ICPay Progress: Widget donation event received:', e.detail);\n\n // Complete steps and show success\n if (!this.failed) {\n for (let i = this.activeIndex; i < this.currentSteps.length; i++) {\n this.updateStepStatus(i, 'completed');\n }\n this.activeIndex = this.currentSteps.length - 1;\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n }\n\n // Dispatch widget donation event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-donation', {\n detail: { amount, currency, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private onWidgetCoffee = (e: any) => {\n const amount = e?.detail?.amount;\n const currency = e?.detail?.currency;\n\n debugLog(this.debug, 'ICPay Progress: Widget coffee event received:', e.detail);\n\n // Complete steps and show success\n if (!this.failed) {\n for (let i = this.activeIndex; i < this.currentSteps.length; i++) {\n this.updateStepStatus(i, 'completed');\n }\n this.activeIndex = this.currentSteps.length - 1;\n this.completed = true;\n this.showSuccess = true;\n this.showConfetti = true;\n }\n\n // Dispatch widget coffee event for external listeners\n this.dispatchEvent(new CustomEvent('icpay-progress-widget-coffee', {\n detail: { amount, currency, step: this.activeIndex },\n bubbles: true\n }));\n };\n\n private updateStepStatus(stepIndex: number, status: StepStatus, errorMessage?: string | null) {\n if (stepIndex >= 0 && stepIndex < this.currentSteps.length) {\n const step = this.currentSteps[stepIndex];\n const oldStatus = step.status;\n\n step.status = status;\n if (status === 'completed') {\n step.timestamp = this.getCurrentTime();\n }\n if (status === 'error' && errorMessage) {\n step.errorMessage = this.transformErrorMessage(errorMessage);\n }\n\n debugLog(this.debug, `ICPay Progress: Step ${stepIndex} (${step.label}) status changed from ${oldStatus} to ${status}`);\n\n this.requestUpdate();\n }\n }\n\n private getCurrentTime() {\n const now = new Date();\n return now.toLocaleTimeString('en-US', {\n hour12: false,\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit'\n });\n }\n\n private getStepIcon(step: Step): string | any {\n switch (step.status) {\n case 'loading':\n return html`<div class=\"loading-spinner\"></div>`; // Use the styled loading spinner\n case 'completed':\n return html`<svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M5 13l4 4L19 7\" />\n </svg>`; // Checkmark icon\n case 'error':\n return html`<svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M6 18L18 6M6 6l12 12\" />\n </svg>`; // X mark icon\n default:\n return html`<svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z\" />\n </svg>`; // Process icon for pending\n }\n }\n\n private getStepIndexByKey(key: string): number {\n return this.currentSteps.findIndex(s => s.key === key);\n }\n\n private setLoadingByKey(key: string) {\n const idx = this.getStepIndexByKey(key);\n if (idx >= 0) {\n this.activeIndex = idx;\n this.updateStepStatus(idx, 'loading');\n if (key === 'confirm') {\n this.confirmLoadingStartedAt = Date.now();\n }\n }\n }\n\n private completeByKey(key: string) {\n const idx = this.getStepIndexByKey(key);\n if (idx >= 0) {\n this.updateStepStatus(idx, 'completed');\n this.activeIndex = idx;\n }\n }\n\n // Normalize specific error messages to friendlier text\n private transformErrorMessage(message: string): string {\n const msg = String(message || '').toLowerCase();\n if (msg.includes('user rejected')) return 'User have rejected the transfer';\n if (msg.includes('user cancelled') || msg.includes('user canceled')) return 'User have rejected the transfer';\n if (msg.includes('signature rejected')) return 'User have rejected the transfer';\n return message;\n }\n\n private renderConfetti() {\n if (!this.showConfetti) return '';\n\n const confettiPieces = Array.from({ length: 50 }, (_, i) => i);\n const colors = ['#0066FF', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6'];\n\n return html`\n <div class=\"confetti\">\n ${confettiPieces.map((piece) => html`\n <div\n class=\"confetti-piece\"\n style=\"\n left: ${Math.random() * 100}%;\n top: ${Math.random() * 100}%;\n background-color: ${colors[Math.floor(Math.random() * colors.length)]};\n animation-delay: ${Math.random() * 2}s;\n animation-duration: ${2 + Math.random() * 2}s;\n \"\n ></div>\n `)}\n </div>\n `;\n }\n\n private renderSuccessState() {\n const displayAmount = this.currentAmount || this.amount;\n const displayCurrency = this.currentLedgerSymbol || this.currentCurrency || this.currency;\n\n debugLog(this.debug, 'ICPay Progress: Rendering success state with:', {\n displayAmount,\n displayCurrency,\n currentAmount: this.currentAmount,\n amount: this.amount,\n currentCurrency: this.currentCurrency,\n currency: this.currency,\n currentLedgerSymbol: this.currentLedgerSymbol,\n ledgerSymbol: this.ledgerSymbol\n });\n\n return html`\n <div class=\"success-container\">\n <div class=\"success-icon\">\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M5 13l4 4L19 7\" />\n </svg>\n </div>\n <h2 class=\"success-title\">Payment Complete!</h2>\n <p class=\"success-message\">Your payment of ${displayAmount} USD has been successfully processed.</p>\n <div class=\"success-actions\">\n <button class=\"btn btn-primary\" @click=${() => { this.open = false; }}>Close</button>\n </div>\n </div>\n `;\n }\n\n private renderErrorState() {\n const isInsufficientFunds = this.errorMessage?.includes('Insufficient balance') || false;\n\n if (isInsufficientFunds) {\n return this.renderInsufficientFundsError();\n }\n\n return this.renderGenericError();\n }\n\n private renderInsufficientFundsError() {\n const displayAmount = this.currentAmount || this.amount;\n const displayCurrency = this.currentLedgerSymbol || this.currentCurrency || this.currency;\n\n return html`\n <div class=\"insufficient-funds-container\">\n <div class=\"payment-summary\">\n <div class=\"payment-amount\">Pay $${displayAmount} with ${displayCurrency}</div>\n </div>\n\n <div class=\"error-notification\">\n <div class=\"error-content\">\n <div class=\"error-icon-small\">\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.5 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z\" />\n </svg>\n </div>\n <div class=\"error-text\">Insufficient balance for this transaction</div>\n </div>\n </div>\n\n <div class=\"error-actions\">\n <button class=\"btn btn-secondary\" @click=${() => this.requestSwitchAccount()} title=\"Switch to a different account\">\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" style=\"width: 16px; height: 16px;\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4\" />\n </svg>\n Switch Account\n </button>\n <button class=\"btn btn-primary\" @click=${() => { this.open = false; }}>\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" style=\"width: 16px; height: 16px;\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M6 18L18 6M6 6l12 12\" />\n </svg>\n Close\n </button>\n </div>\n </div>\n `;\n }\n\n private renderGenericError() {\n return html`\n <div class=\"error-container\">\n <div class=\"error-icon-large\">\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z\" />\n </svg>\n </div>\n <h2 class=\"error-title\">Transaction Failed</h2>\n <p class=\"error-message-text\">${this.errorMessage}</p>\n <div class=\"error-actions\">\n <button class=\"btn btn-secondary\" @click=${() => this.requestSwitchAccount()} title=\"Switch to a different account\">\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" style=\"width: 16px; height: 16px;\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4\" />\n </svg>\n Switch Account\n </button>\n <button class=\"btn btn-primary\" @click=${() => { this.open = false; }}>\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" style=\"width: 16px; height: 16px;\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M6 18L18 6M6 6l12 12\" />\n </svg>\n Close\n </button>\n </div>\n </div>\n `;\n }\n\n private requestSwitchAccount() {\n try {\n // Close the progress modal so the wallet selector can be used\n this.open = false;\n const walletType = this.currentWalletType || 'unknown';\n window.dispatchEvent(new CustomEvent('icpay-switch-account', { detail: { walletType } } as any));\n } catch {}\n }\n\n private handleAddFunds() {\n try {\n // Dispatch add funds event for external handling\n window.dispatchEvent(new CustomEvent('icpay-add-funds', {\n detail: {\n amount: this.currentAmount || this.amount,\n currency: this.currentLedgerSymbol || this.currentCurrency || this.currency\n }\n }));\n\n // Close the modal to allow external handling\n this.open = false;\n } catch (error) {\n console.error('Error handling add funds:', error);\n }\n }\n\n private startTransitionToProgress() {\n this.isTransitioning = true;\n this.requestUpdate();\n\n // After transition animation completes, switch to progress view\n setTimeout(() => {\n this.showWalletSelector = false;\n this.isTransitioning = false;\n this.requestUpdate();\n }, 400);\n }\n\n private renderProgressContent() {\n if (this.showSuccess) {\n return this.renderSuccessState();\n }\n\n if (this.failed) {\n return this.renderErrorState();\n }\n\n return html`\n <div class=\"progress-container\">\n <div class=\"progress-header\">\n <h3 class=\"progress-title\">Processing Payment</h3>\n <p class=\"progress-subtitle\">Please wait while we process your transaction</p>\n ${this.renderConfirmTip()}\n </div>\n <div class=\"progress-steps\">\n ${this.currentSteps.map((step, index) => html`\n <div class=\"step ${index === this.activeIndex ? 'active' : ''} ${step.status === 'completed' ? 'completed' : ''} ${step.status === 'error' ? 'error' : ''}\">\n <div class=\"step-icon\">\n ${step.status === 'loading' ? html`<div class=\"loading-spinner\"></div>` : ''}\n ${step.status === 'completed' ? html`\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M5 13l4 4L19 7\" />\n </svg>\n ` : step.status === 'error' ? html`\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M6 18L18 6M6 6l12 12\" />\n </svg>\n ` : html`\n <svg fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z\" />\n </svg>\n `}\n </div>\n <div class=\"step-content\">\n <div class=\"step-title\">${step.label}</div>\n <div class=\"step-description\">${step.tooltip}</div>\n ${step.status === 'error' && step.errorMessage ? html`\n <div class=\"step-error-message\">${step.errorMessage}</div>\n ` : ''}\n </div>\n </div>\n `)}\n </div>\n </div>\n `;\n }\n\n private renderConfirmTip() {\n try {\n const confirmIdx = this.getStepIndexByKey('confirm');\n if (confirmIdx < 0) return null as any;\n const isConfirmLoading = this.activeIndex === confirmIdx && this.currentSteps[confirmIdx]?.status === 'loading';\n if (!isConfirmLoading) return null as any;\n const started = this.confirmLoadingStartedAt || 0;\n const elapsed = started ? (Date.now() - started) : 0;\n if (elapsed < 30000) return null as any;\n return html`<p class=\"progress-subtitle\" style=\"margin-top:8px;color:#60a5fa\">Verification can take from 30 seconds up to 10 minutes depending on the amount. Please wait…</p>`;\n } catch {\n return null as any;\n }\n }\n\n private retryTransaction() {\n // Reset state but preserve dynamic values\n this.activeIndex = 0;\n this.completed = false;\n this.failed = false;\n this.errorMessage = null;\n this.showSuccess = false;\n this.showConfetti = false;\n\n // Preserve dynamic values from the current transaction\n // Don't reset currentAmount, currentCurrency, currentLedgerSymbol\n\n // Reset all steps to pending\n this.currentSteps = this.currentSteps.map(step => ({ ...step, status: 'pending' as StepStatus }));\n\n // Update first step to loading\n this.updateStepStatus(0, 'loading');\n\n // Start automatic progression again\n this.startAutomaticProgression();\n\n this.requestUpdate();\n }\n\n private closeProgress() {\n this.open = false;\n this.showWalletSelector = false;\n this.isTransitioning = false;\n }\n\n private renderStep(step: Step, index: number) {\n return html`\n <div class=\"step-item ${step.status}\">\n <div class=\"step-icon\">\n ${this.getStepIcon(step)}\n </div>\n <div class=\"step-content\">\n <div class=\"step-title\">\n ${step.status === 'completed' ? 'COMPLETED' : step.label}\n </div>\n ${step.status === 'completed' ? html`\n <div class=\"step-subtitle\">\n ${step.timestamp} - ${step.tooltip}\n </div>\n ` : step.status === 'error' && step.errorMessage ? html`\n <div class=\"step-error\">${step.errorMessage}</div>\n ` : html`\n <div class=\"step-subtitle\">${step.tooltip}</div>\n `}\n </div>\n </div>\n `;\n }\n\n private get isWalletConnectLoading(): boolean {\n try {\n const idx = this.currentSteps.findIndex(s => (s as any).key === 'wallet');\n if (idx < 0) return false;\n return this.currentSteps[idx].status === 'loading' && !this.failed && !this.showSuccess;\n } catch {\n return false;\n }\n }\n\n render() {\n return html`\n ${this.open ? html`\n ${this.renderConfetti()}\n <div class=\"modal-overlay active\">\n <div class=\"modal-container\">\n <button class=\"close-button\" @click=${() => this.closeProgress()} aria-label=\"Close\" title=\"Close\">✕</button>\n <div class=\"modal-content ${this.isTransitioning ? 'transitioning' : ''}\">\n ${this.renderProgressContent()}\n </div>\n </div>\n </div>\n ` : null}\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-progress-bar': ICPayProgressBar } }\n\n\n","import { html, TemplateResult } from 'lit';\n\ntype Environment = 'STAGING' | 'PRODUCTION';\n\nexport type TransakOnrampOptions = {\n\tvisible: boolean;\n\t/** If provided, will embed Transak directly with session id */\n\tsessionId?: string | null;\n\t/** Optional error message to show when sessionId is missing */\n\terrorMessage?: string | null;\n\t/** Transak apiKey (public key). Required if using double-iframe helper */\n\tapiKey?: string | null;\n\t/** Controls staging vs production */\n\tenvironment?: Environment;\n\t/** Optional width/height for inner iframe */\n\twidth?: number | string;\n\theight?: number | string;\n\t/** Called when user closes modal */\n\tonClose: () => void;\n /** Called when user clicks to go back to wallet selector */\n onBack?: () => void;\n};\n\n/**\n * Renders a modal containing Transak onramp widget.\n * - If sessionId is present, we embed Transak directly using the session flow URL.\n * - Otherwise, we fall back to Transak's double-iframe helper page that loads an inner iframe\n * pointing to global-stg/global with the provided apiKey.\n *\n * Reference: https://docs.transak.com/docs/double-embed-iframe-webapp\n */\nexport function renderTransakOnrampModal(opts: TransakOnrampOptions): TemplateResult | null {\n\tif (!opts.visible) return null as any;\n\tconst environment: Environment = opts.environment ?? 'STAGING';\n\tconst width = opts.width ?? 420;\n\tconst height = opts.height ?? 680;\n\n\t// Build iframe src\n\tlet iframeSrc = '';\n\tif (opts.sessionId) {\n\t\t// Direct session embed per Transak session flow.\n\t\t// For production: https://global.transak.com?sessionId=...\n\t\t// For staging: https://global-stg.transak.com?sessionId=...\n\t\tconst base = environment === 'PRODUCTION' ? 'https://global.transak.com' : 'https://global-stg.transak.com';\n\t\tiframeSrc = `${base}?sessionId=${encodeURIComponent(opts.sessionId)}`;\n\t}\n\n\treturn html`\n\t\t<div style=\"position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.85);backdrop-filter:blur(10px);z-index:10000\">\n\t\t\t<div style=\"position:relative;background:#0f1115;border:1px solid rgba(255,255,255,0.1);border-radius:16px;padding:16px;box-shadow:0 20px 60px rgba(0,0,0,0.5)\">\n\t\t\t\t<button @click=${opts.onClose} aria-label=\"Close\" title=\"Close\"\n\t\t\t\t\tstyle=\"position:absolute;top:10px;right:10px;background:transparent;border:none;color:#9ca3af;cursor:pointer;font-size:20px\">✕</button>\n\t\t\t\t${opts.sessionId ? html`\n\t\t\t\t\t<iframe\n id=\"transak-iframe\"\n\t\t\t\t\t\tstyle=\"border:none;border-radius:12px;background:#111\"\n\t\t\t\t\t\twidth=\"${String(width)}\"\n\t\t\t\t\t\theight=\"${String(height)}\"\n\t\t\t\t\t\tsrc=\"${iframeSrc}\"\n\t\t\t\t\t\tallow=\"camera;microphone;payment\"\n\t\t\t\t\t></iframe>\n\t\t\t\t` : html`\n\t\t\t\t\t<div style=\"width:${String(width)}px;max-width:90vw;padding:12px\">\n\t\t\t\t\t\t<div style=\"background:#1a1f2e;border:1px solid rgba(255,255,255,0.1);border-radius:12px;padding:24px;color:#e5e7eb;text-align:center\">\n\t\t\t\t\t\t\t<div style=\"font-size:18px;font-weight:600;margin-bottom:8px\">Service unavailable</div>\n\t\t\t\t\t\t\t<div style=\"font-size:14px;opacity:0.85;margin-bottom:16px\">${opts.errorMessage || 'The service is currently unavailable, please try again later.'}</div>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t@click=${() => { if (opts.onBack) opts.onBack(); else opts.onClose(); }}\n\t\t\t\t\t\t\t\tstyle=\"padding:10px 16px;border-radius:10px;border:1px solid rgba(255,255,255,0.15);background:linear-gradient(135deg,#3b82f6 0%,#10b981 100%);color:#fff;cursor:pointer;font-weight:600\">\n\t\t\t\t\t\t\t\tGo back to wallet selection\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t`}\n\t\t\t</div>\n\t\t</div>\n\t`;\n}\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { PremiumContentConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Plug N Play will be imported dynamically when needed\nlet PlugNPlay: any = null;\n\n// Debug logger utility for widget components\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-premium-content')\nexport class ICPayPremiumContent extends LitElement {\n static styles = [baseStyles, css`\n .image-container {\n position: relative;\n border-radius: 16px;\n overflow: hidden;\n margin-bottom: 16px;\n background: #111827;\n border: 1px solid var(--icpay-border);\n aspect-ratio: 16/10;\n }\n .locked-image {\n width: 100%;\n height: 100%;\n background-size: cover;\n background-position: center;\n background-repeat: no-repeat;\n filter: blur(8px) grayscale(1);\n transition: all 0.6s ease;\n min-height: 200px;\n }\n .locked-image.unlocked { filter: blur(0px) grayscale(1); }\n .lock-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }\n .pricing { text-align: center; margin: 16px 0; }\n .price { font-size: 28px; font-weight: 800; color: var(--icpay-text); }\n .label { color: var(--icpay-muted); font-size: 14px; }\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }\n .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }\n .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n\n .error-message {\n border: 1px solid;\n font-weight: 500;\n }\n\n .error-message.info {\n background: rgba(59, 130, 246, 0.1);\n border-color: rgba(59, 130, 246, 0.3);\n color: #3b82f6;\n }\n\n .error-message.warning {\n background: rgba(245, 158, 11, 0.1);\n border-color: rgba(245, 158, 11, 0.3);\n color: #f59e0b;\n }\n\n .error-message.error {\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n color: #ef4444;\n }\n `];\n\n @property({ type: Object }) config!: PremiumContentConfig;\n @state() private selectedSymbol: string | null = null;\n @state() private unlocked = false;\n @state() private succeeded = false;\n @state() private processing = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'pay' | null = null;\n @state() private showWalletModal = false;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n private async tryAutoConnectPNP() {\n try {\n if (!this.config || this.config?.useOwnWallet) return;\n const raw = localStorage.getItem('icpay:pnp');\n if (!raw) return;\n const saved = JSON.parse(raw);\n if (!saved?.provider || !saved?.principal) return;\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n const _cfg1: any = { ...(this.config?.plugNPlay || {}) };\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg1.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n const pnp = new PlugNPlay(_cfg1);\n // Hydrate saved principal for UI/history; require connect on pay\n this.walletConnected = false;\n this.config = {\n ...this.config,\n connectedWallet: { owner: saved.principal, principal: saved.principal, connected: false } as any\n };\n } catch {}\n }\n\n private get cryptoOptions(): CryptoOption[] {\n // If config provides cryptoOptions, use those (allows override)\n if (this.config.cryptoOptions) {\n return this.config.cryptoOptions;\n }\n // Otherwise use fetched verified ledgers\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Premium content connected', { config: this.config });\n this.tryAutoConnectPNP();\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'pay') this.onPay(); }, 0);\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.config?.priceUsd || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) {\n // Skip in SSR or if config not set yet\n return;\n }\n\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map(ledger => ({\n symbol: ledger.symbol,\n label: ledger.name,\n canisterId: ledger.canisterId\n }));\n // Set default selection to defaultSymbol or first available ledger\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol || 'ICP');\n }\n } catch (error) {\n console.warn('Failed to load verified ledgers:', error);\n // Fallback to basic options if API fails\n this.availableLedgers = [\n { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' }\n ];\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n\n private async onPay() {\n if (!isBrowser) return; // Skip in SSR\n\n if (this.processing || this.unlocked) return;\n\n debugLog(this.config?.debug || false, 'Premium content payment started', {\n priceUsd: this.config.priceUsd,\n selectedSymbol: this.selectedSymbol,\n useOwnWallet: this.config.useOwnWallet\n });\n\n // Clear previous errors\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount: this.config.priceUsd, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Check wallet connection status first\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'pay';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return;\n }\n } else {\n // Built-in wallet handling - connect directly with Plug N Play\n if (!this.walletConnected) {\n debugLog(this.config?.debug || false, 'Connecting to wallet via Plug N Play');\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _cfg2: any = wantsOisyTab ? applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) }) : ({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg2.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg2);\n try {\n const principal = await detectOisySessionViaAdapter(this.pnp);\n if (principal) {\n this.walletConnected = true;\n const normalized = normalizeConnectedWallet(this.pnp, { owner: principal, principal, connected: true });\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n // Proceed directly\n this.onPay();\n return;\n }\n } catch {}\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n return;\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error:', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return;\n }\n }\n }\n\n // Wallet is connected, proceed with payment\n debugLog(this.config?.debug || false, 'Creating SDK for payment');\n const sdk = createSdk(this.config);\n\n // resolve canisterId by symbol if provided, otherwise require canisterId per option\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const option = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = option.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n\n debugLog(this.config?.debug || false, 'Payment details', {\n priceUsd: this.config.priceUsd,\n selectedSymbol: symbol,\n canisterId\n });\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(this.config.priceUsd, canisterId, { context: 'premium-content' });\n debugLog(this.config?.debug || false, 'Payment completed', { resp });\n\n this.unlocked = true;\n this.succeeded = true;\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status });\n this.dispatchEvent(new CustomEvent('icpay-unlock', { detail: { amount: this.config.priceUsd, tx: resp }, bubbles: true }));\n } catch (e) {\n // Handle errors using the new error handling system\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n\n // Update UI error state if error should be shown to user\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const option = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = option.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await (sdk as any).startOnrampUsd(this.config.priceUsd, canisterId, { context: 'premium:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private select(symbol: string) {\n this.selectedSymbol = symbol;\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'pay') setTimeout(() => this.onPay(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n render() {\n if (!this.config) {\n return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n }\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\">\n ${this.config?.progressBar?.enabled !== false ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.config?.priceUsd || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n <div class=\"image-container\">\n <div class=\"locked-image ${this.unlocked ? 'unlocked' : ''}\" style=\"background-image:url('${this.config.imageUrl || ''}')\"></div>\n ${this.unlocked ? null : html`<div class=\"lock-overlay\">🔒</div>`}\n </div>\n\n <div class=\"pricing\">\n <div class=\"price\">$${Number(this.config?.priceUsd ?? 0).toFixed(2)}</div>\n <div class=\"label\">One-time unlock</div>\n </div>\n\n <div>\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${(this.config?.showLedgerDropdown || 'buttons')}\n @icpay-token-change=${(e: any) => this.select(e.detail.symbol)}\n ></icpay-token-selector>\n </div>\n\n <button class=\"pay-button ${this.processing ? 'processing' : ''}\" ?disabled=${this.processing || this.unlocked || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)} @click=${() => this.onPay()}>\n ${this.unlocked ? 'Unlocked' : (this.processing ? 'Processing…' : (\n (this.config?.buttonLabel || 'Pay ${amount} with {symbol}')\n .replace('{amount}', `${Number(this.config?.priceUsd ?? 0).toFixed(2)}`)\n .replace('{symbol}', (this.selectedSymbol || this.config?.defaultSymbol || 'ICP'))\n ))}\n </button>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`\n <button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">\n ${this.errorAction}\n </button>\n ` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true)) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true),\n creditCardTooltip: (() => {\n const min = 5; const amt = Number(this.config?.priceUsd || 0); if (amt > 0 && amt < min && ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true))) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.onPay(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-premium-content': ICPayPremiumContent } }\n\n\n","import { IcpayError } from '@ic-pay/icpay-sdk';\n\n// Define error codes locally to avoid SSR issues\nconst ERROR_CODES = {\n WALLET_NOT_CONNECTED: 'WALLET_NOT_CONNECTED',\n WALLET_USER_CANCELLED: 'WALLET_USER_CANCELLED',\n WALLET_SIGNATURE_REJECTED: 'WALLET_SIGNATURE_REJECTED',\n INSUFFICIENT_BALANCE: 'INSUFFICIENT_BALANCE',\n NETWORK_ERROR: 'NETWORK_ERROR',\n API_ERROR: 'API_ERROR',\n LEDGER_NOT_FOUND: 'LEDGER_NOT_FOUND',\n TRANSACTION_FAILED: 'TRANSACTION_FAILED',\n TRANSACTION_TIMEOUT: 'TRANSACTION_TIMEOUT',\n UNKNOWN_ERROR: 'UNKNOWN_ERROR'\n} as const;\n\n// Widget-specific error handling utilities\nexport interface WidgetErrorHandler {\n onError: (error: IcpayError) => void;\n onUserCancelled?: () => void;\n onInsufficientBalance?: (error: IcpayError) => void;\n onWalletError?: (error: IcpayError) => void;\n onNetworkError?: (error: IcpayError) => void;\n}\n\n// Default error handler that logs errors to console\nexport const defaultErrorHandler: WidgetErrorHandler = {\n onError: (error: IcpayError) => {\n console.error('[ICPay Widget] Error:', error);\n },\n onUserCancelled: () => {\n console.log('[ICPay Widget] User cancelled the action');\n },\n onInsufficientBalance: (error: IcpayError) => {\n console.warn('[ICPay Widget] Insufficient balance:', error.message);\n },\n onWalletError: (error: IcpayError) => {\n console.warn('[ICPay Widget] Wallet error:', error.message);\n },\n onNetworkError: (error: IcpayError) => {\n console.error('[ICPay Widget] Network error:', error.message);\n }\n};\n\n// Error handling function for widget components\nexport function handleWidgetError(error: unknown, errorHandler: WidgetErrorHandler = defaultErrorHandler): void {\n if (error instanceof IcpayError) {\n // Call the general error handler\n errorHandler.onError(error);\n\n // Call specific handlers based on error type\n if (error.isUserCancelled()) {\n errorHandler.onUserCancelled?.();\n } else if (error.isBalanceError()) {\n errorHandler.onInsufficientBalance?.(error);\n } else if (error.isWalletError()) {\n errorHandler.onWalletError?.(error);\n } else if (error.isNetworkError()) {\n errorHandler.onNetworkError?.(error);\n }\n } else {\n // Handle non-IcpayError errors\n console.error('[ICPay Widget] Unknown error:', error);\n errorHandler.onError(new IcpayError({\n code: ERROR_CODES.UNKNOWN_ERROR,\n message: error instanceof Error ? error.message : 'An unknown error occurred',\n details: error\n }));\n }\n}\n\n// Error message templates for common scenarios\nexport const ERROR_MESSAGES = {\n [ERROR_CODES.WALLET_NOT_CONNECTED]: 'Please connect your wallet to continue',\n [ERROR_CODES.WALLET_USER_CANCELLED]: 'User have rejected the transfer',\n [ERROR_CODES.WALLET_SIGNATURE_REJECTED]: 'User have rejected the transfer',\n [ERROR_CODES.INSUFFICIENT_BALANCE]: 'Insufficient balance for this transaction',\n [ERROR_CODES.NETWORK_ERROR]: 'Network error. Please try again',\n [ERROR_CODES.API_ERROR]: 'Service temporarily unavailable',\n [ERROR_CODES.LEDGER_NOT_FOUND]: 'Selected token is not supported',\n [ERROR_CODES.TRANSACTION_FAILED]: 'Transaction failed. Please try again',\n [ERROR_CODES.TRANSACTION_TIMEOUT]: 'Transaction timed out. Please try again',\n [ERROR_CODES.UNKNOWN_ERROR]: 'Something went wrong. Please try again'\n} as const;\n\n// Get user-friendly error message\nexport function getErrorMessage(error: IcpayError): string {\n return ERROR_MESSAGES[error.code] || error.message || 'An error occurred';\n}\n\n// Check if error should be shown to user (vs logged only)\nexport function shouldShowErrorToUser(error: IcpayError): boolean {\n // Don't show user-cancelled actions as errors\n if (error.isUserCancelled()) {\n return false;\n }\n\n // Show all other errors to user\n return true;\n}\n\n// Get appropriate UI action for error\nexport function getErrorAction(error: IcpayError): string | null {\n // Disable for now\n return null;\n /*\n if (error.userAction) {\n return error.userAction;\n }\n\n switch (error.code) {\n case ERROR_CODES.WALLET_NOT_CONNECTED:\n return 'Connect Wallet';\n case ERROR_CODES.INSUFFICIENT_BALANCE:\n return 'Add Funds';\n case ERROR_CODES.NETWORK_ERROR:\n case ERROR_CODES.API_ERROR:\n return 'Try Again';\n default:\n return null;\n }\n */\n}\n\n// Error severity levels for UI styling\nexport enum ErrorSeverity {\n INFO = 'info',\n WARNING = 'warning',\n ERROR = 'error'\n}\n\nexport function getErrorSeverity(error: IcpayError): ErrorSeverity {\n if (error.isUserCancelled()) {\n return ErrorSeverity.INFO;\n }\n\n if (error.isBalanceError() || error.isWalletError()) {\n return ErrorSeverity.WARNING;\n }\n\n return ErrorSeverity.ERROR;\n}\n","import { LitElement, html, css } from 'lit';\nimport { applyThemeVars } from '../styles';\nimport { customElement, property } from 'lit/decorators.js';\nimport { query } from 'lit/decorators.js';\nimport type { CryptoOption } from '../types';\n\n@customElement('icpay-token-selector')\nexport class ICPayTokenSelector extends LitElement {\n static styles = css`\n :host { display: block; width: 100%; box-sizing: border-box; }\n\n /* Common */\n .label,\n .icpay-dropdown-label { font-size: 14px; font-weight: 600; color: var(--icpay-text, #fff); margin-bottom: 8px; display: block; }\n\n /* Buttons grid (from crypto-payment-selector) */\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; margin: 12px 0 16px; box-sizing: border-box; }\n .crypto-option { background: var(--icpay-surface-alt, #2a3142); border: 1px solid var(--icpay-border, #3a4154); border-radius: 8px; padding: 8px 4px; cursor: pointer; transition: all 0.15s ease; position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 60px; }\n .crypto-option:active { transform: scale(0.95); }\n .crypto-option.selected { background: #f7f7f7; border-color: #ffffff; }\n .crypto-option.selected .crypto-name { color: #1a1f2e; }\n .crypto-option.selected .crypto-symbol { color: #4a5568; }\n .crypto-option.selected::after { content: \"✓\"; position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; background-color: #22C55E; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: bold; }\n\n /* Icon as external SVG image with constraints */\n .crypto-icon { width: 24px; height: 24px; border-radius: 50%; object-fit: contain; background: transparent; flex-shrink: 0; }\n .crypto-name { font-size: 11px; font-weight: 600; color: var(--icpay-text, #ffffff); text-align: center; line-height: 1.1; }\n .crypto-symbol { font-size: 9px; color: var(--icpay-muted-text, #888); text-align: center; line-height: 1; }\n\n /* Dropdown (from crypto-dropdown-selector) */\n .dropdown-wrapper { position: relative; width: 100%; box-sizing: border-box; }\n .dropdown-trigger { position: relative; width: 100%; box-sizing: border-box; background: var(--icpay-surface, #0a0a0a); border: 1px solid var(--icpay-border, #262626); border-radius: 12px; padding: 10px 40px 10px 16px; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; gap: 12px; min-height: 44px; }\n .dropdown-trigger:hover { border-color: #404040; background: #171717; }\n .dropdown-trigger:active { transform: scale(0.99); }\n .dropdown-trigger.open { border-color: #525252; background: #171717; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }\n .selected-option { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }\n .dropdown-selected-icon { width: 32px; height: 32px; border-radius: 50%; object-fit: contain; flex-shrink: 0; }\n .dropdown-crypto-name { font-size: 14px; font-weight: 600; color: var(--icpay-text, #ffffff); line-height: 1.2; }\n .dropdown-crypto-symbol { font-size: 12px; color: var(--icpay-muted-text, #a3a3a3); line-height: 1.2; }\n .dropdown-arrow { width: 20px; height: 20px; color: #a3a3a3; transition: transform 0.2s ease; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }\n .dropdown-trigger.open .dropdown-arrow { transform: translateY(-50%) rotate(180deg); color: #ffffff; }\n /* Render menu as absolute under wrapper to align within widget */\n .dropdown-wrapper { position: relative; }\n .dropdown-menu { position: absolute; left: 0; top: 100%; background: var(--icpay-surface, #0a0a0a); border: 1px solid var(--icpay-border, #262626); border-top: none; border-radius: 0 0 12px 12px; overflow: hidden; opacity: 0; visibility: hidden; transform: translateY(-10px); transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease; z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,0.5); max-height: 280px; overflow-y: auto; width: 100%; box-sizing: border-box; }\n .dropdown-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }\n .dropdown-option { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; transition: background 0.15s ease; border-bottom: 1px solid #171717; }\n .dropdown-option:last-child { border-bottom: none; }\n .dropdown-option:hover { background: #171717; }\n .dropdown-option:active { background: #262626; }\n .dropdown-option.selected { background: #171717; }\n .dropdown-menu::-webkit-scrollbar { width: 4px; }\n .dropdown-menu::-webkit-scrollbar-track { background: #171717; }\n .dropdown-menu::-webkit-scrollbar-thumb { background: #404040; border-radius: 2px; }\n .dropdown-menu::-webkit-scrollbar-thumb:hover { background: #525252; }\n .dropdown-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.2); opacity: 0; visibility: hidden; transition: all 0.2s ease; z-index: 500; }\n .dropdown-backdrop.open { opacity: 1; visibility: visible; }\n\n /* Small screens */\n @media (max-width: 320px) {\n .crypto-grid { gap: 4px; }\n .crypto-option { padding: 6px 2px; min-height: 54px; }\n .dropdown-trigger { padding: 10px 12px; min-height: 48px; }\n .dropdown-option { padding: 10px 12px; }\n .dropdown-selected-icon { width: 28px; height: 28px; }\n }\n `;\n\n @property({ type: Array }) options: CryptoOption[] = [];\n @property({ type: String }) value: string | null = null;\n @property({ type: String }) defaultSymbol: string = 'ICP';\n @property({ type: String }) mode: 'buttons' | 'dropdown' | 'none' = 'buttons';\n @property({ type: Object }) theme?: { primaryColor?: string; secondaryColor?: string };\n @property({ type: Boolean }) open: boolean = false;\n @property({ type: Boolean }) showLabel: boolean = true;\n @query('.dropdown-trigger') private triggerEl?: HTMLElement;\n @query('.dropdown-wrapper') private wrapperEl?: HTMLElement;\n private menuPos: { left: number; top: number; width: number } = { left: 0, top: 0, width: 0 };\n\n connectedCallback(): void {\n super.connectedCallback();\n try { applyThemeVars(this, this.theme as any); } catch {}\n }\n\n updated(changed: Map<string, unknown>): void {\n if (changed.has('theme')) {\n try { applyThemeVars(this, this.theme as any); } catch {}\n }\n }\n\n firstUpdated(): void {\n const onDocClick = (event: MouseEvent) => {\n if (!this.open) return;\n const path = event.composedPath();\n if (!path.includes(this)) {\n this.closeDropdown();\n }\n };\n const onKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape' && this.open) {\n this.closeDropdown();\n }\n };\n // Store on instance for removal\n (this as any)._onDocClick = onDocClick;\n (this as any)._onKey = onKey;\n window.addEventListener('click', onDocClick);\n window.addEventListener('keydown', onKey);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n const onDocClick = (this as any)._onDocClick as ((e: MouseEvent) => void) | undefined;\n const onKey = (this as any)._onKey as ((e: KeyboardEvent) => void) | undefined;\n if (onDocClick) window.removeEventListener('click', onDocClick);\n if (onKey) window.removeEventListener('keydown', onKey);\n // no-op: no position listeners\n }\n\n private get effectiveSymbol(): string {\n if (this.value) return this.value;\n const single = this.options?.[0]?.symbol;\n return this.defaultSymbol || single || 'ICP';\n }\n\n private getOptionBySymbol(symbol: string): CryptoOption | undefined {\n return (this.options || []).find(o => o.symbol === symbol);\n }\n\n private getLogoUrl(symbol: string): string {\n const slug = String(symbol || '').toLowerCase();\n // Prefer explicit chain via element attribute or global window config; default to 'ic'\n const chain = (this.getAttribute('chain-name') || (window as any)?.ICPay?.config?.chainName || 'IC').toLowerCase();\n const base = (window as any)?.ICPay?.config?.widgetBaseUrl || 'https://widget.icpay.org';\n return `${base}/img/tokens/${chain}/${slug}.svg`;\n }\n\n private onSelect(symbol: string) {\n this.value = symbol;\n // Force update to ensure current selection reflects immediately\n this.requestUpdate('value');\n this.open = false;\n this.dispatchEvent(new CustomEvent('icpay-token-change', { detail: { symbol }, bubbles: true, composed: true }));\n }\n\n private toggleDropdown() {\n this.open = !this.open;\n // No dynamic positioning required with absolute menu; keep listeners off\n }\n\n private closeDropdown() {\n this.open = false;\n // No-op for absolute menu\n }\n\n // Removed dynamic fixed positioning logic; absolute under wrapper now\n\n render() {\n const opts = this.options || [];\n // If none or single option, and mode is not forced to show UI, render nothing\n if (this.mode === 'none' || opts.length <= 1) {\n // Ensure selected value is set for parent to use\n const sym = opts.length === 1 ? opts[0].symbol : this.effectiveSymbol;\n if (this.value !== sym) {\n // Microtask to avoid render loop\n queueMicrotask(() => this.onSelect(sym));\n }\n return html``;\n }\n\n if (this.mode === 'dropdown') {\n const current = this.effectiveSymbol;\n const currentOpt = this.getOptionBySymbol(current) || { symbol: current, label: current } as CryptoOption;\n return html`\n ${this.showLabel ? html`<label class=\"icpay-dropdown-label\">Payment method</label>` : null}\n <div class=\"dropdown-wrapper\">\n <div class=\"dropdown-trigger ${this.open ? 'open' : ''}\" @click=${() => this.toggleDropdown()}>\n <div class=\"selected-option\">\n <img class=\"dropdown-selected-icon\" src=\"${this.getLogoUrl(currentOpt.symbol)}\" alt=\"${currentOpt.symbol}\" />\n <div class=\"crypto-info\">\n <div class=\"dropdown-crypto-name\">${currentOpt.label}</div>\n <div class=\"dropdown-crypto-symbol\">${currentOpt.symbol}</div>\n </div>\n </div>\n <svg class=\"dropdown-arrow\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" aria-hidden=\"true\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M19 9l-7 7-7-7\" />\n </svg>\n </div>\n\n <div class=\"dropdown-menu ${this.open ? 'open' : ''}\">\n ${opts.map(o => html`\n <div class=\"dropdown-option ${this.value===o.symbol?'selected': (current===o.symbol?'selected':'')}\" @click=${() => this.onSelect(o.symbol)}>\n <img class=\"dropdown-selected-icon\" src=\"${this.getLogoUrl(o.symbol)}\" alt=\"${o.symbol}\" />\n <div class=\"crypto-info\">\n <div class=\"dropdown-crypto-name\">${o.label}</div>\n <div class=\"dropdown-crypto-symbol\">${o.symbol}</div>\n </div>\n </div>\n `)}\n </div>\n </div>\n <div class=\"dropdown-backdrop ${this.open ? 'open' : ''}\" @click=${() => this.closeDropdown()}></div>\n `;\n }\n\n // buttons mode\n const current = this.effectiveSymbol;\n return html`\n <div class=\"icpay-token-selector\" style=\"width:100%;box-sizing:border-box;\">\n ${this.showLabel ? html`<label class=\"label\">Payment method</label>` : null}\n <div class=\"crypto-grid\">\n ${opts.map(o => html`\n <div class=\"crypto-option ${current===o.symbol?'selected':''}\" @click=${() => this.onSelect(o.symbol)}>\n <img class=\"crypto-icon\" src=\"${this.getLogoUrl(o.symbol)}\" alt=\"${o.symbol}\" />\n <div class=\"crypto-name\">${o.label}</div>\n <div class=\"crypto-symbol\">${o.symbol}</div>\n </div>\n `)}\n </div>\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-token-selector': ICPayTokenSelector } }\n\n\n","import { html, TemplateResult } from 'lit';\n\n// Embedded icon for NFID provider (data URL)\n\nfunction sanitizeDataUrl(url: string): string {\n if (!url) return url;\n if (!url.startsWith('data:')) return url;\n // Remove any whitespace that might have slipped in (spaces, newlines, tabs)\n return url.replace(/\\s+/g, '');\n}\n\nfunction getWalletFriendlyName(id: string, fallback?: string): string {\n const lower = (id || '').toLowerCase();\n if (lower === 'ii') return 'Internet Identity';\n if (lower === 'nfid') return 'NFID';\n if (lower === 'plug') return 'Plug';\n if (lower === 'oisy') return 'Oisy';\n if (fallback && fallback.trim()) return fallback;\n return id ? id.charAt(0).toUpperCase() + id.slice(1) : 'Wallet';\n}\n\nexport type WalletEntry = { id: string; label: string; icon?: string | null };\n\ntype Options = {\n visible: boolean;\n wallets: WalletEntry[];\n isConnecting?: boolean;\n onSelect: (walletId: string) => void;\n onClose: () => void;\n // Optional onramp (credit card) entry at the end\n onCreditCard?: () => void;\n creditCardLabel?: string;\n showCreditCard?: boolean;\n creditCardTooltip?: string | null;\n};\n\nexport function renderWalletSelectorModal(opts: Options & { oisyReadyToPay?: boolean; onOisyPay?: () => void }): TemplateResult | null {\n if (!opts.visible) return null as any;\n const { wallets, onSelect, onClose, isConnecting } = opts;\n const normalizedWallets = wallets.map(w => {\n const id = (w.id || '').toLowerCase();\n return {\n ...w,\n // Force NFID to use embedded icon; others keep provided icon\n icon: w.icon ?? null,\n };\n });\n // onramp-start: Temporarily disable Credit Card (Transak) option in wallet selector\n const creditCardSection: TemplateResult | null = null;\n /*\n // Original credit card section (re-enable by replacing `${creditCardSection}` with this block):\n <div style=\"margin:12px 0;height:1px;background:rgba(255,255,255,0.08)\"></div>\n <div style=\"display:flex;flex-direction:column;gap:6px\">\n <button\n @click=${() => { if (opts.onCreditCard) opts.onCreditCard(); }}\n style=\"width:100%;padding:12px 16px;background:linear-gradient(135deg,#3b82f6 0%,#10b981 100%);border:1px solid rgba(255,255,255,0.15);border-radius:8px;color:#fff;text-align:center;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;gap:10px\">\n <span>💳</span>\n <span style=\"font-weight:600\">${opts.creditCardLabel || 'Pay with credit card'}</span>\n </button>\n ${opts.creditCardTooltip ? html`<div style=\"font-size:12px;color:#f5d78a;text-align:center\">${opts.creditCardTooltip}</div>` : null}\n </div>\n */\n // onramp-end\n return html`\n <div style=\"position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.5);z-index:10000\">\n <style>\n .icpay-w-8 { width: 2rem; }\n .icpay-h-8 { height: 2rem; }\n </style>\n <div style=\"background:#1f2937;border-radius:12px;padding:24px;max-width:400px;width:90%;border:1px solid rgba(255,255,255,0.1);position:relative\">\n <button @click=${onClose} style=\"position:absolute;top:16px;right:16px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#9ca3af;cursor:pointer;border:none;background:transparent;font-size:20px\">✕</button>\n ${opts.oisyReadyToPay ? null : html`<h3 style=\"color:#fff;margin:0 48px 16px 0;font-size:18px;font-weight:600\">Choose Wallet</h3>`}\n <div style=\"display:flex;flex-direction:column;gap:8px\">\n ${opts.oisyReadyToPay ? html`\n <button\n @click=${() => { if (opts.onOisyPay) opts.onOisyPay(); }}\n style=\"width:100%;padding:12px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;text-align:left;cursor:pointer;font-size:14px;display:flex;align-items:center;gap:12px;justify-content:center\">\n Pay with OISY\n </button>\n ` : normalizedWallets.map(w => {\n const id = (w.id || '').toLowerCase();\n const displayName = getWalletFriendlyName(w.id, w.label);\n const mainButton = html`\n <button\n @click=${() => onSelect(w.id)}\n style=\"width:100%;padding:12px 16px;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);border-radius:8px;color:#fff;text-align:left;cursor:pointer;font-size:14px;opacity:${isConnecting?0.5:1};display:flex;align-items:center;gap:12px\">\n ${w.icon ? html`\n <div style=\"width:48px;height:48px;display:flex;align-items:center;justify-content:center\">\n <img src=\"${sanitizeDataUrl(w.icon)}\" alt=\"${displayName} logo\" class=\"icpay-w-8 icpay-h-8\" style=\"object-fit:contain\" />\n </div>\n ` : html`\n <div style=\"width:48px;height:48px;background:linear-gradient(135deg,#3b82f6 0%,#8b5cf6 100%);border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:bold\">\n ${displayName}\n </div>\n `}\n <div><div style=\"font-weight:500\">${displayName}</div></div>\n </button>`;\n if (id === 'ii') {\n return html`\n <div style=\"display:flex;gap:8px;align-items:center;width:100%\">\n ${mainButton}\n <button\n @click=${() => { try { window.open('https://identity.ic0.app/','_blank','noopener,noreferrer'); } catch {} }}\n title=\"Use a different Internet Identity\"\n aria-label=\"Use a different Internet Identity\"\n style=\"width:56px;height:72px;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.15);border-radius:8px;color:#9ca3af;cursor:pointer;\">\n <span style=\"font-size:20px\" aria-hidden=\"true\">🔄</span>\n </button>\n </div>`;\n }\n return html`<div style=\"width:100%\">${mainButton}</div>`;\n })}\n </div>\n ${creditCardSection}\n </div>\n </div>\n `;\n}\n\n\n","export function hidePnPDefaultModal(): void {\n try {\n if (typeof document === 'undefined') return;\n const hideNow = () => {\n // Scoped and global overlays\n const selectors = [\n '.icpay-widget-base .modal-overlay',\n '.modal-overlay',\n // legacy roots/selectors\n '.plug-n-play-modal',\n '.pnp-modal',\n '#plug-n-play-root',\n '#pnp-root',\n '[data-pnp-root]',\n '[data-pnp-modal]'\n ];\n document.querySelectorAll(selectors.join(',')).forEach((el) => {\n const overlay = el as HTMLElement;\n try {\n const hasWalletSelector = !!overlay.querySelector?.('.wallet-selector-container');\n if (overlay.classList?.contains('modal-overlay')) {\n if (hasWalletSelector) overlay.style.display = 'none';\n } else {\n overlay.style.display = 'none';\n }\n } catch {}\n });\n };\n\n hideNow();\n\n // Briefly observe DOM mutations to hide overlays that appear after async connects\n try {\n const Observer = (window as any).MutationObserver || (window as any).WebKitMutationObserver;\n if (Observer) {\n const observer = new Observer((mutations: any[]) => {\n for (const m of mutations) {\n if (!m.addedNodes) continue;\n for (const node of m.addedNodes) {\n if (!(node instanceof HTMLElement)) continue;\n if (node.matches?.('.modal-overlay') || node.querySelector?.('.wallet-selector-container')) {\n hideNow();\n }\n }\n }\n });\n observer.observe(document.body, { childList: true, subtree: true });\n setTimeout(() => { try { observer.disconnect(); } catch {} }, 3000);\n }\n } catch {}\n } catch {}\n}\n\n\n// Force Oisy to open in a browser tab (not a sized popup) by clearing window features\n// This relies on @windoge98/plug-n-play honoring adapter.config.transport.windowOpenerFeatures\n// When features string is empty, most browsers open a new tab instead of a popup window\nexport function applyOisyNewTabConfig(cfg: any): any {\n try {\n const next = cfg || {};\n next.adapters = next.adapters || {};\n const oisy = next.adapters.oisy || {};\n const oisyConfig = oisy.config || {};\n const transport = {\n ...(oisyConfig.transport || {}),\n windowOpenerFeatures: '',\n // Allow establishing channel even if not in the same click stack (Oisy signer requirement is strict)\n detectNonClickEstablishment: false\n };\n next.adapters.oisy = { ...oisy, config: { ...oisyConfig, transport } };\n return next;\n } catch {\n return cfg;\n }\n}\n\n// Normalize the connected wallet object to the shape expected by icpay-sdk\n// Ensures there is an `owner` (principal string) available for intent creation\nexport function normalizeConnectedWallet(pnp: any, connectResult: any): any {\n try {\n const fromResult = (connectResult && (connectResult.owner || connectResult.principal)) || null;\n const fromAccount = (pnp && pnp.account && (pnp.account.owner || pnp.account.principal)) || null;\n const toStringSafe = (v: any) => (typeof v === 'string' ? v : (v && typeof v.toString === 'function' ? v.toString() : null));\n const principal = toStringSafe(fromResult) || toStringSafe(fromAccount) || null;\n if (principal) {\n return { owner: principal, principal };\n }\n // Fallback to raw result to maintain other data, but SDK will still require owner\n return connectResult || { owner: null };\n } catch {\n return connectResult || { owner: null };\n }\n}\n\n// Read saved Plug N Play session (provider/principal) from localStorage\n// Try to detect existing Oisy session via adapter APIs (no localStorage/cookies)\n// Returns principal string if an active session is detected, else null\nexport async function detectOisySessionViaAdapter(pnp: any): Promise<string | null> {\n try {\n // Support both external PNP and internal wallet-select implementation\n const getEnabled = typeof pnp?.getEnabledWallets === 'function' ? pnp.getEnabledWallets.bind(pnp) : null;\n if (!getEnabled) return null;\n const enabled = getEnabled() || [];\n const oisyCfg = enabled.find((w: any) => (w?.id || '').toLowerCase() === 'oisy');\n if (!oisyCfg || !oisyCfg.adapter) return null;\n const AdapterCtor = oisyCfg.adapter;\n const adapterInstance = new AdapterCtor({ config: (pnp as any)?.config || {} });\n const connected: boolean = await adapterInstance.isConnected();\n if (!connected) return null;\n const principal: string | null = await adapterInstance.getPrincipal();\n if (principal && principal !== '2vxsx-fae') return principal;\n return null;\n } catch {\n return null;\n }\n}\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { TipJarConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Plug N Play will be imported dynamically when needed\nlet PlugNPlay: any = null;\n\n// Debug logger utility for widget components\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-tip-jar')\nexport class ICPayTipJar extends LitElement {\n static styles = [baseStyles, css`\n .jar { width: 120px; height: 160px; margin: 0 auto 12px; position: relative; background: linear-gradient(135deg, #374151 0%, #4b5563 100%); border-radius: 0 0 60px 60px; border: 3px solid #6b7280; border-top: 8px solid #6b7280; overflow: hidden; }\n .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; }\n .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }\n .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }\n .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }\n .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }\n .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n\n .error-message {\n border: 1px solid;\n font-weight: 500;\n }\n\n .error-message.info {\n background: rgba(59, 130, 246, 0.1);\n border-color: rgba(59, 130, 246, 0.3);\n color: #3b82f6;\n }\n\n .error-message.warning {\n background: rgba(245, 158, 11, 0.1);\n border-color: rgba(245, 158, 11, 0.3);\n color: #f59e0b;\n }\n\n .error-message.error {\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n color: #ef4444;\n }\n `];\n\n @property({ type: Object }) config!: TipJarConfig;\n @state() private selectedAmount = 1;\n @state() private selectedSymbol: string | null = null;\n @state() private total = 0;\n @state() private processing = false;\n @state() private succeeded = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'tip' | null = null;\n @state() private showWalletModal = false;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n private async tryAutoConnectPNP() {\n try {\n if (!this.config || this.config?.useOwnWallet) return;\n const raw = localStorage.getItem('icpay:pnp');\n if (!raw) return;\n const saved = JSON.parse(raw);\n if (!saved?.provider || !saved?.principal) return;\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n const _cfg1: any = applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg1.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n const pnp = new PlugNPlay(_cfg1);\n // Do not call connect here; just hydrate saved principal for UI/history.\n // Keep walletConnected false so pressing pay triggers real connect.\n this.walletConnected = false;\n this.config = {\n ...this.config,\n connectedWallet: { owner: saved.principal, principal: saved.principal, connected: false } as any\n };\n } catch {}\n }\n\n private get amounts(): number[] {\n return this.config?.amountsUsd || [1, 5, 10];\n }\n private get cryptoOptions(): CryptoOption[] {\n // If config provides cryptoOptions, use those (allows override)\n if (this.config.cryptoOptions) {\n return this.config.cryptoOptions;\n }\n // Otherwise use fetched verified ledgers\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Tip jar connected', { config: this.config });\n\n if (this.config && this.config.defaultAmountUsd) this.selectedAmount = this.config.defaultAmountUsd;\n this.tryAutoConnectPNP();\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n if (this.config?.defaultSymbol) this.selectedSymbol = this.config.defaultSymbol;\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n // Resume the original action after external wallet connected\n setTimeout(() => { if (action === 'tip') this.tip(); }, 0);\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'tip';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.selectedAmount || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'tip', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) {\n // Skip in SSR or if config not set yet\n return;\n }\n\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map(ledger => ({\n symbol: ledger.symbol,\n label: ledger.name,\n canisterId: ledger.canisterId\n }));\n // If user provided a single cryptoOption, auto-select regardless of dropdown mode\n if (this.config?.cryptoOptions && this.config.cryptoOptions.length === 1) {\n this.selectedSymbol = this.config.cryptoOptions[0].symbol;\n }\n // Set default selection to provided defaultSymbol, else first available\n if (!this.selectedSymbol && this.availableLedgers.length > 0) {\n this.selectedSymbol = this.config?.defaultSymbol || this.availableLedgers[0].symbol;\n }\n } catch (error) {\n console.warn('Failed to load verified ledgers:', error);\n // Fallback to basic options if API fails\n this.availableLedgers = [ { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' } ];\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n }\n\n private selectAmount(v: number) { this.selectedAmount = v; }\n private selectSymbol(s: string) { this.selectedSymbol = s; }\n\n private get fillPercentage() {\n const max = 50; // visual cap\n return Math.min((this.total / max) * 100, 100);\n }\n\n private async tip() {\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Tip button clicked!', { config: this.config, processing: this.processing });\n if (this.processing) return;\n\n // Clear previous errors\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'tip', type: 'sendUsd', amount: this.selectedAmount, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Check wallet connection status first\n if (this.config.useOwnWallet) {\n // External wallet handling - always require explicit connect before pay\n if (!this.config.actorProvider) {\n this.pendingAction = 'tip';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return;\n }\n } else {\n // Built-in wallet handling - connect directly with Plug N Play\n if (!this.walletConnected) {\n debugLog(this.config?.debug || false, 'Connecting to wallet via Plug N Play');\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _cfg2: any = wantsOisyTab ? applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) }) : ({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg2.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg2);\n try {\n const principal = await detectOisySessionViaAdapter(this.pnp);\n if (principal) {\n this.walletConnected = true;\n const normalized = normalizeConnectedWallet(this.pnp, { owner: principal, principal, connected: true });\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n this.tip();\n return;\n }\n } catch {}\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'tip';\n this.showWalletModal = true;\n return;\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error:', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return;\n }\n }\n }\n\n // Wallet is connected, proceed with payment\n debugLog(this.config?.debug || false, 'Creating SDK for payment');\n const sdk = createSdk(this.config);\n\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n\n debugLog(this.config?.debug || false, 'Tip payment details', {\n amount: this.selectedAmount,\n selectedSymbol: symbol,\n canisterId\n });\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(this.selectedAmount, canisterId, { context: 'tip-jar' });\n debugLog(this.config?.debug || false, 'Tip payment completed', { resp });\n\n this.total += this.selectedAmount;\n this.succeeded = true;\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status, total: this.total });\n this.dispatchEvent(new CustomEvent('icpay-tip', { detail: { amount: this.selectedAmount, tx: resp }, bubbles: true }));\n } catch (e) {\n // Handle errors using the new error handling system\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n\n // Update UI error state if error should be shown to user\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await (sdk as any).startOnrampUsd(this.selectedAmount, canisterId, { context: 'tip:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'tip') setTimeout(() => this.tip(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n render() {\n if (!this.config) {\n return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n }\n\n // Determine token selector visibility/mode using new string-based setting\n const optionsCount = this.cryptoOptions?.length || 0;\n const hasMultiple = optionsCount > 1;\n const rawMode = (this.config?.showLedgerDropdown as any) as ('buttons'|'dropdown'|'none'|undefined);\n const globalMode: 'buttons'|'dropdown'|'none' = rawMode === 'dropdown' ? 'dropdown' : rawMode === 'none' ? 'none' : 'buttons';\n const showSelector = (globalMode !== 'none') && (hasMultiple || globalMode === 'dropdown');\n const tokenSelectorMode: 'buttons'|'dropdown'|'none' = globalMode === 'dropdown' ? 'dropdown' : (hasMultiple ? 'buttons' : 'none');\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\" style=\"text-align:center;\">\n ${this.config?.progressBar?.enabled !== false ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.selectedAmount || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n <div class=\"jar\"><div class=\"fill\" style=\"height:${this.fillPercentage}%\"></div></div>\n <div class=\"label\">Total Tips: $${this.total}</div>\n\n <div class=\"amounts\">\n ${this.amounts.map(a => html`<div class=\"chip ${this.selectedAmount===a?'selected':''}\" @click=${() => this.selectAmount(a)}>$${a}</div>`)}\n </div>\n\n ${showSelector ? html`\n <div>\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${tokenSelectorMode}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n </div>\n ` : null}\n\n <button class=\"pay-button ${this.processing?'processing':''}\"\n ?disabled=${this.processing || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)}\n @click=${() => this.tip()}>\n ${this.succeeded && this.config?.disableAfterSuccess ? 'Paid' : (this.processing ? 'Processing…' : (this.config?.buttonLabel\n ? this.config.buttonLabel.replace('{amount}', String(this.selectedAmount)).replace('{symbol}', (this.selectedSymbol || this.config?.defaultSymbol || 'ICP'))\n : `Tip $${this.selectedAmount} with ${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}`))}\n </button>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`\n <button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">\n ${this.errorAction}\n </button>\n ` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: (this.config?.onramp?.enabled !== false) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false),\n creditCardTooltip: (() => {\n const min = 5; const amt = Number(this.selectedAmount || this.config?.defaultAmountUsd || 0); if (amt > 0 && amt < min && (this.config?.onramp?.enabled !== false)) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.tip(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-tip-jar': ICPayTipJar } }\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { ArticlePaywallConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Plug N Play will be imported dynamically when needed\nlet PlugNPlay: any = null;\n\n// Debug logger utility for widget components\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-article-paywall')\nexport class ICPayArticlePaywall extends LitElement {\n static styles = [baseStyles, css`\n .container { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 16px; padding: 16px; margin-bottom: 16px; }\n .title { color: var(--icpay-text); font-weight: 700; margin-bottom: 8px; }\n .preview { color: var(--icpay-muted); margin-bottom: 12px; line-height: 1.6; }\n .locked { filter: blur(3px); color: #6b7280; margin-bottom: 12px; }\n .unlocked { filter: blur(0); color: var(--icpay-text); }\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }\n .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }\n .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n\n .error-message {\n border: 1px solid;\n font-weight: 500;\n }\n\n .error-message.info {\n background: rgba(59, 130, 246, 0.1);\n border-color: rgba(59, 130, 246, 0.3);\n color: #3b82f6;\n }\n\n .error-message.warning {\n background: rgba(245, 158, 11, 0.1);\n border-color: rgba(245, 158, 11, 0.3);\n color: #f59e0b;\n }\n\n .error-message.error {\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n color: #ef4444;\n }\n `];\n\n @property({ type: Object }) config!: ArticlePaywallConfig;\n @property({ type: String }) title: string = 'Article Title';\n @property({ type: String }) preview: string = '';\n @property({ type: String }) lockedContent: string = '';\n private get obfuscatedLockedContent(): string {\n try {\n const s = this.lockedContent || '';\n // Replace all non-whitespace characters with 'x' to avoid leaking content\n return s.replace(/[^\\s]/g, 'x');\n } catch {\n return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';\n }\n }\n @state() private selectedSymbol: string | null = null;\n @state() private unlocked = false;\n @state() private succeeded = false;\n @state() private processing = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'unlock' | null = null;\n @state() private showWalletModal = false;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n private async tryAutoConnectPNP() {\n try {\n if (!this.config || this.config?.useOwnWallet) return;\n const raw = localStorage.getItem('icpay:pnp');\n if (!raw) return;\n const saved = JSON.parse(raw);\n if (!saved?.provider || !saved?.principal) return;\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n const _cfg1: any = { ...(this.config?.plugNPlay || {}) };\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg1.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n const pnp = new PlugNPlay(_cfg1);\n // Hydrate saved principal for UI/history; require connect on pay\n this.walletConnected = false;\n this.config = {\n ...this.config,\n connectedWallet: { owner: saved.principal, principal: saved.principal, connected: false } as any\n };\n } catch {}\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await (sdk as any).startOnrampUsd(this.config.priceUsd, canisterId, { context: 'article:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private get cryptoOptions(): CryptoOption[] {\n // If config provides cryptoOptions, use those (allows override)\n if (this.config.cryptoOptions) {\n return this.config.cryptoOptions;\n }\n // Otherwise use fetched verified ledgers\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Article paywall connected', { config: this.config });\n\n // Apply config-driven content if provided\n if (this.config) {\n if (typeof (this.config as any).title === 'string') this.title = (this.config as any).title;\n if (typeof (this.config as any).preview === 'string') this.preview = (this.config as any).preview;\n if (typeof (this.config as any).lockedContent === 'string') this.lockedContent = (this.config as any).lockedContent;\n }\n\n this.tryAutoConnectPNP();\n // Listen for switch-account request\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config')) {\n // Re-apply content on config update\n if (this.config) {\n if (typeof (this.config as any).title === 'string') this.title = (this.config as any).title;\n if (typeof (this.config as any).preview === 'string') this.preview = (this.config as any).preview;\n if (typeof (this.config as any).lockedContent === 'string') this.lockedContent = (this.config as any).lockedContent;\n }\n }\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'unlock') this.unlock(); }, 0);\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n // Prepare to restart flow after reconnect\n this.pendingAction = 'unlock';\n this.showWalletModal = true;\n this.requestUpdate();\n // Restart progress from step 0 for unlock\n try {\n const amount = Number(this.config?.priceUsd || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'unlock', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) {\n // Skip in SSR or if config not set yet\n return;\n }\n\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map(ledger => ({\n symbol: ledger.symbol,\n label: ledger.name,\n canisterId: ledger.canisterId\n }));\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol || 'ICP');\n }\n } catch (error) {\n console.warn('Failed to load verified ledgers:', error);\n // Fallback to basic options if API fails\n this.availableLedgers = [{ symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' }];\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n\n private selectSymbol(s: string) { this.selectedSymbol = s; }\n\n private async unlock() {\n if (!isBrowser) return; // Skip in SSR\n\n if (this.processing || this.unlocked) return;\n\n debugLog(this.config?.debug || false, 'Article paywall unlock started', {\n priceUsd: this.config.priceUsd,\n selectedSymbol: this.selectedSymbol,\n useOwnWallet: this.config.useOwnWallet\n });\n\n // Clear previous errors\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'unlock', type: 'sendUsd', amount: this.config.priceUsd, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Check wallet connection status first\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'unlock';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return;\n }\n } else {\n // Built-in wallet handling - connect directly with Plug N Play\n if (!this.walletConnected) {\n debugLog(this.config?.debug || false, 'Connecting to wallet via Plug N Play');\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _cfg2: any = wantsOisyTab ? applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) }) : ({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg2.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg2);\n try {\n const principal = await detectOisySessionViaAdapter(this.pnp);\n if (principal) {\n this.walletConnected = true;\n const normalized = normalizeConnectedWallet(this.pnp, { owner: principal, principal, connected: true });\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n this.unlock();\n return;\n }\n } catch {}\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'unlock';\n this.showWalletModal = true;\n return;\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error:', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return;\n }\n }\n }\n\n // Wallet is connected, proceed with payment\n debugLog(this.config?.debug || false, 'Creating SDK for payment');\n const sdk = createSdk(this.config);\n\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await (sdk.client.getLedgerCanisterIdBySymbol(symbol as string));\n\n debugLog(this.config?.debug || false, 'Article payment details', {\n priceUsd: this.config.priceUsd,\n selectedSymbol: symbol,\n canisterId\n });\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(this.config.priceUsd, canisterId, { context: 'article' });\n debugLog(this.config?.debug || false, 'Article payment completed', { resp });\n\n this.unlocked = true;\n this.succeeded = true;\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status });\n this.dispatchEvent(new CustomEvent('icpay-unlock', { detail: { amount: this.config.priceUsd, tx: resp }, bubbles: true }));\n } catch (e) {\n // Handle errors using the new error handling system\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n\n // Update UI error state if error should be shown to user\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'unlock') setTimeout(() => this.unlock(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n render() {\n if (!this.config) {\n return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n }\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\">\n ${this.config?.progressBar?.enabled !== false ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.config?.priceUsd || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n <div class=\"container\">\n <div class=\"title\">${this.title}</div>\n <div class=\"preview\">${this.preview}</div>\n <div class=\"${this.unlocked ? 'unlocked' : 'locked'}\">${this.unlocked ? this.lockedContent : this.obfuscatedLockedContent}</div>\n </div>\n <div>\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${(this.config?.showLedgerDropdown || 'buttons')}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n </div>\n <button class=\"pay-button ${this.processing?'processing':''}\" ?disabled=${this.processing||this.unlocked || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)} @click=${() => this.unlock()}>\n ${this.unlocked ? 'Unlocked' : (this.processing ? 'Processing…' : (\n (this.config?.buttonLabel || 'Pay ${amount} with {symbol}')\n .replace('{amount}', `${Number(this.config?.priceUsd ?? 0).toFixed(2)}`)\n .replace('{symbol}', (this.selectedSymbol || this.config?.defaultSymbol || 'ICP'))\n ))}\n </button>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`\n <button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">\n ${this.errorAction}\n </button>\n ` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true)) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true),\n creditCardTooltip: (() => {\n const min = 5; const amt = Number(this.config?.priceUsd || 0); if (amt > 0 && amt < min && ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true))) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.unlock(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-article-paywall': ICPayArticlePaywall } }\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { CoffeeShopConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Plug N Play will be imported dynamically when needed\nlet PlugNPlay: any = null;\n\n// Debug logger utility for widget components\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-coffee-shop')\nexport class ICPayCoffeeShop extends LitElement {\n static styles = [baseStyles, css`\n .menu { display: grid; gap: 8px; margin-bottom: 12px; }\n .item { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 16px; display:flex; justify-content: space-between; align-items:center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }\n .item.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n .total { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; margin-bottom: 12px; color: var(--icpay-text); }\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }\n .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }\n .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n\n .error-message {\n border: 1px solid;\n font-weight: 500;\n }\n\n .error-message.info {\n background: rgba(59, 130, 246, 0.1);\n border-color: rgba(59, 130, 246, 0.3);\n color: #3b82f6;\n }\n\n .error-message.warning {\n background: rgba(245, 158, 11, 0.1);\n border-color: rgba(245, 158, 11, 0.3);\n color: #f59e0b;\n }\n\n .error-message.error {\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n color: #ef4444;\n }\n `];\n\n @property({ type: Object }) config!: CoffeeShopConfig;\n @state() private selectedIndex = 0;\n @state() private selectedSymbol: string | null = null;\n @state() private processing = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'order' | null = null;\n @state() private showWalletModal = false;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n\n private get cryptoOptions(): CryptoOption[] {\n // If config provides cryptoOptions, use those (allows override)\n if (this.config.cryptoOptions) {\n return this.config.cryptoOptions;\n }\n // Otherwise use fetched verified ledgers\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Coffee shop connected', { config: this.config });\n\n if (this.config && typeof this.config.defaultItemIndex === 'number') this.selectedIndex = this.config.defaultItemIndex;\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'order') this.order(); }, 0);\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'order';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.selectedItem?.priceUsd || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'order', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) {\n // Skip in SSR or if config not set yet\n return;\n }\n\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map(ledger => ({\n symbol: ledger.symbol,\n label: ledger.name,\n canisterId: ledger.canisterId\n }));\n // Set default selection to defaultSymbol or first available ledger\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol || 'ICP');\n }\n } catch (error) {\n console.warn('Failed to load verified ledgers:', error);\n // Fallback to basic options if API fails\n this.availableLedgers = [\n { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' }\n ];\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n }\n\n private selectItem(i: number) { this.selectedIndex = i; }\n private selectSymbol(s: string) { this.selectedSymbol = s; }\n\n private get selectedItem() { return this.config?.items?.[this.selectedIndex] || { name: 'Loading...', priceUsd: 0 }; }\n\n private async order() {\n if (!isBrowser) return; // Skip in SSR\n\n if (this.processing) return;\n\n debugLog(this.config?.debug || false, 'Coffee order started', {\n selectedItem: this.selectedItem,\n selectedSymbol: this.selectedSymbol,\n useOwnWallet: this.config.useOwnWallet\n });\n\n // Clear previous errors\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'order', type: 'sendUsd', amount: this.selectedItem.priceUsd, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Check wallet connection status first\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'order';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return;\n }\n } else {\n // Built-in wallet handling - connect directly with Plug N Play\n if (!this.walletConnected) {\n debugLog(this.config?.debug || false, 'Connecting to wallet via Plug N Play');\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _cfg: any = wantsOisyTab ? applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) }) : ({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg);\n try {\n const principal = await detectOisySessionViaAdapter(this.pnp);\n if (principal) {\n this.walletConnected = true;\n const normalized = normalizeConnectedWallet(this.pnp, { owner: principal, principal, connected: true });\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n this.order();\n return;\n }\n } catch {}\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'order';\n this.showWalletModal = true;\n return;\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error:', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return;\n }\n }\n }\n\n // Wallet is connected, proceed with payment\n debugLog(this.config?.debug || false, 'Creating SDK for payment');\n const sdk = createSdk(this.config);\n\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n\n debugLog(this.config?.debug || false, 'Coffee order payment details', {\n item: this.selectedItem.name,\n priceUsd: this.selectedItem.priceUsd,\n selectedSymbol: symbol,\n canisterId\n });\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(this.selectedItem.priceUsd, canisterId, { context: 'coffee', item: this.selectedItem.name });\n debugLog(this.config?.debug || false, 'Coffee order payment completed', { resp });\n\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status, item: this.selectedItem.name });\n this.dispatchEvent(new CustomEvent('icpay-coffee', { detail: { item: this.selectedItem, tx: resp }, bubbles: true }));\n } catch (e) {\n // Handle errors using the new error handling system\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n\n // Update UI error state if error should be shown to user\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await (sdk as any).startOnrampUsd(this.selectedItem.priceUsd, canisterId, { context: 'coffee:onramp', item: this.selectedItem.name });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'order') setTimeout(() => this.order(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n render() {\n if (!this.config) {\n return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n }\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\">\n ${this.config?.progressBar?.enabled !== false ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.selectedItem?.priceUsd || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n <div class=\"menu\">\n ${this.config.items.map((it, i) => html`\n <div class=\"item ${this.selectedIndex===i?'selected':''}\" @click=${() => this.selectItem(i)}>\n <span>${it.name}</span>\n <span>$${Number(it?.priceUsd ?? 0).toFixed(2)}</span>\n </div>\n `)}\n </div>\n\n <div class=\"total\">Order Total: $${Number(this.selectedItem?.priceUsd ?? 0).toFixed(2)}</div>\n\n <div>\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${(this.config?.showLedgerDropdown || 'buttons')}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n </div>\n\n <button class=\"pay-button ${this.processing?'processing':''}\" ?disabled=${this.processing} @click=${() => this.order()}>\n ${this.processing ? 'Processing…' : `Order ${this.selectedItem.name}`}\n </button>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`\n <button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">\n ${this.errorAction}\n </button>\n ` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true)) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true),\n creditCardTooltip: (() => {\n const min = 5; const i = this.config?.defaultItemIndex ?? 0; const amt = Number((this.config?.items?.[i]?.priceUsd) || 0); if (amt > 0 && amt < min && ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true))) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.order(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-coffee-shop': ICPayCoffeeShop } }\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { DonationThermometerConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\n// Check if we're in a browser environment\nconst isBrowser = typeof window !== 'undefined';\n\n// Plug N Play will be imported dynamically when needed\nlet PlugNPlay: any = null;\n\n// Debug logger utility for widget components\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-donation-thermometer')\nexport class ICPayDonationThermometer extends LitElement {\n static styles = [baseStyles, css`\n .thermo { width: 60px; height: 200px; background: var(--icpay-surface-alt); border: 3px solid #6b7280; border-radius: 30px; margin: 0 auto 12px; position: relative; overflow: hidden; }\n .fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); transition: height 0.8s ease; height: 0%; border-radius: 0 0 27px 27px; }\n .amounts { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 12px 0; }\n .chip { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; }\n .chip.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n .crypto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }\n .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }\n .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }\n\n .error-message {\n border: 1px solid;\n font-weight: 500;\n }\n\n .error-message.info {\n background: rgba(59, 130, 246, 0.1);\n border-color: rgba(59, 130, 246, 0.3);\n color: #3b82f6;\n }\n\n .error-message.warning {\n background: rgba(245, 158, 11, 0.1);\n border-color: rgba(245, 158, 11, 0.3);\n color: #f59e0b;\n }\n\n .error-message.error {\n background: rgba(239, 68, 68, 0.1);\n border-color: rgba(239, 68, 68, 0.3);\n color: #ef4444;\n }\n `];\n\n @property({ type: Object }) config!: DonationThermometerConfig;\n @state() private selectedAmount = 10;\n @state() private selectedSymbol: string | null = null;\n @state() private raised = 0;\n @state() private processing = false;\n @state() private succeeded = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'donate' | null = null;\n @state() private showWalletModal = false;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n private async tryAutoConnectPNP() {\n try {\n if (!this.config || this.config?.useOwnWallet) return;\n const raw = localStorage.getItem('icpay:pnp');\n if (!raw) return;\n const saved = JSON.parse(raw);\n if (!saved?.provider || !saved?.principal) return;\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n const _cfg1: any = applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg1.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n const pnp = new PlugNPlay(_cfg1);\n // Hydrate saved principal for UI/history; require connect on pay\n this.walletConnected = false;\n this.config = {\n ...this.config,\n connectedWallet: { owner: saved.principal, principal: saved.principal, connected: false } as any\n };\n } catch {}\n }\n\n private get amounts(): number[] {\n return this.config?.amountsUsd || [10, 25, 50, 100, 250, 500];\n }\n private get cryptoOptions(): CryptoOption[] {\n // If config provides cryptoOptions, use those (allows override)\n if (this.config.cryptoOptions) {\n return this.config.cryptoOptions;\n }\n // Otherwise use fetched verified ledgers\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return; // Skip in SSR\n\n debugLog(this.config?.debug || false, 'Donation thermometer connected', { config: this.config });\n\n if (this.config && typeof this.config.defaultAmountUsd === 'number') this.selectedAmount = this.config.defaultAmountUsd;\n this.tryAutoConnectPNP();\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'donate') this.donate(); }, 0);\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'donate';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.selectedAmount || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'donate', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) {\n // Skip in SSR or if config not set yet\n return;\n }\n\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map(ledger => ({\n symbol: ledger.symbol,\n label: ledger.name,\n canisterId: ledger.canisterId\n }));\n // Set default selection to defaultSymbol or first available ledger\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol || 'ICP');\n }\n } catch (error) {\n console.warn('Failed to load verified ledgers:', error);\n // Fallback to basic options if API fails\n this.availableLedgers = [\n { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' }\n ];\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n }\n\n private selectAmount(v: number) { this.selectedAmount = v; }\n private selectSymbol(s: string) { this.selectedSymbol = s; }\n\n private get fillPercentage() {\n const goal = Number(this.config?.goalUsd ?? 1000);\n const denom = goal > 0 ? goal : 1000;\n return Math.min((this.raised / denom) * 100, 100);\n }\n\n private async donate() {\n if (!isBrowser) return; // Skip in SSR\n\n if (this.processing) return;\n\n debugLog(this.config?.debug || false, 'Donation started', {\n amount: this.selectedAmount,\n selectedSymbol: this.selectedSymbol,\n useOwnWallet: this.config.useOwnWallet\n });\n\n // Clear previous errors\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'donate', type: 'sendUsd', amount: this.selectedAmount, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Check wallet connection status first\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'donate';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return;\n }\n } else {\n // Built-in wallet handling - connect directly with Plug N Play\n if (!this.walletConnected) {\n debugLog(this.config?.debug || false, 'Connecting to wallet via Plug N Play');\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _cfg2: any = wantsOisyTab ? applyOisyNewTabConfig({ ...(this.config?.plugNPlay || {}) }) : ({ ...(this.config?.plugNPlay || {}) });\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg2.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg2);\n try {\n const principal = await detectOisySessionViaAdapter(this.pnp);\n if (principal) {\n this.walletConnected = true;\n const normalized = normalizeConnectedWallet(this.pnp, { owner: principal, principal, connected: true });\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n this.donate();\n return;\n }\n } catch {}\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'donate';\n this.showWalletModal = true;\n return;\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error:', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return;\n }\n }\n }\n\n // Wallet is connected, proceed with payment\n debugLog(this.config?.debug || false, 'Creating SDK for payment');\n const sdk = createSdk(this.config);\n\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n\n debugLog(this.config?.debug || false, 'Donation payment details', {\n amount: this.selectedAmount,\n selectedSymbol: symbol,\n canisterId\n });\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(this.selectedAmount, canisterId, { context: 'donation' });\n debugLog(this.config?.debug || false, 'Donation payment completed', { resp });\n\n this.raised += this.selectedAmount;\n this.succeeded = true;\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status, raised: this.raised });\n this.dispatchEvent(new CustomEvent('icpay-donation', { detail: { amount: this.selectedAmount, tx: resp }, bubbles: true }));\n } catch (e) {\n // Handle errors using the new error handling system\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n\n // Update UI error state if error should be shown to user\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol)!;\n const canisterId = opt.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await (sdk as any).startOnrampUsd(this.selectedAmount, canisterId, { context: 'donation:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'donate') setTimeout(() => this.donate(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n render() {\n if (!this.config) {\n return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n }\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\" style=\"text-align:center;\">\n ${this.config?.progressBar?.enabled !== false ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.selectedAmount || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n <div class=\"thermo\"><div class=\"fill\" style=\"height:${this.fillPercentage}%\"></div></div>\n <div class=\"total\">$${Number(this.raised).toFixed(0)} / $${Number(this.config?.goalUsd ?? 0).toFixed(2)}</div>\n\n <div class=\"amounts\">\n ${this.amounts.map(a => html`<div class=\"chip ${this.selectedAmount===a?'selected':''}\" @click=${() => this.selectAmount(a)}>$${a}</div>`)}\n </div>\n\n <div>\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${(this.config?.showLedgerDropdown || 'buttons')}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n </div>\n\n <button class=\"pay-button ${this.processing?'processing':''}\"\n ?disabled=${this.processing || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)}\n @click=${() => this.donate()}>\n ${this.succeeded && this.config?.disableAfterSuccess ? 'Donated' : (this.processing ? 'Processing…' : (\n (this.config?.buttonLabel || 'Donate {amount} with {symbol}')\n .replace('{amount}', `${this.selectedAmount}`)\n .replace('{symbol}', (this.selectedSymbol || this.config?.defaultSymbol || 'ICP'))\n ))}\n </button>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`\n <button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">\n ${this.errorAction}\n </button>\n ` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: (this.config?.onramp?.enabled !== false) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false),\n creditCardTooltip: (() => {\n const min = 5; const amt = Number(this.selectedAmount || this.config?.defaultAmountUsd || 0); if (amt > 0 && amt < min && (this.config?.onramp?.enabled !== false)) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.donate(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-donation-thermometer': ICPayDonationThermometer } }\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { PayButtonConfig, CryptoOption } from '../types';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { createSdk } from '../utils/sdk';\nimport type { WidgetSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\nconst isBrowser = typeof window !== 'undefined';\nlet PlugNPlay: any = null;\n\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-pay-button')\nexport class ICPayPayButton extends LitElement {\n static styles = [baseStyles, css`\n .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }\n .row.single { grid-template-columns: 1fr; }\n select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }\n .error-message { border: 1px solid; font-weight: 500; }\n .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }\n .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }\n .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }\n `];\n\n @property({ type: Object }) config!: PayButtonConfig;\n @state() private selectedSymbol: string | null = null;\n @state() private processing = false;\n @state() private succeeded = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'pay' | null = null;\n @state() private showWalletModal = false;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n @state() private oisyReadyToPay: boolean = false;\n @state() private oisySignerPreopened: boolean = false;\n @state() private skipDisconnectOnce: boolean = false;\n @state() private lastWalletId: string | null = null;\n private onrampPollTimer: number | null = null;\n private transakMessageHandlerBound: any | null = null;\n private pnp: any | null = null;\n private oisyConnectRetriedNewTab: boolean = false;\n private sdk: WidgetSdk | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n\n private getSdk(): WidgetSdk {\n if (!this.sdk) {\n this.sdk = createSdk(this.config);\n }\n return this.sdk;\n }\n\n private get cryptoOptions(): CryptoOption[] {\n if (this.config?.cryptoOptions?.length) return this.config.cryptoOptions;\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return;\n debugLog(this.config?.debug || false, 'Pay button connected', { config: this.config });\n // Load ledgers by default when cryptoOptions not provided (widget should be self-sufficient)\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n // Initialize default symbol\n if (this.config?.defaultSymbol) this.selectedSymbol = this.config.defaultSymbol;\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n // Debug: observe SDK intent creation event\n try {\n window.addEventListener('icpay-sdk-transaction-created', ((e: any) => {\n debugLog(this.config?.debug || false, 'SDK transaction created', { detail: e?.detail });\n }) as EventListener);\n } catch {}\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config') && this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'pay') this.pay(); }, 0);\n }\n // No longer pull sessionId from config; it is obtained from SDK response\n if (changed.has('config')) {\n // Recreate SDK on config changes\n this.sdk = null;\n // Prefer defaultSymbol from config if selection not made yet\n if (!this.selectedSymbol && this.config?.defaultSymbol) {\n this.selectedSymbol = this.config.defaultSymbol;\n }\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.config?.amountUsd || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) return;\n try {\n const sdk = this.getSdk();\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map((ledger: any) => ({ symbol: ledger.symbol, label: ledger.name, canisterId: ledger.canisterId }));\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol ?? 'ICP');\n }\n } catch (error) {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: { message: 'Failed to load verified ledgers', cause: error }, bubbles: true }));\n this.availableLedgers = [ { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' } ];\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n\n private selectSymbol(symbol: string) { this.selectedSymbol = symbol; }\n\n private async ensureWallet(): Promise<boolean> {\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'pay';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return false;\n }\n return true;\n }\n\n if (this.walletConnected) return true;\n try {\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n // Optional: open Oisy in a new tab if explicitly enabled\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _rawCfg: any = { ...(this.config?.plugNPlay || {}) };\n const _cfg: any = wantsOisyTab ? applyOisyNewTabConfig(_rawCfg) : _rawCfg;\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg);\n const availableWallets = this.pnp.getEnabledWallets();\n debugLog(this.config?.debug || false, 'Available wallets', availableWallets);\n if (!availableWallets?.length) throw new Error('No wallets available');\n // Show chooser modal and resume later\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n return false;\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return false;\n }\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n if (this.lastWalletId === 'oisy') this.oisyConnectRetriedNewTab = false;\n // Minimal: connect immediately within click (no pre-open or detection)\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n debugLog(this.config?.debug || false, 'Wallet connect result', result);\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = (walletId || '').toLowerCase() === 'oisy';\n if (isOisy) {\n // Stay in modal and show a single CTA to execute the transfer from a user gesture\n this.oisyReadyToPay = true;\n // Prevent auto-pay via updated() resume logic\n this.pendingAction = null;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'pay') { this.skipDisconnectOnce = true; this.pay(); }\n }\n }).catch((error: any) => {\n debugLog(this.config?.debug || false, 'Wallet connection error', error);\n const isOisy = (walletId || '').toLowerCase() === 'oisy';\n const message = (error && (error.message || String(error))) || '';\n const blocked = isOisy && (!this.oisyConnectRetriedNewTab) && (message.includes('Signer window could not be opened') || message.includes('Communication channel could not be established'));\n if (blocked) {\n // Retry Oisy connect by forcing new-tab transport\n this.oisyConnectRetriedNewTab = true;\n (async () => {\n try {\n if (!PlugNPlay) { const module = await import('../wallet-select'); PlugNPlay = module.WalletSelect; }\n const raw: any = { ...(this.config?.plugNPlay || {}) };\n const cfg: any = applyOisyNewTabConfig(raw);\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n cfg.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(cfg);\n const retry = this.pnp.connect('oisy');\n retry.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'oisy' } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n this.oisyReadyToPay = true;\n this.pendingAction = null;\n }).catch((err2: any) => {\n debugLog(this.config?.debug || false, 'Oisy retry connect (new tab) failed', err2);\n this.errorMessage = err2 instanceof Error ? err2.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (initErr) {\n debugLog(this.config?.debug || false, 'Oisy new-tab init failed', initErr);\n this.errorMessage = initErr instanceof Error ? initErr.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n })();\n return;\n }\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n debugLog(this.config?.debug || false, 'Wallet connection error (sync)', error);\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n private renderWalletModal() {\n if (!this.showWalletModal || !this.pnp) return null as any;\n const walletsRaw = this.pnp.getEnabledWallets() || [];\n const wallets = walletsRaw.map((w: any) => ({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n const onrampEnabled = (this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true);\n const minOnramp = 5;\n const amountUsd = Number(this.config?.amountUsd ?? 0);\n const showTooltip = onrampEnabled && amountUsd > 0 && amountUsd < minOnramp;\n const diff = Math.max(0, minOnramp - amountUsd);\n const tooltip = showTooltip ? `Note: Minimum card amount is $${minOnramp}. You will pay about $${diff.toFixed(2)} more.` : null;\n return renderWalletSelectorModal({\n visible: this.showWalletModal,\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => {\n // Ensure any signer window/channel establishment happens directly in this click handler\n this.connectWithWallet(walletId);\n },\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: onrampEnabled ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: onrampEnabled,\n creditCardTooltip: tooltip,\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => {\n this.showWalletModal = false; // Close modal so progress bar can proceed\n this.skipDisconnectOnce = true;\n this.oisyReadyToPay = false;\n this.pay(); // Trigger pay within same user gesture\n }\n });\n }\n\n private startOnramp() {\n // Signal to progress bar that onramp flow is starting\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n // Kick off onramp intent creation through SDK and open Transak with returned sessionId\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const amountUsd = Number(this.config?.amountUsd ?? 0);\n const sdk = this.getSdk();\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n const symbol = this.selectedSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol);\n const canisterId = opt?.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const resp = await sdk.startOnrampUsd(amountUsd, canisterId, { context: 'pay-button:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampErrorMessage = errorMessage || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n // Open modal in friendly error state (sessionId missing)\n this.onrampSessionId = null;\n this.showOnrampModal = true;\n }\n } catch (e) {\n // Also show friendly error modal on any error\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || null;\n this.showOnrampModal = true;\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n\n // Only react to Transak order success\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n // Prevent multiple pollers if provider emits duplicates\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n // Complete steps up to verify and set confirm to loading by emitting method success events the progress bar understands\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-success', { detail: { name: 'getLedgerBalance' } })); } catch {}\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-success', { detail: { name: 'sendFundsToLedger' } })); } catch {}\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-success', { detail: { name: 'notifyLedgerTransaction' } })); } catch {}\n\n // Close Transak modal upon success, continue with our own progress\n this.showOnrampModal = false;\n\n // Start polling our API for intent status\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n // Clear any previous polling\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n\n const sdk = this.getSdk();\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n // Also listen to completion event to tidy up\n const listener = (e: any) => { handleComplete(); };\n try { window.addEventListener('icpay-sdk-transaction-completed', listener as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = sdk.notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n // Store a no-op timer id placeholder so our cleanup path remains intact\n this.onrampPollTimer = 1 as any;\n }\n\n private async pay() {\n if (!isBrowser || this.processing) return;\n\n // Reset error state\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n // Emit method start to open progress modal and set first step\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount: this.config?.amountUsd, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n // Disconnect current built-in wallet before new payment attempt unless we just connected\n if (!this.skipDisconnectOnce) {\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } else {\n this.skipDisconnectOnce = false;\n }\n const ready = await this.ensureWallet();\n if (!ready) return;\n\n const sdk = this.getSdk();\n // Debug: snapshot wallet state before resolving canister and sending\n try {\n const cw = (this.config as any)?.connectedWallet;\n const pnpAcct = (this as any)?.pnp?.account;\n debugLog(this.config?.debug || false, 'Wallet state before payment', {\n connectedWallet: cw,\n pnpAccount: pnpAcct,\n principal: (cw?.owner || cw?.principal || pnpAcct?.owner || pnpAcct?.principal || null)\n });\n } catch {}\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n const symbol = this.selectedSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol);\n const canisterId = opt?.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n debugLog(this.config?.debug || false, 'Resolved ledger details', { symbol, canisterId });\n const amountUsd = Number(this.config?.amountUsd ?? 0);\n const meta = { context: 'pay-button' } as Record<string, any>;\n // Do not pre-open Oisy signer tab; SDK will open it within this user gesture\n debugLog(this.config?.debug || false, 'Calling sdk.sendUsd', { amountUsd, canisterId, meta });\n const resp = await sdk.sendUsd(amountUsd, canisterId, meta);\n debugLog(this.config?.debug || false, 'sdk.sendUsd response', resp);\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status });\n this.succeeded = true;\n this.dispatchEvent(new CustomEvent('icpay-pay', { detail: { amount: amountUsd, tx: resp }, bubbles: true }));\n } catch (e) {\n debugLog(this.config?.debug || false, 'Payment error', {\n message: (e as any)?.message,\n code: (e as any)?.code,\n details: (e as any)?.details,\n stack: (e as any)?.stack\n });\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n render() {\n if (!this.config) return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n\n const optionsCount = this.cryptoOptions?.length || 0;\n const hasMultiple = optionsCount > 1;\n const rawMode = (this.config?.showLedgerDropdown as any) as ('buttons'|'dropdown'|'none'|undefined);\n const globalMode: 'buttons'|'dropdown'|'none' = rawMode === 'dropdown' ? 'dropdown' : rawMode === 'none' ? 'none' : 'buttons';\n const showSelector = (globalMode !== 'none') && (hasMultiple || globalMode === 'dropdown');\n const tokenSelectorMode: 'buttons'|'dropdown'|'none' = globalMode === 'dropdown' ? 'dropdown' : (hasMultiple ? 'buttons' : 'none');\n const selectedSymbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const amountPart = typeof this.config?.amountUsd === 'number' ? `${Number(this.config.amountUsd).toFixed(2)}` : '';\n const rawLabel = this.config?.buttonLabel || (typeof this.config?.amountUsd === 'number' ? 'Pay ${amount} with {symbol}' : 'Pay with {symbol}');\n const label = rawLabel.replace('{amount}', amountPart || '$0.00').replace('{symbol}', selectedSymbol);\n const progressEnabled = this.config?.progressBar?.enabled !== false;\n const showProgressBar = progressEnabled;\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\">\n ${showProgressBar ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.config?.amountUsd || 0)}\n .ledgerSymbol=${selectedSymbol}\n ></icpay-progress-bar>\n ` : null}\n\n <div class=\"row ${showSelector ? '' : 'single'}\">\n ${showSelector ? html`\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${tokenSelectorMode}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n ` : null}\n <button class=\"pay-button ${this.processing?'processing':''}\"\n ?disabled=${this.processing || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)}\n @click=${() => this.pay()}>\n ${this.succeeded && this.config?.disableAfterSuccess ? 'Paid' : (this.processing ? 'Processing…' : label)}\n </button>\n </div>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`<button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">${this.errorAction}</button>` : ''}\n </div>\n ` : ''}\n ${this.renderWalletModal()}\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n apiUrl: this.config?.apiUrl,\n paymentIntentId: this.onrampPaymentIntentId,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-pay-button': ICPayPayButton } }\n\n\n","import { LitElement, html, css } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { baseStyles } from '../styles';\nimport { handleWidgetError, getErrorMessage, shouldShowErrorToUser, getErrorAction, getErrorSeverity, ErrorSeverity } from '../error-handling';\nimport type { AmountInputConfig, CryptoOption } from '../types';\nimport { createSdk } from '../utils/sdk';\nimport './progress-bar';\nimport './token-selector';\nimport { renderWalletSelectorModal } from './wallet-selector-modal';\nimport { renderTransakOnrampModal, TransakOnrampOptions } from './transak-onramp-modal';\nimport { applyOisyNewTabConfig, normalizeConnectedWallet, detectOisySessionViaAdapter } from '../utils/pnp';\n\nconst isBrowser = typeof window !== 'undefined';\nlet PlugNPlay: any = null;\n\nfunction debugLog(debug: boolean, message: string, data?: any): void {\n if (debug) {\n if (data !== undefined) {\n console.log(`[ICPay Widget] ${message}`, data);\n } else {\n console.log(`[ICPay Widget] ${message}`);\n }\n }\n}\n\n@customElement('icpay-amount-input')\nexport class ICPayAmountInput extends LitElement {\n static styles = [baseStyles, css`\n .row { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }\n .top-row { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: center; }\n .top-row.with-selector { grid-template-columns: 1fr 2fr; }\n icpay-token-selector { width: 100%; }\n .amount-field { position: relative; width: 100%; }\n .amount-field .currency-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--icpay-muted, #a3a3a3); font-weight: 600; pointer-events: none; z-index: 2; }\n .amount-field input[type=\"number\"] { padding-left: 32px; position: relative; z-index: 1; }\n input[type=\"number\"] { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; width: 100%; box-sizing: border-box; height: 54px; }\n select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }\n .pay-button { width: 100%; }\n .error-message { border: 1px solid; font-weight: 500; }\n .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }\n .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }\n .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }\n .hint { font-size: 12px; color: var(--icpay-muted); margin-top: 6px; }\n\n @media (max-width: 520px) {\n .top-row { grid-template-columns: 1fr; }\n }\n `];\n\n @property({ type: Object }) config!: AmountInputConfig;\n @state() private amountUsd: number = 0;\n @state() private hasUserAmount: boolean = false;\n @state() private selectedSymbol: string | null = null;\n @state() private processing = false;\n @state() private succeeded = false;\n @state() private availableLedgers: CryptoOption[] = [];\n @state() private errorMessage: string | null = null;\n @state() private errorSeverity: ErrorSeverity | null = null;\n @state() private errorAction: string | null = null;\n @state() private walletConnected = false;\n @state() private pendingAction: 'pay' | null = null;\n @state() private showWalletModal = false;\n @state() private showOnrampModal = false;\n @state() private onrampSessionId: string | null = null;\n @state() private onrampPaymentIntentId: string | null = null;\n @state() private onrampErrorMessage: string | null = null;\n @state() private oisyReadyToPay: boolean = false;\n @state() private lastWalletId: string | null = null;\n private pnp: any | null = null;\n private transakMessageHandlerBound: any | null = null;\n private onrampPollTimer: number | null = null;\n private onrampPollingActive: boolean = false;\n private onrampNotifyController: { stop: () => void } | null = null;\n\n private get cryptoOptions(): CryptoOption[] {\n if (this.config?.cryptoOptions?.length) return this.config.cryptoOptions;\n return this.availableLedgers;\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n if (!isBrowser) return;\n debugLog(this.config?.debug || false, 'Amount input connected', { config: this.config });\n this.amountUsd = Number(this.config?.defaultAmountUsd ?? 0);\n this.hasUserAmount = false;\n // Always fetch verified ledgers by default when cryptoOptions not provided\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0)) {\n this.loadVerifiedLedgers();\n }\n if (this.config?.defaultSymbol) this.selectedSymbol = this.config.defaultSymbol;\n try { window.addEventListener('icpay-switch-account', this.onSwitchAccount as EventListener); } catch {}\n }\n\n protected updated(changed: Map<string, unknown>): void {\n if (changed.has('config')) {\n // Apply defaults only if user hasn't edited the amount\n if (!this.hasUserAmount && typeof this.config?.defaultAmountUsd === 'number') {\n if (this.amountUsd === 0 || this.amountUsd == null || Number.isNaN(this.amountUsd)) {\n this.amountUsd = Number(this.config.defaultAmountUsd);\n }\n }\n if (!this.selectedSymbol && this.config?.defaultSymbol) {\n this.selectedSymbol = this.config.defaultSymbol;\n }\n\n // Ensure ledgers are loaded if dropdown is enabled and no options provided\n if (!(this.config?.cryptoOptions && this.config.cryptoOptions.length > 0) && this.availableLedgers.length === 0) {\n this.loadVerifiedLedgers();\n }\n\n // If we were waiting on wallet connect, resume action\n if (this.pendingAction && this.config?.actorProvider) {\n const action = this.pendingAction;\n this.pendingAction = null;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: 'external' } })); } catch {}\n setTimeout(() => { if (action === 'pay') this.pay(); }, 0);\n }\n }\n }\n\n private onSwitchAccount = async (e: any) => {\n try {\n if (this.pnp) {\n try { await this.pnp.disconnect(); } catch {}\n }\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n this.requestUpdate();\n try {\n const amount = Number(this.amountUsd || 0);\n const curr = this.selectedSymbol || this.config?.defaultSymbol;\n window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount, currency: curr } }));\n } catch {}\n } catch {}\n };\n\n private async loadVerifiedLedgers() {\n if (!isBrowser || !this.config?.publishableKey) return;\n try {\n const sdk = createSdk(this.config);\n const ledgers = await sdk.client.getVerifiedLedgers();\n this.availableLedgers = ledgers.map((ledger: any) => ({ symbol: ledger.symbol, label: ledger.name, canisterId: ledger.canisterId }));\n if (!this.selectedSymbol) {\n this.selectedSymbol = this.config?.defaultSymbol || (this.availableLedgers[0]?.symbol ?? 'ICP');\n }\n } catch (error) {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: { message: 'Failed to load verified ledgers', cause: error }, bubbles: true }));\n this.availableLedgers = [ { symbol: 'ICP', label: 'ICP', canisterId: 'ryjl3-tyaaa-aaaaa-aaaba-cai' } ];\n if (!this.selectedSymbol) this.selectedSymbol = this.config?.defaultSymbol || 'ICP';\n }\n }\n\n private onInputChange(e: any) {\n const step = Number(this.config?.stepUsd ?? 0.5);\n const value = Math.max(0, Number(e.target.value || 0));\n const rounded = Math.round(value / step) * step;\n this.amountUsd = Number(rounded.toFixed(2));\n this.hasUserAmount = true;\n }\n\n private selectSymbol(symbol: string) { this.selectedSymbol = symbol; }\n\n private isValidAmount(): boolean {\n const min = Number(this.config?.minUsd ?? 0.5);\n const max = this.config?.maxUsd !== undefined ? Number(this.config.maxUsd) : Infinity;\n return this.amountUsd >= min && this.amountUsd <= max;\n }\n\n private async ensureWallet(): Promise<boolean> {\n if (this.config.useOwnWallet) {\n if (!this.config.actorProvider) {\n this.pendingAction = 'pay';\n this.dispatchEvent(new CustomEvent('icpay-connect-wallet', { bubbles: true }));\n return false;\n }\n return true;\n }\n\n if (this.walletConnected) return true;\n try {\n if (!PlugNPlay) {\n const module = await import('../wallet-select');\n PlugNPlay = module.WalletSelect;\n }\n const wantsOisyTab = !!((this.config as any)?.openOisyInNewTab || (this.config as any)?.plugNPlay?.openOisyInNewTab);\n const _rawCfg: any = { ...(this.config?.plugNPlay || {}) };\n const _cfg: any = wantsOisyTab ? applyOisyNewTabConfig(_rawCfg) : _rawCfg;\n try {\n if (typeof window !== 'undefined') {\n const { resolveDerivationOrigin } = await import('../utils/origin');\n _cfg.derivationOrigin = this.config?.derivationOrigin || resolveDerivationOrigin();\n }\n } catch {}\n this.pnp = new PlugNPlay(_cfg);\n const availableWallets = this.pnp.getEnabledWallets();\n if (!availableWallets?.length) throw new Error('No wallets available');\n this.pendingAction = 'pay';\n this.showWalletModal = true;\n return false;\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n return false;\n }\n }\n\n private getWalletId(w: any): string { return (w && (w.id || w.provider || w.key)) || ''; }\n private getWalletLabel(w: any): string { return (w && (w.label || w.name || w.title || w.id)) || 'Wallet'; }\n private getWalletIcon(w: any): string | null { return (w && (w.icon || w.logo || w.image)) || null; }\n\n\n private connectWithWallet(walletId: string) {\n if (!this.pnp) return;\n try {\n if (!walletId) throw new Error('No wallet ID provided');\n this.lastWalletId = (walletId || '').toLowerCase();\n const promise = this.pnp.connect(walletId);\n promise.then((result: any) => {\n const isConnected = !!(result && (result.connected === true || (result as any).principal || (result as any).owner || this.pnp?.account));\n if (!isConnected) throw new Error('Wallet connection was rejected');\n this.walletConnected = true;\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-wallet-connected', { detail: { walletType: walletId } })); } catch {}\n const normalized = normalizeConnectedWallet(this.pnp, result);\n this.config = { ...this.config, connectedWallet: normalized, actorProvider: (canisterId: string, idl: any) => this.pnp!.getActor({ canisterId, idl, requiresSigning: true, anon: false }) };\n const isOisy = this.lastWalletId === 'oisy';\n if (isOisy) {\n // Keep modal open and show only the explicit CTA\n this.oisyReadyToPay = true;\n } else {\n this.showWalletModal = false;\n const action = this.pendingAction; this.pendingAction = null;\n if (action === 'pay') setTimeout(() => this.pay(), 0);\n }\n }).catch((error: any) => {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n });\n } catch (error) {\n this.errorMessage = error instanceof Error ? error.message : 'Wallet connection failed';\n this.errorSeverity = ErrorSeverity.ERROR;\n this.showWalletModal = false;\n }\n }\n\n private attachTransakMessageListener() {\n if (this.transakMessageHandlerBound) return;\n this.transakMessageHandlerBound = (event: MessageEvent) => this.onTransakMessage(event);\n try { window.addEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n }\n\n private detachTransakMessageListener() {\n if (this.transakMessageHandlerBound) {\n try { window.removeEventListener('message', this.transakMessageHandlerBound as any); } catch {}\n this.transakMessageHandlerBound = null;\n }\n }\n\n private onTransakMessage(event: MessageEvent) {\n const data: any = event?.data;\n const eventId: string | undefined = data?.event_id || data?.eventId || data?.id;\n if (!eventId || typeof eventId !== 'string') return;\n\n if (eventId === 'TRANSAK_ORDER_SUCCESSFUL') {\n this.detachTransakMessageListener();\n if (this.onrampPollingActive) return;\n // Close modal and start our own flow\n this.showOnrampModal = false;\n const orderId = (data?.data?.id) || (data?.id) || (data?.webhookData?.id) || null;\n this.startOnrampPolling(orderId || undefined);\n }\n }\n\n private startOnramp() {\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'createPaymentUsd', type: 'onramp' } })); } catch {}\n this.showWalletModal = false;\n setTimeout(() => this.createOnrampIntent(), 0);\n }\n\n private async createOnrampIntent() {\n try {\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol);\n const canisterId = opt?.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const amountUsd = Number(this.amountUsd);\n const resp = await (sdk as any).startOnrampUsd(amountUsd, canisterId, { context: 'amount-input:onramp' });\n const sessionId = resp?.metadata?.onramp?.sessionId || resp?.metadata?.onramp?.session_id || null;\n const paymentIntentId = resp?.metadata?.paymentIntentId || resp?.paymentIntentId || null;\n const errorMessage = resp?.metadata?.onramp?.errorMessage || null;\n this.onrampPaymentIntentId = paymentIntentId;\n if (sessionId) {\n this.onrampSessionId = sessionId;\n this.onrampErrorMessage = null;\n this.showOnrampModal = true;\n this.attachTransakMessageListener();\n } else {\n this.onrampSessionId = null;\n this.onrampErrorMessage = errorMessage || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n } catch (e) {\n this.onrampSessionId = null;\n this.onrampErrorMessage = (e as any)?.message || 'Failed to obtain onramp sessionId';\n this.showOnrampModal = true;\n }\n }\n\n private startOnrampPolling(orderId?: string) {\n if (this.onrampPollTimer) { try { clearInterval(this.onrampPollTimer); } catch {}; this.onrampPollTimer = null; }\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {}; this.onrampNotifyController = null; }\n\n const paymentIntentId = this.onrampPaymentIntentId;\n if (!paymentIntentId) return;\n\n const sdk = createSdk(this.config);\n const handleComplete = () => {\n this.detachTransakMessageListener();\n if (this.onrampNotifyController) { try { this.onrampNotifyController.stop(); } catch {} }\n this.onrampNotifyController = null;\n this.onrampPollingActive = false;\n };\n try { window.addEventListener('icpay-sdk-transaction-completed', (() => handleComplete()) as any, { once: true } as any); } catch {}\n this.onrampPollingActive = true;\n this.onrampNotifyController = (sdk as any).notifyIntentUntilComplete(paymentIntentId, 5000, orderId);\n this.onrampPollTimer = 1 as any;\n }\n\n private async pay() {\n if (!isBrowser || this.processing) return;\n\n // Reset error state\n this.errorMessage = null;\n this.errorSeverity = null;\n this.errorAction = null;\n\n if (!this.isValidAmount()) {\n this.errorMessage = 'Please enter a valid amount';\n this.errorSeverity = ErrorSeverity.WARNING;\n return;\n }\n\n try { window.dispatchEvent(new CustomEvent('icpay-sdk-method-start', { detail: { name: 'pay', type: 'sendUsd', amount: this.amountUsd, currency: this.selectedSymbol || this.config?.defaultSymbol } })); } catch {}\n\n this.processing = true;\n try {\n const ready = await this.ensureWallet();\n if (!ready) return;\n\n const sdk = createSdk(this.config);\n const symbol = this.selectedSymbol || this.config?.defaultSymbol || 'ICP';\n const opt = this.cryptoOptions.find(o => o.symbol === symbol);\n const canisterId = opt?.canisterId || await sdk.client.getLedgerCanisterIdBySymbol(symbol);\n const amountUsd = Number(this.amountUsd);\n const meta = { context: 'amount-input' } as Record<string, any>;\n\n // Do not pre-open Oisy signer tab here; let SDK handle it inside this click\n const resp = await sdk.sendUsd(amountUsd, canisterId, meta);\n if (this.config.onSuccess) this.config.onSuccess({ id: resp.transactionId, status: resp.status, amountUsd });\n this.succeeded = true;\n this.dispatchEvent(new CustomEvent('icpay-amount-pay', { detail: { amount: amountUsd, tx: resp }, bubbles: true }));\n } catch (e) {\n handleWidgetError(e, {\n onError: (error) => {\n this.dispatchEvent(new CustomEvent('icpay-error', { detail: error, bubbles: true }));\n if (shouldShowErrorToUser(error)) {\n this.errorMessage = getErrorMessage(error);\n this.errorSeverity = getErrorSeverity(error);\n this.errorAction = getErrorAction(error);\n }\n }\n });\n // On failure, disconnect so next attempt triggers wallet selection again\n try {\n if (!this.config.useOwnWallet && this.pnp) {\n await this.pnp.disconnect?.();\n this.walletConnected = false;\n this.config = { ...this.config, actorProvider: undefined as any, connectedWallet: undefined } as any;\n }\n } catch {}\n } finally {\n this.processing = false;\n }\n }\n\n render() {\n if (!this.config) return html`<div class=\"icpay-card icpay-section\">Loading...</div>`;\n const placeholder = this.config?.placeholder || 'Enter amount in USD';\n const payLabelRaw = this.config?.buttonLabel || 'Pay ${amount} with {symbol}';\n const payLabel = payLabelRaw\n .replace('{amount}', this.amountUsd ? `${Number(this.amountUsd).toFixed(2)}` : '$0.00')\n .replace('{symbol}', this.selectedSymbol || (this.config?.defaultSymbol || 'ICP'));\n const selectedLabel =\n (this.cryptoOptions.find(o => o.symbol === (this.selectedSymbol||''))?.label)\n || (this.cryptoOptions[0]?.label)\n || (this.config?.defaultSymbol || 'ICP');\n const mode = this.config?.progressBar?.mode || 'modal';\n const rawMode = (this.config?.showLedgerDropdown as any) as ('buttons'|'dropdown'|'none'|boolean|undefined);\n const globalMode: 'buttons'|'dropdown'|'none' = rawMode === 'buttons' ? 'buttons' : rawMode === 'none' ? 'none' : 'dropdown';\n const optionsCount = this.cryptoOptions?.length || 0;\n const hasMultiple = optionsCount > 1;\n const showSelector = (globalMode !== 'none') && (hasMultiple || globalMode === 'dropdown');\n const tokenSelectorMode: 'buttons'|'dropdown'|'none' = globalMode === 'dropdown' ? 'dropdown' : (hasMultiple ? 'buttons' : 'none');\n const progressEnabled = this.config?.progressBar?.enabled !== false;\n const showProgressBar = progressEnabled && (mode === 'modal' ? true : this.processing);\n\n return html`\n <div class=\"icpay-card icpay-section icpay-widget-base\">\n ${showProgressBar ? html`\n <icpay-progress-bar\n .debug=${!!this.config?.debug}\n .theme=${this.config?.theme}\n .amount=${Number(this.amountUsd || 0)}\n .ledgerSymbol=${this.selectedSymbol || this.config?.defaultSymbol || 'ICP'}\n ></icpay-progress-bar>\n ` : null}\n\n <div class=\"row\">\n <div class=\"top-row ${showSelector ? 'with-selector' : ''}\">\n <div class=\"amount-field\">\n <span class=\"currency-prefix\">$</span>\n <input type=\"number\" min=\"0\" step=\"${Number(this.config?.stepUsd ?? 0.5)}\" .value=${String(this.amountUsd || '')} placeholder=\"${placeholder}\" @input=${(e: any) => this.onInputChange(e)} />\n </div>\n ${showSelector ? html`\n <icpay-token-selector\n .options=${this.cryptoOptions}\n .value=${this.selectedSymbol || ''}\n .defaultSymbol=${this.config?.defaultSymbol || 'ICP'}\n mode=${tokenSelectorMode}\n .showLabel=${false}\n @icpay-token-change=${(e: any) => this.selectSymbol(e.detail.symbol)}\n ></icpay-token-selector>\n ` : null}\n </div>\n <button class=\"pay-button ${this.processing?'processing':''}\"\n ?disabled=${this.processing || (this.config?.disablePaymentButton === true) || (this.succeeded && this.config?.disableAfterSuccess === true)}\n @click=${() => this.pay()}>\n ${this.succeeded && this.config?.disableAfterSuccess ? 'Paid' : (this.processing ? 'Processing…' : payLabel)}\n </button>\n </div>\n <div class=\"hint\">Default: ${this.config?.defaultSymbol || 'ICP'}. Min: $${Number(this.config?.minUsd ?? 0.5).toFixed(2)}${this.config?.maxUsd ? `, Max: $${Number(this.config.maxUsd).toFixed(2)}` : ''}</div>\n\n ${this.errorMessage ? html`\n <div class=\"error-message ${this.errorSeverity}\" style=\"margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-align: center;\">\n ${this.errorMessage}\n ${this.errorAction ? html`<button style=\"margin-left: 8px; padding: 4px 8px; background: transparent; border: 1px solid currentColor; border-radius: 4px; font-size: 12px; cursor: pointer;\">${this.errorAction}</button>` : ''}\n </div>\n ` : ''}\n ${(() => {\n const walletsRaw = (this as any).pnp?.getEnabledWallets?.() || [];\n const wallets = walletsRaw.map((w:any)=>({ id: this.getWalletId(w), label: this.getWalletLabel(w), icon: this.getWalletIcon(w) }));\n return renderWalletSelectorModal({\n visible: !!(this.showWalletModal && this.pnp),\n wallets,\n isConnecting: false,\n onSelect: (walletId: string) => this.connectWithWallet(walletId),\n onClose: () => { this.showWalletModal = false; this.oisyReadyToPay = false; },\n onCreditCard: ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true)) ? () => this.startOnramp() : undefined,\n creditCardLabel: this.config?.onramp?.creditCardLabel || 'Pay with credit card',\n showCreditCard: (this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true),\n creditCardTooltip: (() => {\n const min = 5; const amt = Number(this.amountUsd || 0); if (amt > 0 && amt < min && ((this.config?.onramp?.enabled !== false) && (this.config?.onrampDisabled !== true))) { const d = (min - amt).toFixed(2); return `Note: Minimum card amount is $${min}. You will pay about $${d} more.`; } return null;\n })(),\n oisyReadyToPay: this.oisyReadyToPay,\n onOisyPay: () => { this.showWalletModal = false; this.oisyReadyToPay = false; this.pay(); }\n });\n })()}\n\n ${this.showOnrampModal ? renderTransakOnrampModal({\n visible: this.showOnrampModal,\n sessionId: this.onrampSessionId,\n errorMessage: this.onrampErrorMessage,\n apiKey: this.config?.onramp?.apiKey,\n environment: (this.config?.onramp?.environment || 'STAGING') as any,\n width: this.config?.onramp?.width,\n height: this.config?.onramp?.height,\n onClose: () => { this.showOnrampModal = false; },\n onBack: () => { this.showOnrampModal = false; this.showWalletModal = true; }\n } as TransakOnrampOptions) : null}\n </div>\n `;\n }\n}\n\ndeclare global { interface HTMLElementTagNameMap { 'icpay-amount-input': ICPayAmountInput } }\n\n\n"],"mappings":"wCAAA,OAAS,OAAAA,OAAW,MAGb,IAAMC,EAAaD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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6BACA+D,EAAA,CAAhBE,EAAM,GA1BIjE,EA0BM,8BACA+D,EAAA,CAAhBE,EAAM,GA3BIjE,EA2BM,0BACA+D,EAAA,CAAhBE,EAAM,GA5BIjE,EA4BM,yBACA+D,EAAA,CAAhBE,EAAM,GA7BIjE,EA6BM,gCACA+D,EAAA,CAAhBE,EAAM,GA9BIjE,EA8BM,4BACA+D,EAAA,CAAhBE,EAAM,GA/BIjE,EA+BM,6BACA+D,EAAA,CAAhBE,EAAM,GAhCIjE,EAgCM,2BACA+D,EAAA,CAAhBE,EAAM,GAjCIjE,EAiCM,+BACA+D,EAAA,CAAhBE,EAAM,GAlCIjE,EAkCM,6BACA+D,EAAA,CAAhBE,EAAM,GAnCIjE,EAmCM,+BACA+D,EAAA,CAAhBE,EAAM,GApCIjE,EAoCM,+BACA+D,EAAA,CAAhBE,EAAM,GArCIjE,EAqCM,+BACA+D,EAAA,CAAhBE,EAAM,GAtCIjE,EAsCM,qCACA+D,EAAA,CAAhBE,EAAM,GAvCIjE,EAuCM,kCACA+D,EAAA,CAAhBE,EAAM,GAxCIjE,EAwCM,8BACA+D,EAAA,CAAhBE,EAAM,GAzCIjE,EAyCM,4BAzCNA,EAAN+D,EAAA,CADNG,GAAc,oBAAoB,GACtBlE","names":["css","baseStyles","applyThemeVars","host","theme","primary","secondary","set","k","v","parseHex","hex","h","full","c","bigint","r","g","b","isLight","rgb","toLin","s","surface","surfaceAlt","border","text","accent","muted","Icpay","isBrowser","debugLog","debug","message","data","createSdk","config","sdkConfig","notifyIntentUntilComplete","paymentIntentId","intervalMs","orderId","client","clientAny","forward","type","e","quoteUsd","usdAmount","ledgerCanisterId","sendUsd","metadata","mergedMeta","startOnrampUsd","error","LitElement","html","css","customElement","property","state","debugLog","debug","message","data","DEFAULT_STEPS","ICPayProgressBar","LitElement","methodName","methodType","step","idx","transactionId","status","errorMessage","errorCode","requestedAmount","paidAmount","requested","paid","walletType","hasBalance","balance","ledgerId","symbol","amount","currency","ledgerSymbol","i","applyThemeVars","changed","stepIndex","oldStatus","html","key","s","msg","confettiPieces","_","colors","piece","displayAmount","displayCurrency","error","index","confirmIdx","started","css","__decorateClass","property","state","customElement","html","renderTransakOnrampModal","opts","environment","width","height","iframeSrc","LitElement","html","css","customElement","property","state","IcpayError","ERROR_CODES","defaultErrorHandler","error","handleWidgetError","errorHandler","ERROR_MESSAGES","getErrorMessage","shouldShowErrorToUser","getErrorAction","getErrorSeverity","error","LitElement","html","css","customElement","property","query","ICPayTokenSelector","LitElement","applyThemeVars","changed","onDocClick","event","onKey","single","symbol","o","slug","chain","opts","sym","html","current","currentOpt","css","__decorateClass","property","query","customElement","html","sanitizeDataUrl","url","getWalletFriendlyName","id","fallback","lower","renderWalletSelectorModal","opts","wallets","onSelect","onClose","isConnecting","normalizedWallets","w","displayName","mainButton","applyOisyNewTabConfig","cfg","next","oisy","oisyConfig","transport","normalizeConnectedWallet","pnp","connectResult","fromResult","fromAccount","toStringSafe","v","principal","detectOisySessionViaAdapter","getEnabled","oisyCfg","w","AdapterCtor","adapterInstance","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayPremiumContent","LitElement","amount","curr","raw","saved","_cfg1","resolveDerivationOrigin","pnp","changed","action","ledgers","createSdk","ledger","error","_cfg2","applyOisyNewTabConfig","principal","detectOisySessionViaAdapter","normalized","normalizeConnectedWallet","canisterId","idl","availableWallets","sdk","symbol","o","resp","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","event","eventId","orderId","sessionId","paymentIntentId","errorMessage","handleComplete","w","walletId","result","html","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayTipJar","LitElement","amount","curr","raw","saved","_cfg1","applyOisyNewTabConfig","resolveDerivationOrigin","pnp","changed","action","ledgers","createSdk","ledger","error","v","s","_cfg2","principal","detectOisySessionViaAdapter","normalized","normalizeConnectedWallet","canisterId","idl","availableWallets","sdk","symbol","o","resp","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","event","eventId","orderId","sessionId","paymentIntentId","errorMessage","handleComplete","w","walletId","result","html","hasMultiple","rawMode","globalMode","showSelector","tokenSelectorMode","a","e","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayArticlePaywall","LitElement","amount","curr","raw","saved","_cfg1","resolveDerivationOrigin","pnp","event","eventId","orderId","sdk","createSdk","symbol","canisterId","o","resp","sessionId","paymentIntentId","errorMessage","handleComplete","changed","action","ledgers","ledger","error","s","_cfg2","applyOisyNewTabConfig","principal","detectOisySessionViaAdapter","normalized","normalizeConnectedWallet","idl","availableWallets","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","w","walletId","result","html","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayCoffeeShop","LitElement","amount","curr","changed","action","ledgers","createSdk","ledger","error","i","s","_cfg","applyOisyNewTabConfig","resolveDerivationOrigin","principal","detectOisySessionViaAdapter","normalized","normalizeConnectedWallet","canisterId","idl","availableWallets","sdk","symbol","o","resp","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","event","eventId","orderId","sessionId","paymentIntentId","errorMessage","handleComplete","w","walletId","result","html","it","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayDonationThermometer","LitElement","amount","curr","raw","saved","_cfg1","applyOisyNewTabConfig","resolveDerivationOrigin","pnp","changed","action","ledgers","createSdk","ledger","error","v","s","goal","denom","_cfg2","principal","detectOisySessionViaAdapter","normalized","normalizeConnectedWallet","canisterId","idl","availableWallets","sdk","symbol","o","resp","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","event","eventId","orderId","sessionId","paymentIntentId","errorMessage","handleComplete","w","walletId","result","html","a","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayPayButton","LitElement","amount","curr","createSdk","changed","action","ledgers","ledger","error","symbol","wantsOisyTab","_rawCfg","_cfg","applyOisyNewTabConfig","resolveDerivationOrigin","availableWallets","w","walletId","result","normalized","normalizeConnectedWallet","canisterId","idl","isOisy","raw","cfg","err2","initErr","wallets","onrampEnabled","minOnramp","amountUsd","showTooltip","diff","tooltip","renderWalletSelectorModal","sdk","o","resp","sessionId","errorMessage","paymentIntentId","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","event","eventId","orderId","handleComplete","listener","e","cw","pnpAcct","meta","html","hasMultiple","rawMode","globalMode","showSelector","tokenSelectorMode","selectedSymbol","amountPart","label","showProgressBar","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement","LitElement","html","css","customElement","property","state","isBrowser","PlugNPlay","debugLog","debug","message","data","ICPayAmountInput","LitElement","amount","curr","changed","action","ledgers","createSdk","ledger","error","step","value","rounded","symbol","min","max","wantsOisyTab","_rawCfg","_cfg","applyOisyNewTabConfig","resolveDerivationOrigin","w","walletId","result","normalized","normalizeConnectedWallet","canisterId","idl","event","eventId","orderId","sdk","o","amountUsd","resp","sessionId","paymentIntentId","errorMessage","handleComplete","meta","handleWidgetError","shouldShowErrorToUser","getErrorMessage","getErrorSeverity","getErrorAction","html","placeholder","payLabel","selectedLabel","mode","rawMode","globalMode","hasMultiple","showSelector","tokenSelectorMode","showProgressBar","e","wallets","renderWalletSelectorModal","amt","renderTransakOnrampModal","baseStyles","css","__decorateClass","property","state","customElement"]}