Skip to content

Commit 8bc4f79

Browse files
committed
fix, refactor loading screen toggle
1 parent 1afd438 commit 8bc4f79

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

packages/core/src/elements/iframe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { iframeStyles } from "../styles/styles";
22

3-
import { loadingDiv } from "../helpers/elements";
3+
import { removeLoadingScreen } from "../helpers/utils";
44

55
import {ORBA_ONE_MESSAGE_CHANNEL,ORBA_ONE_SUCCESS,ORBA_ONE_CANCEL} from "./constants";
66

@@ -51,7 +51,7 @@ export function iframeManager(
5151
if (iframe) {
5252
window.removeEventListener(ORBA_ONE_MESSAGE_CHANNEL, handler);
5353
document.body.style.overflowY = "auto";
54-
document.body.removeChild(loadingDiv);
54+
removeLoadingScreen();
5555
document.body.removeChild(iframe);
5656
}
5757
}

packages/core/src/helpers/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { OrbaOneConfig } from "./types";
2+
import { iframeLoader } from "../styles/templates";
3+
import { loadingDiv } from "../helpers/elements";
24

35
export function isDomElement(obj: any): obj is HTMLElement | Element {
46
//! 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
5759
return `${verificationUrl}?publicKey=${apiKey}&applicantId=${applicantId}&steps=${steps.join("&steps=")}`;
5860
}
5961

62+
export function showLoadingScreen() {
63+
loadingDiv.innerHTML = iframeLoader;
64+
document.body.appendChild(loadingDiv);
65+
}
66+
67+
export function removeLoadingScreen() {
68+
document.body.removeChild(loadingDiv);
69+
}

packages/core/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { createButton } from "./elements/button";
22
import { createIframe } from "./elements/iframe";
33
import { verificationUrl } from "./helpers/defaultConfig";
4-
import { loadingDiv } from "./helpers/elements";
54
import { OrbaOneConfig } from "./helpers/types";
6-
import { iframeLoader } from "./styles/templates";
75
import { getSessionUrl, isValidConfig } from "./helpers/utils";
6+
import { showLoadingScreen } from "./helpers/utils";
87

98
function initializeVerification(config: OrbaOneConfig, button: ReturnType<typeof createButton>): void {
109
const { apiKey, applicantId, onSuccess, onCancelled, onError, steps } = config;
1110

1211
//Set Loading state
1312
button.setState("loading");
14-
loadingDiv.innerHTML = iframeLoader;
15-
16-
document.body.appendChild(loadingDiv);
13+
showLoadingScreen();
14+
1715
const url = getSessionUrl(verificationUrl, apiKey, applicantId, steps);
1816
const iframe = createIframe(url, applicantId, onSuccess, onCancelled, onError, (state) => {
1917
button.setState(state);

0 commit comments

Comments
 (0)