From 9d259c25ac88d142f910bff81895d10dabbd0dc1 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa <136090360+vsrivatsa-juspay@users.noreply.github.com> Date: Fri, 17 May 2024 22:29:25 +0530 Subject: [PATCH] revert: do not unmount preMountLoader iframe (#382) --- src/Payments/PreMountLoader.res | 1 + src/orca-loader/Elements.res | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/Payments/PreMountLoader.res b/src/Payments/PreMountLoader.res index 79220b1d4..3b531e00b 100644 --- a/src/Payments/PreMountLoader.res +++ b/src/Payments/PreMountLoader.res @@ -96,6 +96,7 @@ let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => { if ( paymentMethodsResponseSent && customerPaymentMethodsResponseSent && sessionTokensResponseSent ) { + handlePostMessage([("preMountLoaderIframeUnMount", true->JSON.Encode.bool)]) Window.removeEventListener("message", handle) } None diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 6c7c3a1c9..2eafd6c8f 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -90,12 +90,21 @@ let make = ( let preMountLoaderIframeDiv = mountPreMountLoaderIframe() + let unMountPreMountLoaderIframe = () => { + switch preMountLoaderIframeDiv->Nullable.toOption { + | Some(iframe) => iframe->remove + | None => () + } + } + let preMountLoaderMountedPromise = Promise.make((resolve, _reject) => { let preMountLoaderIframeCallback = (ev: Types.event) => { let json = ev.data->Identity.anyTypeToJson let dict = json->getDictFromJson if dict->Dict.get("preMountLoaderIframeMountedCallback")->Option.isSome { resolve(true->JSON.Encode.bool) + } else if dict->Dict.get("preMountLoaderIframeUnMount")->Option.isSome { + unMountPreMountLoaderIframe() } } addSmartEventListener(