Skip to content

Commit

Permalink
fix: comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Nov 13, 2024
1 parent dd9b5e5 commit fa619e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ let mergeAndFlattenToTuples = (body, requiredFieldsBody) =>
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict

let handleIframePostMessage = (~msg, ~componentName, ~sendFallbackMessage) => {
let handleIframePostMessageForWallets = (msg, componentName, mountedIframeRef) => {
let isMessageSent = ref(false)
let iframes = Window.querySelectorAll("iframe")

Expand All @@ -1448,16 +1448,6 @@ let handleIframePostMessage = (~msg, ~componentName, ~sendFallbackMessage) => {
})

if !isMessageSent.contents {
sendFallbackMessage()
mountedIframeRef->Window.iframePostMessage(msg)
}
}

let handleApplePayIframePostMessage = (msg, componentName, mountedIframeRef) =>
handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ =>
mountedIframeRef->Window.iframePostMessage(msg)
)

let handlePazeIframePostMessage = (msg, componentName, source) =>
handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ =>
source->Window.sendPostMessage(msg)
)
24 changes: 13 additions & 11 deletions src/hyper-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ let make = (
}
}

let onPazeCallback = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson
let dict = json->getDictFromJson
if dict->getBool("isPaze", false) {
let componentName = dict->getString("componentName", "payment")
let msg = [("data", json)]->Dict.fromArray
handlePazeIframePostMessage(msg, componentName, event.source)
let onPazeCallback = mountedIframeRef => {
(event: Types.event) => {
let json = event.data->Identity.anyTypeToJson
let dict = json->getDictFromJson
if dict->getBool("isPaze", false) {
let componentName = dict->getString("componentName", "payment")
let msg = [("data", json)]->Dict.fromArray
handleIframePostMessageForWallets(msg, componentName, mountedIframeRef)
}
}
}

Expand All @@ -148,7 +150,7 @@ let make = (
isTaxCalculationEnabled.contents =
dict->getDictFromDict("response")->getBool("is_tax_calculation_enabled", false)
addSmartEventListener("message", onPlaidCallback(mountedIframeRef), "onPlaidCallback")
addSmartEventListener("message", onPazeCallback, "onPazeCallback")
addSmartEventListener("message", onPazeCallback(mountedIframeRef), "onPazeCallback")

let json = dict->getJsonFromDict("response", JSON.Encode.null)
let isApplePayPresent = PaymentMethodsRecord.getPaymentMethodTypeFromList(
Expand Down Expand Up @@ -401,7 +403,7 @@ let make = (
try {
let msg = [("applePayCanMakePayments", true->JSON.Encode.bool)]->Dict.fromArray

handleApplePayIframePostMessage(msg, componentName, mountedIframeRef)
handleIframePostMessageForWallets(msg, componentName, mountedIframeRef)
} catch {
| exn => {
let exnString = exn->anyTypeToJson->JSON.stringify
Expand Down Expand Up @@ -895,13 +897,13 @@ let make = (
("applePayShippingContact", shippingContact),
]->Dict.fromArray

handleApplePayIframePostMessage(msg, componentName, mountedIframeRef)
handleIframePostMessageForWallets(msg, componentName, mountedIframeRef)
}

if dict->Dict.get("showApplePayButton")->Option.isSome {
let msg = [("showApplePayButton", true->JSON.Encode.bool)]->Dict.fromArray

handleApplePayIframePostMessage(msg, componentName, mountedIframeRef)
handleIframePostMessageForWallets(msg, componentName, mountedIframeRef)
}
}

Expand Down

0 comments on commit fa619e8

Please sign in to comment.