From 7930928ea73d12ee6c44df63ddc01115ca914df8 Mon Sep 17 00:00:00 2001 From: Gavrila Andrei Date: Thu, 19 Dec 2024 12:56:48 +0200 Subject: [PATCH] Replace window with safeWindow --- src/utils/createModalElement.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/createModalElement.ts b/src/utils/createModalElement.ts index 1175bd4..cfc3423 100644 --- a/src/utils/createModalElement.ts +++ b/src/utils/createModalElement.ts @@ -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 } + T extends HTMLElement & { + getEventBus: () => Promise; + } >( 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;