Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
59 changes: 40 additions & 19 deletions src/utils/modalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,52 @@ export class QRCodeModal {
};
}

async show(requestUrl: string): Promise<void> {
try {
// Remove existing modal if present
this.close();
async show(requestUrl: string): Promise<void> {
try {

// Prevent showing modal inside an iframe if enabled
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;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: onClose callback invoked when modal never opened

When preventIframe blocks the modal from opening, the onClose callback is invoked even though the modal was never actually opened. The onClose callback is documented as "Callback when modal is closed" and should only fire when an opened modal is being closed, not when the modal is prevented from opening. This creates semantic inconsistency and will cause false positives for developers tracking modal lifecycle events for analytics, cleanup, or state management purposes.

Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the type definition issues and modal cleanup. All checks are passing. Ready for review!

}

// Create modal HTML
const modalHTML = this.createModalHTML();
// Remove existing modal if present
this.close();

// Add modal to DOM
document.body.insertAdjacentHTML('beforeend', modalHTML);
// Create modal HTML
const modalHTML = this.createModalHTML();

// Generate QR code
await this.generateQRCode(requestUrl, 'reclaim-qr-code');
// Add modal to DOM
document.body.insertAdjacentHTML('beforeend', modalHTML);

// Add event listeners
this.addEventListeners();
// Generate QR code
await this.generateQRCode(requestUrl, 'reclaim-qr-code');

// Start auto-close timer
this.startAutoCloseTimer();
// Add event listeners
this.addEventListeners();

} catch (error) {
logger.info('Error showing QR code modal:', error);
throw error;
}
// Start auto-close timer
this.startAutoCloseTimer();

} catch (error) {
logger.info('Error showing QR code modal:', error);
throw error;
}
}


close(): void {
// Clear timers
Expand Down Expand Up @@ -348,4 +369,4 @@ export class QRCodeModal {
progressBar.style.width = `${progressPercentage}%`;
}
}
}
}
5 changes: 4 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -160,4 +163,4 @@ export type StatusUrlResponse = {
statusV2: string;
};
providerId?: string;
};
};