From a8cc22972f9da470f342f8dc3860098c82d608f6 Mon Sep 17 00:00:00 2001 From: Arush Date: Fri, 19 Apr 2024 01:23:24 +0530 Subject: [PATCH] fix(orcalogger): added support for Elements Source string --- src/App.res | 2 +- src/CardTheme.res | 15 --------------- src/Components/SavedMethods.res | 2 +- src/LoaderController.res | 4 ++-- src/Types/CardThemeType.res | 30 +++++++++++++++++++++++++++++ src/orca-log-catcher/OrcaLogger.res | 15 ++++++++++++++- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/App.res b/src/App.res index 3f13ef226..539bd21c1 100644 --- a/src/App.res +++ b/src/App.res @@ -5,7 +5,7 @@ let make = () => { let setLoggerState = Recoil.useSetRecoilState(RecoilAtoms.loggerAtom) let paymentMode = CardUtils.getQueryParamsDictforKey(url.search, "componentName") - let paymentType = paymentMode->CardTheme.getPaymentMode + let paymentType = paymentMode->CardThemeType.getPaymentMode let (logger, initTimestamp) = React.useMemo0(() => { (OrcaLogger.make(~source=Elements(paymentType), ()), Date.now()) }) diff --git a/src/CardTheme.res b/src/CardTheme.res index 257c8154d..1b1e3e0e1 100644 --- a/src/CardTheme.res +++ b/src/CardTheme.res @@ -32,21 +32,6 @@ let getShowLoader = (str, logger) => { } } -let getPaymentMode = val => { - switch val { - | "card" => Card - | "payment" => Payment - | "cardNumber" => CardNumberElement - | "cardExpiry" => CardExpiryElement - | "cardCvc" => CardCVCElement - | "googlePay" => GooglePayElement - | "payPal" => PayPalElement - | "applePay" => ApplePayElement - | "paymentRequestButtons" => PaymentRequestButtonsElement - | _ => NONE - } -} - let defaultAppearance = { theme: Default, variables: DefaultTheme.default, diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res index 12c0729b4..ac6b6eb75 100644 --- a/src/Components/SavedMethods.res +++ b/src/Components/SavedMethods.res @@ -55,7 +55,7 @@ let make = ( | Some(ele) => ele | None => "" }->getCardType, - ""->CardTheme.getPaymentMode, + ""->CardThemeType.getPaymentMode, ) } let isActive = token == obj.paymentToken diff --git a/src/LoaderController.res b/src/LoaderController.res index a12aaac7a..2a8aba774 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -73,7 +73,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let updateOptions = dict => { let optionsDict = dict->getDictFromObj("options") - switch paymentMode->CardTheme.getPaymentMode { + switch paymentMode->CardThemeType.getPaymentMode { | CardNumberElement | CardExpiryElement | CardCVCElement @@ -180,7 +180,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime if dict->Dict.toArray->Array.length > 0 { generateStyleSheet("", dict, "themestyle") } - switch paymentMode->CardTheme.getPaymentMode { + switch paymentMode->CardThemeType.getPaymentMode { | Payment => () | _ => let styleClass = [ diff --git a/src/Types/CardThemeType.res b/src/Types/CardThemeType.res index c7e1c8406..3290cfde1 100644 --- a/src/Types/CardThemeType.res +++ b/src/Types/CardThemeType.res @@ -84,3 +84,33 @@ type configClass = { fonts: array, loader: showLoader, } + +let getPaymentMode = val => { + switch val { + | "card" => Card + | "payment" => Payment + | "cardNumber" => CardNumberElement + | "cardExpiry" => CardExpiryElement + | "cardCvc" => CardCVCElement + | "googlePay" => GooglePayElement + | "payPal" => PayPalElement + | "applePay" => ApplePayElement + | "paymentRequestButtons" => PaymentRequestButtonsElement + | _ => NONE + } +} + +let getPaymentModeToStrMapper = val => { + switch val { + | Card => "Card" + | Payment => "Payment" + | CardNumberElement => "CardNumberElement" + | CardExpiryElement => "CardExpiryElement" + | CardCVCElement => "CardCVCElement" + | GooglePayElement => "GooglePayElement" + | PayPalElement => "PayPalElement" + | ApplePayElement => "ApplePayElement" + | PaymentRequestButtonsElement => "PaymentRequestButtonsElement" + | NONE => "None" + } +} diff --git a/src/orca-log-catcher/OrcaLogger.res b/src/orca-log-catcher/OrcaLogger.res index 557fa712b..e39d69e62 100644 --- a/src/orca-log-catcher/OrcaLogger.res +++ b/src/orca-log-catcher/OrcaLogger.res @@ -133,6 +133,12 @@ let convertToScreamingSnakeCase = text => { text->String.trim->String.replaceRegExp(%re("/ /g"), "_")->String.toUpperCase } +let toSnakeCaseWithSeparator = (str, separator) => { + str->Js.String2.unsafeReplaceBy0(%re("/[A-Z]/g"), (letter, _, _) => + `${separator}${letter->String.toLowerCase}` + ) +} + type maskableDetails = Email | CardDetails type source = Loader | Elements(CardThemeType.mode) | Headless let logInfo = log => { @@ -299,7 +305,14 @@ let getRefFromOption = val => { let getSourceString = source => { switch source { | Loader => "orca-loader" - | Elements(_) => "orca-element" + | Elements(paymentMode) => { + let formattedPaymentMode = + paymentMode + ->CardThemeType.getPaymentModeToStrMapper + ->toSnakeCaseWithSeparator("-") + + "orca" ++ formattedPaymentMode + } | Headless => "headless" } }