Skip to content

Commit

Permalink
chore: removing two utils and making one utility file
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Apr 5, 2024
1 parent 9385e42 commit d7bdcc8
Show file tree
Hide file tree
Showing 21 changed files with 436 additions and 457 deletions.
40 changes: 21 additions & 19 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -316,29 +316,30 @@ let calculateLuhn = value => {

let getCardBrandIcon = (cardType, paymentType) => {
open CardThemeType
open Utils
switch cardType {
| VISA => <Icon size=Utils.brandIconSize name="visa-light" />
| MASTERCARD => <Icon size=Utils.brandIconSize name="mastercard" />
| AMEX => <Icon size=Utils.brandIconSize name="amex-light" />
| MAESTRO => <Icon size=Utils.brandIconSize name="maestro" />
| DINERSCLUB => <Icon size=Utils.brandIconSize name="diners" />
| DISCOVER => <Icon size=Utils.brandIconSize name="discover" />
| BAJAJ => <Icon size=Utils.brandIconSize name="card" />
| SODEXO => <Icon size=Utils.brandIconSize name="card" />
| RUPAY => <Icon size=Utils.brandIconSize name="rupay-card" />
| JCB => <Icon size=Utils.brandIconSize name="jcb-card" />
| CARTESBANCAIRES => <Icon size=Utils.brandIconSize name="card" />
| UNIONPAY => <Icon size=Utils.brandIconSize name="card" />
| INTERAC => <Icon size=Utils.brandIconSize name="interac" />
| VISA => <Icon size=brandIconSize name="visa-light" />
| MASTERCARD => <Icon size=brandIconSize name="mastercard" />
| AMEX => <Icon size=brandIconSize name="amex-light" />
| MAESTRO => <Icon size=brandIconSize name="maestro" />
| DINERSCLUB => <Icon size=brandIconSize name="diners" />
| DISCOVER => <Icon size=brandIconSize name="discover" />
| BAJAJ => <Icon size=brandIconSize name="card" />
| SODEXO => <Icon size=brandIconSize name="card" />
| RUPAY => <Icon size=brandIconSize name="rupay-card" />
| JCB => <Icon size=brandIconSize name="jcb-card" />
| CARTESBANCAIRES => <Icon size=brandIconSize name="card" />
| UNIONPAY => <Icon size=brandIconSize name="card" />
| INTERAC => <Icon size=brandIconSize name="interac" />
| NOTFOUND =>
switch paymentType {
| Payment => <Icon size=Utils.brandIconSize name="base-card" />
| Payment => <Icon size=brandIconSize name="base-card" />
| Card
| CardNumberElement
| CardExpiryElement
| CardCVCElement
| NONE =>
<Icon size=Utils.brandIconSize name="default-card" />
<Icon size=brandIconSize name="default-card" />
}
}
}
Expand Down Expand Up @@ -577,16 +578,17 @@ let postalRegex = (postalCodes: array<PostalCodeType.postalCodes>, ~country=?, (
}

let setRightIconForCvc = (~cardEmpty, ~cardInvalid, ~color, ~cardComplete) => {
open Utils
if cardEmpty {
<Icon size=Utils.brandIconSize name="cvc-empty" />
<Icon size=brandIconSize name="cvc-empty" />
} else if cardInvalid {
<div style={ReactDOMStyle.make(~color, ())}>
<Icon size=Utils.brandIconSize name="cvc-invalid" />
<Icon size=brandIconSize name="cvc-invalid" />
</div>
} else if cardComplete {
<Icon size=Utils.brandIconSize name="cvc-complete" />
<Icon size=brandIconSize name="cvc-complete" />
} else {
<Icon size=Utils.brandIconSize name="cvc-empty" />
<Icon size=brandIconSize name="cvc-empty" />
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let make = (~paymentType, ~className="") => {

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if line1.value == "" {
setLine1(prev => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BlikCodePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let make = () => {

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if blikCode.value == "" {
setblikCode(prev => {
Expand Down
18 changes: 7 additions & 11 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let make = (
~cvcProps=None,
~isBancontact=false,
) => {
open Utils
React.useEffect(() => {
setRequiredFieldsBody(_ => Dict.make())
None
Expand Down Expand Up @@ -125,9 +126,8 @@ let make = (

let (stateJson, setStatesJson) = React.useState(_ => None)

let bankNames =
Bank.getBanks(paymentMethodType)->Utils.getBankNames(paymentMethodTypes.bank_names)
let countryNames = Utils.getCountryNames(Country.getCountry(paymentMethodType))
let bankNames = Bank.getBanks(paymentMethodType)->getBankNames(paymentMethodTypes.bank_names)
let countryNames = getCountryNames(Country.getCountry(paymentMethodType))

let setCurrency = val => {
setCurrency(val)
Expand Down Expand Up @@ -226,11 +226,7 @@ let make = (
None
})

let _regex = CardUtils.postalRegex(
postalCodes,
~country={Utils.getCountryCode(country).isoAlpha2},
(),
)
let _regex = CardUtils.postalRegex(postalCodes, ~country={getCountryCode(country).isoAlpha2}, ())

let onPostalChange = ev => {
let val = ReactEvent.Form.target(ev)["value"]
Expand Down Expand Up @@ -282,7 +278,7 @@ let make = (
)

let submitCallback = DynamicFieldsUtils.useSubmitCallback()
Utils.useSubmitPaymentData(submitCallback)
useSubmitPaymentData(submitCallback)

let bottomElement = <InfoElement />

Expand Down Expand Up @@ -518,7 +514,7 @@ let make = (
fieldName=localeString.stateLabel
value=state
setValue=setState
options={options->Utils.getStateNames({
options={options->getStateNames({
value: country,
isValid: None,
errorString: "",
Expand Down Expand Up @@ -640,7 +636,7 @@ let make = (
fieldName=localeString.stateLabel
value=state
setValue=setState
options={options->Utils.getStateNames({
options={options->getStateNames({
value: country,
isValid: None,
errorString: "",
Expand Down
8 changes: 4 additions & 4 deletions src/Components/EmailPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ let make = (~paymentType) => {
let val: string = ReactEvent.Form.target(ev)["value"]
setEmail(prev => {
value: val,
isValid: val->Utils.isEmailValid,
errorString: val->Utils.isEmailValid->Option.getOr(false) ? "" : prev.errorString,
isValid: val->isEmailValid,
errorString: val->isEmailValid->Option.getOr(false) ? "" : prev.errorString,
})
}
let onBlur = ev => {
let val = ReactEvent.Focus.target(ev)["value"]
setEmail(prev => {
...prev,
isValid: val->Utils.isEmailValid,
isValid: val->isEmailValid,
})
}

Expand All @@ -42,7 +42,7 @@ let make = (~paymentType) => {

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if email.value == "" {
setEmail(prev => {
Expand Down
8 changes: 4 additions & 4 deletions src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Loader = {
@react.component
let make = () => {
open RecoilAtoms
open Utils
let (showLoader, setShowLoader) = React.useState(() => false)

let {themeObj, localeString} = configAtom->Recoil.useRecoilValueFromAtom
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom
let (isPayNowButtonDisable, setIsPayNowButtonDisable) = payNowButtonDisable->Recoil.useRecoilState
Expand All @@ -24,8 +24,8 @@ let make = () => {
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)

let handleMessage = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson->Utils.getStringFromJson("")->OrcaUtils.safeParse
let dict = json->Utils.getDictFromJson
let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse
let dict = json->getDictFromJson
switch dict->Dict.get("submitSuccessful") {
| Some(_) =>
setIsPayNowButtonDisable(_ => false)
Expand All @@ -38,7 +38,7 @@ let make = () => {
setIsPayNowButtonDisable(_ => true)
setShowLoader(_ => true)
EventListenerManager.addSmartEventListener("message", handleMessage, "onSubmitSuccessful")
Utils.handlePostMessage([("handleSdkConfirm", confirmPayload)])
handlePostMessage([("handleSdkConfirm", confirmPayload)])
}

<div className="flex flex-col gap-1 h-auto w-full items-center">
Expand Down
6 changes: 3 additions & 3 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ let make = (
~bodyArr=savedPaymentMethodBody
->Dict.fromArray
->JSON.Encode.object
->OrcaUtils.flattenObject(true)
->OrcaUtils.mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->OrcaUtils.getArrayOfTupleFromDict,
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
Expand Down
30 changes: 15 additions & 15 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let {config} = configAtom
let {iframeId} = keys

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

let setUserFullName = Recoil.useLoggedSetRecoilState(userFullName, "fullName", logger)
let setUserEmail = Recoil.useLoggedSetRecoilState(userEmailAddress, "email", logger)
Expand Down Expand Up @@ -56,7 +56,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
if optionsPayment.defaultValues.billingDetails.address.country === "" {
let clientTimeZone = CardUtils.dateTimeFormat().resolvedOptions().timeZone
let clientCountry = Utils.getClientCountry(clientTimeZone)
let clientCountry = getClientCountry(clientTimeZone)
setUserAddressCountry(prev => {
...prev,
value: clientCountry.countryName,
Expand Down Expand Up @@ -94,7 +94,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let (default, defaultRules) = (themeValues.default, themeValues.defaultRules)
let config = CardTheme.itemToObjMapper(paymentOptions, default, defaultRules, logger)

let optionsLocaleString = Utils.getWarningString(optionsDict, "locale", "", ~logger)
let optionsLocaleString = getWarningString(optionsDict, "locale", "", ~logger)

let optionsAppearance = CardTheme.getAppearance(
"appearance",
Expand Down Expand Up @@ -128,7 +128,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
logger.setLogInitiated()
let updatedState: PaymentType.loadType = switch paymentlist {
| Loading =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
showCardFormByDefault && checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
| x => x
}
let finalLoadLatency = if launchTime <= 0.0 {
Expand Down Expand Up @@ -174,7 +174,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
CardUtils.genreateFontsLink(config.fonts)
let dict = config.appearance.rules->getDictFromJson
if dict->Dict.toArray->Array.length > 0 {
Utils.generateStyleSheet("", dict, "themestyle")
generateStyleSheet("", dict, "themestyle")
}
switch paymentMode->CardTheme.getPaymentMode {
| Payment => ()
Expand All @@ -189,7 +189,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
->Array.map(item => {
let (class, dict) = item
if dict->Dict.toArray->Array.length > 0 {
Utils.generateStyleSheet(class, dict, "widgetstyle")->ignore
generateStyleSheet(class, dict, "widgetstyle")->ignore
}
})
->ignore
Expand Down Expand Up @@ -243,7 +243,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
logger.setMetadata(metadata)
}
if dict->getDictIsSome("paymentOptions") {
let paymentOptions = dict->Utils.getDictFromObj("paymentOptions")
let paymentOptions = dict->getDictFromObj("paymentOptions")

let clientSecret = getWarningString(paymentOptions, "clientSecret", "", ~logger)
setKeys(prev => {
Expand All @@ -252,7 +252,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
logger.setClientSecret(clientSecret)

switch OrcaUtils.getThemePromise(paymentOptions) {
switch getThemePromise(paymentOptions) {
| Some(promise) =>
promise
->then(res => {
Expand All @@ -267,7 +267,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
}
}
let newLaunchTime = dict->Utils.getFloat("launchTime", 0.0)
let newLaunchTime = dict->getFloat("launchTime", 0.0)
setLaunchTime(_ => newLaunchTime)
let initLoadlatency = Date.now() -. newLaunchTime
logger.setLogInfo(
Expand All @@ -293,7 +293,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
)
}
} else if dict->getDictIsSome("paymentOptions") {
let paymentOptions = dict->Utils.getDictFromObj("paymentOptions")
let paymentOptions = dict->getDictFromObj("paymentOptions")

let clientSecret = getWarningString(paymentOptions, "clientSecret", "", ~logger)
setKeys(prev => {
Expand All @@ -302,7 +302,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
logger.setClientSecret(clientSecret)

switch OrcaUtils.getThemePromise(paymentOptions) {
switch getThemePromise(paymentOptions) {
| Some(promise) =>
promise
->then(res => {
Expand Down Expand Up @@ -337,7 +337,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})
| None => ()
}
switch OrcaUtils.getThemePromise(optionsDict) {
switch getThemePromise(optionsDict) {
| Some(promise) =>
promise
->then(res => {
Expand Down Expand Up @@ -370,11 +370,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let updatedState: PaymentType.loadType =
list == Dict.make()->JSON.Encode.object
? LoadError(list)
: switch list->Utils.getDictFromJson->Dict.get("error") {
: switch list->getDictFromJson->Dict.get("error") {
| Some(_) => LoadError(list)
| None =>
let isNonEmptyPaymentMethodList =
list->Utils.getDictFromJson->Utils.getArray("payment_methods")->Array.length > 0
list->getDictFromJson->getArray("payment_methods")->Array.length > 0
isNonEmptyPaymentMethodList ? Loaded(list) : LoadError(list)
}

Expand Down Expand Up @@ -489,7 +489,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}

React.useEffect(() => {
Utils.handlePostMessage([
handlePostMessage([
("iframeHeight", (divH +. 1.0)->JSON.Encode.float),
("iframeId", iframeId->JSON.Encode.string),
])
Expand Down
8 changes: 4 additions & 4 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ let make = (
requestBody
->Dict.fromArray
->JSON.Encode.object
->OrcaUtils.flattenObject(true)
->OrcaUtils.mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->OrcaUtils.getArrayOfTupleFromDict
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
intent(
~bodyArr=requiredFieldsBodyArr,
~confirmParam={
Expand Down Expand Up @@ -246,7 +246,7 @@ let make = (
)
setApplePayClicked(_ => true)
open Promise
OrcaUtils.makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)
makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)
->then(result => {
let result = result->JSON.Decode.bool->Option.getOr(false)
if result {
Expand Down
6 changes: 3 additions & 3 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ let make = (
(isBancontact ? banContactBody : cardBody)
->Dict.fromArray
->JSON.Encode.object
->OrcaUtils.flattenObject(true)
->OrcaUtils.mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->OrcaUtils.getArrayOfTupleFromDict
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
},
~confirmParam=confirm.confirmParams,
~handleUserError=false,
Expand Down
Loading

0 comments on commit d7bdcc8

Please sign in to comment.