diff --git a/README.md b/README.md index 18f6285..36ea54a 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,16 @@ reclaimProofRequest.setModalOptions({ await reclaimProofRequest.triggerReclaimFlow(); ``` +### preventIframe (optional) + +Prevents the QR modal from opening when the SDK is running inside an iframe. +Useful for apps embedded in dashboards, widgets, or hosted inside other platforms. + +```ts +reclaimProofRequest.setModalOptions({ + preventIframe: true +}); +``` ### Benefits of the New Flow: diff --git a/src/utils/modalUtils.ts b/src/utils/modalUtils.ts index 5aff30d..272cc9a 100644 --- a/src/utils/modalUtils.ts +++ b/src/utils/modalUtils.ts @@ -23,31 +23,51 @@ export class QRCodeModal { }; } - async show(requestUrl: string): Promise { - try { - // Remove existing modal if present - this.close(); + async show(requestUrl: string): Promise { + try { + // Always close previous modal FIRST + this.close(); + + // IFRAME CHECK + if (this.options.preventIframe) { + try { + if (window.self !== window.top) { + logger.info( + "Reclaim Modal blocked: preventIframe = true and page is inside an iframe." + ); + if (this.options.onClose) this.options.onClose(); + return; + } + } catch { + logger.info( + "Reclaim Modal blocked: preventIframe = true and iframe check threw a security error." + ); + if (this.options.onClose) this.options.onClose(); + return; + } + } - // Create modal HTML - const modalHTML = this.createModalHTML(); + // Create modal HTML + const modalHTML = this.createModalHTML(); - // Add modal to DOM - document.body.insertAdjacentHTML('beforeend', modalHTML); + // Add modal to DOM + document.body.insertAdjacentHTML('beforeend', modalHTML); - // Generate QR code - await this.generateQRCode(requestUrl, 'reclaim-qr-code'); + // Generate QR code + await this.generateQRCode(requestUrl, 'reclaim-qr-code'); - // Add event listeners - this.addEventListeners(); + // Add event listeners + this.addEventListeners(); - // Start auto-close timer - this.startAutoCloseTimer(); + // Start auto-close timer + this.startAutoCloseTimer(); - } catch (error) { - logger.info('Error showing QR code modal:', error); - throw error; - } + } catch (error) { + logger.info('Error showing QR code modal:', error); + throw error; } +} + close(): void { // Clear timers @@ -348,4 +368,4 @@ export class QRCodeModal { progressBar.style.width = `${progressPercentage}%`; } } -} \ No newline at end of file +} diff --git a/src/utils/types.ts b/src/utils/types.ts index b5d73ec..da19a22 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -67,6 +67,9 @@ export type ModalOptions = { modalPopupTimer?: number; showExtensionInstallButton?: boolean; onClose?: () => void; + // NEW OPTION + preventIframe?: boolean; + }; // JSON-safe modal options (excludes non-serializable functions) @@ -160,4 +163,4 @@ export type StatusUrlResponse = { statusV2: string; }; providerId?: string; -}; \ No newline at end of file +};