From 021a9dbe797872e7833104a0a64f85e82c3e344f Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Tue, 15 Oct 2024 18:44:07 +0530 Subject: [PATCH] refactor: some code name changes --- src/LoaderController.res | 10 ++++++---- src/Payments/ApplePay.res | 4 +++- src/Payments/GPay.res | 2 +- src/Payments/KlarnaSDK.res | 8 ++++---- src/Payments/PayPal.res | 2 +- src/Payments/PaypalSDK.res | 4 +++- src/Utilities/RecoilAtoms.res | 2 +- src/orca-loader/Elements.res | 4 ++-- src/orca-loader/LoaderPaymentElement.res | 7 ++++--- 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/LoaderController.res b/src/LoaderController.res index 9fd0f839..838cedee 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -38,7 +38,9 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let (isCompleteCallbackUsed, setIsCompleteCallbackUsed) = Recoil.useRecoilState( isCompleteCallbackUsed, ) - let (isSDKHandleClickUsed, setIsSDKHandleClickUsed) = Recoil.useRecoilState(isSDKHandleClick) + let (isPaymentButtonHandlerProvided, setIsPaymentButtonHandlerProvided) = Recoil.useRecoilState( + isPaymentButtonHandlerProvidedAtom, + ) let optionsCallback = (optionsPayment: PaymentType.options) => { [ @@ -254,9 +256,9 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let isCallbackUsedVal = dict->Utils.getBool("onCompleteDoThisUsed", false) setIsCompleteCallbackUsed(_ => isCallbackUsedVal) } - if dict->getDictIsSome("onSDKHandleClickIsUsed") { - let isSDKClick = dict->Utils.getBool("onSDKHandleClickIsUsed", false) - setIsSDKHandleClickUsed(_ => isSDKClick) + if dict->getDictIsSome("isPaymentButtonHandlerProvided") { + let isSDKClick = dict->Utils.getBool("isPaymentButtonHandlerProvided", false) + setIsPaymentButtonHandlerProvided(_ => isSDKClick) } if dict->getDictIsSome("paymentOptions") { let paymentOptions = dict->getDictFromObj("paymentOptions") diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index 86837911..0152259e 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -5,7 +5,9 @@ let make = (~sessionObj: option, ~walletOptions, ~paymentType: CardTheme let url = RescriptReactRouter.useUrl() let componentName = CardUtils.getQueryParamsDictforKey(url.search, "componentName") let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) - let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(RecoilAtoms.isSDKHandleClick) + let sdkHandleIsThere = Recoil.useRecoilValueFromAtom( + RecoilAtoms.isPaymentButtonHandlerProvidedAtom, + ) let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) let isApplePayReady = Recoil.useRecoilValueFromAtom(RecoilAtoms.isApplePayReady) let setIsShowOrPayUsing = Recoil.useSetRecoilState(RecoilAtoms.isShowOrPayUsing) diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index ba0883e5..d9e0c69d 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -15,7 +15,7 @@ let make = ( let componentName = CardUtils.getQueryParamsDictforKey(url.search, "componentName") let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) let {iframeId} = Recoil.useRecoilValueFromAtom(keys) - let isSDKHandleClick = Recoil.useRecoilValueFromAtom(RecoilAtoms.isSDKHandleClick) + let isSDKHandleClick = Recoil.useRecoilValueFromAtom(isPaymentButtonHandlerProvidedAtom) let {publishableKey} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Gpay) diff --git a/src/Payments/KlarnaSDK.res b/src/Payments/KlarnaSDK.res index dd7e774c..a53771a7 100644 --- a/src/Payments/KlarnaSDK.res +++ b/src/Payments/KlarnaSDK.res @@ -9,12 +9,12 @@ open KlarnaSDKTypes let make = (~sessionObj: SessionsType.token) => { let url = RescriptReactRouter.useUrl() let componentName = CardUtils.getQueryParamsDictforKey(url.search, "componentName") - let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) - let setIsShowOrPayUsing = Recoil.useSetRecoilState(RecoilAtoms.isShowOrPayUsing) - let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(RecoilAtoms.isSDKHandleClick) + let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) + let setIsShowOrPayUsing = Recoil.useSetRecoilState(isShowOrPayUsing) + let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(isPaymentButtonHandlerProvidedAtom) let {publishableKey} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) - let isManualRetryEnabled = Recoil.useRecoilValueFromAtom(RecoilAtoms.isManualRetryEnabled) + let isManualRetryEnabled = Recoil.useRecoilValueFromAtom(isManualRetryEnabled) let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Other) let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let status = CommonHooks.useScript("https://x.klarnacdn.net/kp/lib/v1/api.js") // Klarna SDK script diff --git a/src/Payments/PayPal.res b/src/Payments/PayPal.res index a7233a97..f7edbb5f 100644 --- a/src/Payments/PayPal.res +++ b/src/Payments/PayPal.res @@ -14,7 +14,7 @@ let payPalIcon = let make = () => { let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) let (paypalClicked, setPaypalClicked) = React.useState(_ => false) - let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(RecoilAtoms.isSDKHandleClick) + let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(isPaymentButtonHandlerProvidedAtom) let {publishableKey} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) let areOneClickWalletsRendered = Recoil.useSetRecoilState(areOneClickWalletsRendered) diff --git a/src/Payments/PaypalSDK.res b/src/Payments/PaypalSDK.res index 71ee290b..1abbc288 100644 --- a/src/Payments/PaypalSDK.res +++ b/src/Payments/PaypalSDK.res @@ -5,7 +5,9 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) = let {iframeId, publishableKey, sdkHandleOneClickConfirmPayment} = Recoil.useRecoilValueFromAtom( RecoilAtoms.keys, ) - let sdkHandleIsThere = Recoil.useRecoilValueFromAtom(RecoilAtoms.isSDKHandleClick) + let sdkHandleIsThere = Recoil.useRecoilValueFromAtom( + RecoilAtoms.isPaymentButtonHandlerProvidedAtom, + ) let (loggerState, _setLoggerState) = Recoil.useRecoilState(RecoilAtoms.loggerAtom) let areOneClickWalletsRendered = Recoil.useSetRecoilState(RecoilAtoms.areOneClickWalletsRendered) let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) diff --git a/src/Utilities/RecoilAtoms.res b/src/Utilities/RecoilAtoms.res index 7b5ee98f..d1207655 100644 --- a/src/Utilities/RecoilAtoms.res +++ b/src/Utilities/RecoilAtoms.res @@ -74,7 +74,7 @@ let userPixKey = Recoil.atom("userPixKey", defaultFieldValues) let userPixCPF = Recoil.atom("userPixCPF", defaultFieldValues) let userPixCNPJ = Recoil.atom("userPixCNPJ", defaultFieldValues) let isCompleteCallbackUsed = Recoil.atom("isCompleteCallbackUsed", false) -let isSDKHandleClick = Recoil.atom("isSDKHandleClick", false) +let isPaymentButtonHandlerProvidedAtom = Recoil.atom("isPaymentButtonHandlerProvidedAtom", false) type areOneClickWalletsRendered = { isGooglePay: bool, diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index f1967e0c..110353b7 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -317,8 +317,8 @@ let make = ( ("launchTime", launchTime->JSON.Encode.float), ("customBackendUrl", customBackendUrl->JSON.Encode.string), ( - "onSDKHandleClickIsUsed", - LoaderPaymentElement.onSDKHandleClickIsUsed.contents->JSON.Encode.bool, + "isPaymentButtonHandlerProvided", + LoaderPaymentElement.isPaymentButtonHandlerProvided.contents->JSON.Encode.bool, ), ( "onCompleteDoThisUsed", diff --git a/src/orca-loader/LoaderPaymentElement.res b/src/orca-loader/LoaderPaymentElement.res index 14f4f839..a09d0e8d 100644 --- a/src/orca-loader/LoaderPaymentElement.res +++ b/src/orca-loader/LoaderPaymentElement.res @@ -7,7 +7,7 @@ open Identity external writeText: string => promise<'a> = "writeText" let onCompleteDoThisUsed = ref(false) -let onSDKHandleClickIsUsed = ref(false) +let isPaymentButtonHandlerProvided = ref(false) let make = ( componentType, options, @@ -53,7 +53,8 @@ let make = ( let dict = json->getDictFromJson if dict->Dict.get("oneClickConfirmTriggered")->Option.isSome { switch currEventHandler.contents { - | Some(eH) => asyncWrapper(eH) + | Some(eH) => + asyncWrapper(eH) ->Promise.then(() => { let msg = [("walletClickEvent", true->JSON.Encode.bool)]->Dict.fromArray event.source->Window.sendPostMessage(msg) @@ -71,7 +72,7 @@ let make = ( let onSDKHandleClick = (eventHandler: option RescriptCore.Promise.t<'a>>) => { currEventHandler := eventHandler if eventHandler->Option.isSome { - onSDKHandleClickIsUsed := true + isPaymentButtonHandlerProvided := true } }