Skip to content

Commit

Permalink
fix: added support to send post messages to parent iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Sep 2, 2024
1 parent 0b8c9cd commit 0fbc749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Hooks/UtilityHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 isEventToSendParent =
events->Array.find(event => eventsToSendToParent->Array.includes(event))->Option.isSome

if isEventToSendParent {
Utils.messageParentWindow(eventsDict->Dict.toArray)
}
}
Window.addEventListener("message", handle)
Some(() => {Window.removeEventListener("message", handle)})
})
}
4 changes: 4 additions & 0 deletions src/ThreeDSAuth.res
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 0fbc749

Please sign in to comment.