Skip to content

Commit

Permalink
fix(orcalogger): added support for Elements Source string
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Apr 22, 2024
1 parent d567f2d commit 2f8d5d7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
15 changes: 0 additions & 15 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let make = (
| Some(ele) => ele
| None => ""
}->getCardType,
""->CardTheme.getPaymentMode,
""->CardThemeType.getPaymentMode,
)
}
let isActive = token == obj.paymentToken
Expand Down
4 changes: 2 additions & 2 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
30 changes: 30 additions & 0 deletions src/Types/CardThemeType.res
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,33 @@ type configClass = {
fonts: array<fonts>,
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"
}
}
17 changes: 15 additions & 2 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -298,8 +304,15 @@ let getRefFromOption = val => {
}
let getSourceString = source => {
switch source {
| Loader => "orca-loader"
| Elements(_) => "orca-element"
| Loader => "hyper_loader"
| Elements(paymentMode) => {
let formattedPaymentMode =
paymentMode
->CardThemeType.getPaymentModeToStrMapper
->toSnakeCaseWithSeparator("_")

"hyper" ++ formattedPaymentMode
}
| Headless => "headless"
}
}
Expand Down

0 comments on commit 2f8d5d7

Please sign in to comment.