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(