diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 83614b01..c5e82b2d 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -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") @@ -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) - ) diff --git a/src/hyper-loader/Elements.res b/src/hyper-loader/Elements.res index cb0d26d1..4eda0f49 100644 --- a/src/hyper-loader/Elements.res +++ b/src/hyper-loader/Elements.res @@ -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) + } } } @@ -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( @@ -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 @@ -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) } }