Skip to content

Commit

Permalink
Replace window with safeWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
mgavrila committed Dec 19, 2024
1 parent 6210a1a commit 7930928
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/utils/createModalElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import { IEventBus } from '@multiversx/sdk-dapp-core-ui/loader';
import { safeWindow } from 'constants/index';
import { defineCustomElements } from 'lib/sdkDappCoreUi';

//TODO: allow override createModalElement similar to accountProvider and add typed name for all webcomponents
export const createModalElement = async <
T extends HTMLElement & { getEventBus: () => Promise<IEventBus | undefined> }
T extends HTMLElement & {
getEventBus: () => Promise<IEventBus | undefined>;
}
>(
name: string
) => {
await defineCustomElements(safeWindow);

const modalElement = document.createElement(name) as T;
document.body.appendChild(modalElement);
if (!safeWindow.document) {
return {} as T;
}

const modalElement = safeWindow.document.createElement(name) as T;
safeWindow.document.body.appendChild(modalElement);
await customElements.whenDefined(name);

return modalElement;
Expand Down

0 comments on commit 7930928

Please sign in to comment.