diff --git a/packages/core/src/elements/iframe.ts b/packages/core/src/elements/iframe.ts index e8dab48..db1536b 100644 --- a/packages/core/src/elements/iframe.ts +++ b/packages/core/src/elements/iframe.ts @@ -1,6 +1,8 @@ import { iframeStyles } from "../styles/styles"; -import { ORBA_ONE_MESSAGE_CHANNEL, ORBA_ONE_SUCCESS, ORBA_ONE_CANCEL } from "./constants"; +import { removeLoadingScreen } from "../helpers/utils"; + +import {ORBA_ONE_MESSAGE_CHANNEL,ORBA_ONE_SUCCESS,ORBA_ONE_CANCEL} from "./constants"; type State = "loading" | "success" | "error" | "idle"; @@ -57,7 +59,9 @@ export function iframeManager( // The html tag has to have a overflowY value of visible instead of auto to // prevent unnecessary margins to the scrollbar document.documentElement.style.overflowY = "visible"; + removeLoadingScreen(); document.body.removeChild(iframe); + } function addIFrame() { diff --git a/packages/core/src/helpers/elements.ts b/packages/core/src/helpers/elements.ts new file mode 100644 index 0000000..a24d26b --- /dev/null +++ b/packages/core/src/helpers/elements.ts @@ -0,0 +1 @@ +export const loadingDiv = document.createElement('div'); diff --git a/packages/core/src/helpers/utils.ts b/packages/core/src/helpers/utils.ts index 0ad7147..764d140 100644 --- a/packages/core/src/helpers/utils.ts +++ b/packages/core/src/helpers/utils.ts @@ -1,4 +1,6 @@ import { OrbaOneConfig } from "./types"; +import { iframeLoader } from "../styles/templates"; +import { loadingDiv } from "../helpers/elements"; export function isDomElement(obj: any): obj is HTMLElement | Element { //! check if obj is not null explicitly because null is a type of object @@ -57,3 +59,11 @@ export function getSessionUrl(verificationUrl: string, apiKey: string, applicant return `${verificationUrl}?publicKey=${apiKey}&applicantId=${applicantId}&steps=${steps.join("&steps=")}`; } +export function showLoadingScreen() { + loadingDiv.innerHTML = iframeLoader; + document.body.appendChild(loadingDiv); +} + +export function removeLoadingScreen() { + document.body.removeChild(loadingDiv); +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 08ad5e2..a6444bd 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -2,15 +2,16 @@ import { createButton } from "./elements/button"; import { createIframe } from "./elements/iframe"; import { verificationUrl } from "./helpers/defaultConfig"; import { OrbaOneConfig } from "./helpers/types"; - import { getSessionUrl, isValidConfig } from "./helpers/utils"; +import { showLoadingScreen } from "./helpers/utils"; function initializeVerification(config: OrbaOneConfig, button: ReturnType): void { const { apiKey, applicantId, onSuccess, onCancelled, onError, steps } = config; //Set Loading state button.setState("loading"); - + showLoadingScreen(); + const url = getSessionUrl(verificationUrl, apiKey, applicantId, steps); const iframe = createIframe(url, applicantId, onSuccess, onCancelled, onError, (state) => { button.setState(state); diff --git a/packages/core/src/styles/templates.ts b/packages/core/src/styles/templates.ts index 52c5fc5..b300822 100644 --- a/packages/core/src/styles/templates.ts +++ b/packages/core/src/styles/templates.ts @@ -119,3 +119,20 @@ export const loader = ` `; + +export const iframeLoader = ` +
+${loader} +
+`;