Skip to content

Commit

Permalink
chore: rename handlePostMessage to messageParentWindow (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
seekshiva authored Aug 26, 2024
1 parent 27c1b6c commit 827ae3a
Show file tree
Hide file tree
Showing 38 changed files with 102 additions and 99 deletions.
2 changes: 1 addition & 1 deletion rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"namespace": true,
"ppx-flags": [],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"bs-dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion src/Components/AddBankAccount.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let make = (~modalData, ~setModalData) => {
let toolTipRef = React.useRef(Nullable.null)

let openModal = () => {
handlePostMessage([
messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("iframeId", iframeId->JSON.Encode.string),
])
Expand Down
2 changes: 1 addition & 1 deletion src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type addressType = Line1 | Line2 | City | Postal | State | Country
type dataModule = {states: JSON.t}

@val
external importStates: string => Promise.t<dataModule> = "import"
external importStates: string => promise<dataModule> = "import"

let getShowType = str => {
switch str {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FullScreenDivDriver.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@react.component
let make = () => {
React.useEffect0(() => {
Utils.handlePostMessage([("driverMounted", true->JSON.Encode.bool)])
Utils.messageParentWindow([("driverMounted", true->JSON.Encode.bool)])
None
})
<div />
Expand Down
2 changes: 1 addition & 1 deletion src/Components/InputField.res
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let make = (
let concatString = Array.joinWith([cardEmpty, cardComplete, cardInvalid, cardFocused], "")

React.useEffect(() => {
Utils.handlePostMessage([
Utils.messageParentWindow([
("id", iframeId->JSON.Encode.string),
("concatedString", concatString->JSON.Encode.string),
])
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Modal.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let close = setOpenModal => {
setOpenModal(_ => false)
setTimeout(() => {
Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
}, 450)->ignore
}

Expand All @@ -21,7 +21,7 @@ let make = (
switch closeCallback {
| Some(fn) => fn()
| None => setTimeout(() => {
Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
}, 450)->ignore
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let make = () => {
setIsPayNowButtonDisable(_ => true)
setShowLoader(_ => true)
EventListenerManager.addSmartEventListener("message", handleMessage, "onSubmitSuccessful")
handlePostMessage([("handleSdkConfirm", confirmPayload)])
messageParentWindow([("handleSdkConfirm", confirmPayload)])
}

<div className="flex flex-col gap-1 h-auto w-full items-center">
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PaymentLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let make = () => {
let (branding, setBranding) = React.useState(_ => "auto")

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->getDictFromJson
Expand Down
6 changes: 3 additions & 3 deletions src/Components/SavedPaymentManagement.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let make = (~savedMethods: array<PaymentType.customerMethods>, ~setSavedMethods)
}

let handleDelete = (paymentItem: PaymentType.customerMethods) => {
handlePostMessage([
messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand All @@ -44,7 +44,7 @@ let make = (~savedMethods: array<PaymentType.customerMethods>, ~setSavedMethods)
} else {
logger.setLogError(~value=res->JSON.stringify, ~eventName=DELETE_SAVED_PAYMENT_METHOD)
}
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
resolve()
})
->catch(err => {
Expand All @@ -53,7 +53,7 @@ let make = (~savedMethods: array<PaymentType.customerMethods>, ~setSavedMethods)
~value=`Error Deleting Saved Payment Method: ${exceptionMessage}`,
~eventName=DELETE_SAVED_PAYMENT_METHOD,
)
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
resolve()
})
->ignore
Expand Down
8 changes: 4 additions & 4 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let {config} = configAtom
let {iframeId} = keys

let handlePostMessage = data => handlePostMessage(data, ~targetOrigin=keys.parentURL)
let messageParentWindow = data => messageParentWindow(data, ~targetOrigin=keys.parentURL)

let setUserFullName = Recoil.useLoggedSetRecoilState(userFullName, "fullName", logger)
let setUserEmail = Recoil.useLoggedSetRecoilState(userEmailAddress, "email", logger)
Expand Down Expand Up @@ -141,8 +141,8 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}

React.useEffect0(() => {
handlePostMessage([("iframeMounted", true->JSON.Encode.bool)])
handlePostMessage([("applePayMounted", true->JSON.Encode.bool)])
messageParentWindow([("iframeMounted", true->JSON.Encode.bool)])
messageParentWindow([("applePayMounted", true->JSON.Encode.bool)])
logger.setLogInitiated()
let updatedState: PaymentType.loadType = switch paymentMethodList {
| Loading =>
Expand Down Expand Up @@ -553,7 +553,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime

React.useEffect(() => {
let iframeHeight = divH->Float.equal(0.0) ? divH : divH +. 1.0
handlePostMessage([
messageParentWindow([
("iframeHeight", iframeHeight->JSON.Encode.float),
("iframeId", iframeId->JSON.Encode.string),
])
Expand Down
4 changes: 2 additions & 2 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
let evalMethodsList = () =>
switch paymentMethodList {
| SemiLoaded | LoadError(_) | Loaded(_) =>
handlePostMessage([("ready", true->JSON.Encode.bool)])
messageParentWindow([("ready", true->JSON.Encode.bool)])
| _ => ()
}
if !displaySavedPaymentMethods {
Expand All @@ -379,7 +379,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
| LoadingSavedCards => ()
| LoadedSavedCards(list, _) =>
list->Array.length > 0
? handlePostMessage([("ready", true->JSON.Encode.bool)])
? messageParentWindow([("ready", true->JSON.Encode.bool)])
: evalMethodsList()
| NoResult(_) => evalMethodsList()
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/AddBankDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let make = (~paymentMethodType) => {
~optLogger=Some(logger),
)
->then(_ => {
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
setShowFields(_ => false)
JSON.Encode.null->resolve
})
Expand Down
7 changes: 5 additions & 2 deletions src/Payments/BankTransfersPopup.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ let make = (~transferType) => {
keys
->Array.map(item => `${item->snakeToTitleCase} : ${getKeyValue(json, item)}`)
->Array.joinWith(`\n`)
handlePostMessage([("copy", true->JSON.Encode.bool), ("copyDetails", text->JSON.Encode.string)])
messageParentWindow([
("copy", true->JSON.Encode.bool),
("copyDetails", text->JSON.Encode.string),
])
setIsCopied(_ => true)
}
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let make = (
if result {
if isInvokeSDKFlow {
if isDelayedSessionToken {
handlePostMessage([
messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/KlarnaSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let make = (~sessionObj: SessionsType.token) => {
}

let handleCloseLoader = () => {
Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
}

let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList(
Expand Down Expand Up @@ -69,7 +69,7 @@ let make = (~sessionObj: SessionsType.token) => {
result => {
let result = result->JSON.Decode.bool->Option.getOr(false)
if result {
Utils.handlePostMessage([
Utils.messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaSDKTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type loadType = {
payment_method_category?: string,
theme?: string,
shape?: string,
on_click?: authorize => Promise.t<unit>,
on_click?: authorize => promise<unit>,
}
type some = {
init: token => unit,
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PaypalSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
| _ => 48
},
}
let handleCloseLoader = () => Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
let handleCloseLoader = () => Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
let isGuestCustomer = UtilityHooks.useIsGuestCustomer()

let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList(
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/PaypalSDKHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let loadPaypalSDK = (
style: buttonStyle,
fundingSource: paypal["FUNDING"]["PAYPAL"],
createOrder: () => {
Utils.handlePostMessage([
Utils.messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down Expand Up @@ -169,7 +169,7 @@ let loadBraintreePaypalSdk = (
fundingSource: paypal["FUNDING"]["PAYPAL"],
createBillingAgreement: () => {
//Paypal Clicked
Utils.handlePostMessage([
Utils.messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down
8 changes: 4 additions & 4 deletions src/Payments/PlaidSDKIframe.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let make = () => {
}
}
Window.addEventListener("message", handle)
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
Some(() => {Window.removeEventListener("message", handle)})
})

Expand Down Expand Up @@ -80,7 +80,7 @@ let make = () => {
~message="Payment is processing. Try again later!",
)
}
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
resolve(json)
})
->then(_ => {
Expand All @@ -101,7 +101,7 @@ let make = () => {
logger.setLogInfo(~value="Plaid SDK Loaded", ~eventName=PLAID_SDK)
},
onSuccess: (publicToken, _) => {
handlePostMessage([
messageParentWindow([
("isPlaid", true->JSON.Encode.bool),
("publicToken", publicToken->JSON.Encode.string),
])
Expand All @@ -113,7 +113,7 @@ let make = () => {
if isForceSync {
callbackOnSuccessOfPlaidPaymentsFlow()
} else {
handlePostMessage([
messageParentWindow([
("fullscreen", false->JSON.Encode.bool),
("isPlaid", true->JSON.Encode.bool),
("isExited", true->JSON.Encode.bool),
Expand Down
8 changes: 4 additions & 4 deletions src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let make = (
open Promise
promise
->then(res => {
handlePostMessage([("response", res), ("data", key->JSON.Encode.string)])
messageParentWindow([("response", res), ("data", key->JSON.Encode.string)])
switch key {
| "payment_methods" => setPaymentMethodsResponseSent(_ => true)
| "session_tokens" => setSessionTokensResponseSent(_ => true)
Expand All @@ -102,7 +102,7 @@ let make = (
resolve()
})
->catch(_err => {
handlePostMessage([("response", JSON.Encode.null), ("data", key->JSON.Encode.string)])
messageParentWindow([("response", JSON.Encode.null), ("data", key->JSON.Encode.string)])
resolve()
})
->ignore
Expand All @@ -124,7 +124,7 @@ let make = (

React.useEffect0(() => {
Window.addEventListener("message", handle)
handlePostMessage([("preMountLoaderIframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("preMountLoaderIframeMountedCallback", true->JSON.Encode.bool)])
Some(
() => {
Window.removeEventListener("message", handle)
Expand All @@ -134,7 +134,7 @@ let make = (

React.useEffect4(() => {
let handleUnmount = () => {
handlePostMessage([("preMountLoaderIframeUnMount", true->JSON.Encode.bool)])
messageParentWindow([("preMountLoaderIframeUnMount", true->JSON.Encode.bool)])
Window.removeEventListener("message", handle)
}

Expand Down
2 changes: 1 addition & 1 deletion src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let make = () => {
let switchToCustomPod = Recoil.useRecoilValueFromAtom(RecoilAtoms.switchToCustomPod)

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/VoucherDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let make = () => {
}, [loader])

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
Expand Down
2 changes: 1 addition & 1 deletion src/SingleLineCardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ let make = (
let concatString = Array.joinWith([cardEmpty, cardComplete, cardInvalid, cardFocused], "")

React.useEffect(() => {
Utils.handlePostMessage([
Utils.messageParentWindow([
("id", iframeId->JSON.Encode.string),
("concatedString", concatString->JSON.Encode.string),
])
Expand Down
4 changes: 2 additions & 2 deletions src/ThreeDSAuth.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let make = () => {
}

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->getDictFromJson
Expand Down Expand Up @@ -64,7 +64,7 @@ let make = () => {
let dict = json->getDictFromJson
if dict->Dict.get("error")->Option.isSome {
let errorObj = PaymentError.itemToObjMapper(dict)
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
messageParentWindow([("fullscreen", false->JSON.Encode.bool)])
postFailedSubmitResponse(
~errortype=errorObj.error.type_,
~message=errorObj.error.message,
Expand Down
6 changes: 3 additions & 3 deletions src/ThreeDSMethod.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let make = () => {
~value="Y",
~paymentMethod="CARD",
)
handlePostMessage([
messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", `3dsAuth`->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down Expand Up @@ -54,7 +54,7 @@ let make = () => {
}

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
Expand Down Expand Up @@ -97,7 +97,7 @@ let make = () => {
~logType=ERROR,
)
metadata->Utils.getDictFromJson->Dict.set("3dsMethodComp", "N"->JSON.Encode.string)
handlePostMessage([
messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", `3dsAuth`->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
Expand Down
4 changes: 2 additions & 2 deletions src/Types/GooglePayType.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type document
@val external document: document = "document"
@send external getElementById: (document, string) => element = "getElementById"
type client = {
isReadyToPay: JSON.t => Promise.t<JSON.t>,
isReadyToPay: JSON.t => promise<JSON.t>,
createButton: JSON.t => Dom.element,
loadPaymentData: JSON.t => Promise.t<Fetch.Response.t>,
loadPaymentData: JSON.t => promise<Fetch.Response.t>,
}
@new external google: JSON.t => client = "google.payments.api.PaymentsClient"
let getLabel = (var: PaymentType.googlePayStyleType) => {
Expand Down
Loading

0 comments on commit 827ae3a

Please sign in to comment.