diff --git a/src/Hooks/UtilityHooks.res b/src/Hooks/UtilityHooks.res index 09a4ef605..ed06c76c5 100644 --- a/src/Hooks/UtilityHooks.res +++ b/src/Hooks/UtilityHooks.res @@ -41,3 +41,23 @@ let useIsCustomerAcceptanceRequired = ( displaySavedPaymentMethodsCheckbox, )) } + +let useSendEventsToParent = eventsToSendToParent => { + React.useEffect0(() => { + let handle = (ev: Window.event) => { + let eventDataObject = ev.data->Identity.anyTypeToJson + let eventsDict = eventDataObject->Utils.getDictFromJson + + let events = eventsDict->Dict.keysToArray + + let shouldSendToParent = + events->Array.some(event => eventsToSendToParent->Array.includes(event)) + + if shouldSendToParent { + Utils.messageParentWindow(eventsDict->Dict.toArray) + } + } + Window.addEventListener("message", handle) + Some(() => {Window.removeEventListener("message", handle)}) + }) +} diff --git a/src/ThreeDSAuth.res b/src/ThreeDSAuth.res index e836219b0..5d5f9a6f6 100644 --- a/src/ThreeDSAuth.res +++ b/src/ThreeDSAuth.res @@ -21,6 +21,10 @@ let make = () => { } } + let eventsToSendToParent = ["confirmParams", "poll_status", "openurl_if_required"] + + eventsToSendToParent->UtilityHooks.useSendEventsToParent + React.useEffect0(() => { messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => {