Skip to content

Commit

Permalink
fix: changed post message from parent window to current window
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Sep 3, 2024
1 parent 15e928c commit f8d1ed6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ type dateTimeFormat = {resolvedOptions: unit => options}
@send external remove: Dom.element => unit = "remove"

@send external postMessage: (parent, JSON.t, string) => unit = "postMessage"
@val @scope("window") external windowPostMessage: (JSON.t, string) => unit = "postMessage"

open ErrorUtils
let messageParentWindow = (~targetOrigin="*", messageArr) => {
iframeParent->postMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin)
}

let messageCurrentWindow = (~targetOrigin="*", messageArr) => {
windowPostMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin)
}

let handleOnFocusPostMessage = (~targetOrigin="*") => {
messageParentWindow([("focus", true->JSON.Encode.bool)], ~targetOrigin)
}
Expand Down
14 changes: 7 additions & 7 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ let make = (
}
switch eventDataObject->getOptionalJsonFromJson("poll_status") {
| Some(val) => {
messageParentWindow([
messageCurrentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", selectorString->JSON.Encode.string),
Expand Down Expand Up @@ -650,7 +650,7 @@ let make = (
)
resolve(JSON.Encode.null)
} else {
messageParentWindow([
messageCurrentWindow([
("fullscreen", false->JSON.Encode.bool),
("submitSuccessful", true->JSON.Encode.bool),
("data", json),
Expand All @@ -662,7 +662,7 @@ let make = (
if redirect.contents === "always" {
Window.Location.replace(url)
}
messageParentWindow([
messageCurrentWindow([
("submitSuccessful", false->JSON.Encode.bool),
("error", err->Identity.anyTypeToJson),
])
Expand All @@ -679,7 +679,7 @@ let make = (

switch eventDataObject->getOptionalJsonFromJson("openurl_if_required") {
| Some(val) =>
messageParentWindow([
messageCurrentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", selectorString->JSON.Encode.string),
Expand All @@ -696,17 +696,17 @@ let make = (
~isForceSync=true,
)
->then(json => {
messageParentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)])
messageCurrentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)])
resolve(json)
})
->catch(err => {
messageParentWindow([
messageCurrentWindow([
("submitSuccessful", false->JSON.Encode.bool),
("error", err->Identity.anyTypeToJson),
])
resolve(err->Identity.anyTypeToJson)
})
->finally(_ => messageParentWindow([("fullscreen", false->JSON.Encode.bool)]))
->finally(_ => messageCurrentWindow([("fullscreen", false->JSON.Encode.bool)]))
}->ignore

| None => ()
Expand Down

0 comments on commit f8d1ed6

Please sign in to comment.