From 44f72856040238b53f28c31ca01659e79d3bd13e Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Tue, 16 Apr 2024 16:32:55 +0530 Subject: [PATCH 1/2] refactor: country props drilling removal --- src/Components/AccordionContainer.res | 4 +- src/Components/Block.res | 7 +- src/Payment.res | 30 +--- src/PaymentElement.res | 14 +- src/PaymentElementRenderer.res | 3 +- src/PaymentElementRenderer.resi | 1 - src/PaymentElementRendererLazy.res | 1 - src/PaymentOptions.res | 2 +- src/Payments/KlarnaPayment.res | 4 +- src/Payments/KlarnaPaymentLazy.res | 1 - src/Payments/PayPal.res | 2 +- src/Payments/PaymentMethodsWrapper.res | 4 +- src/Payments/SepaBankTransfer.res | 8 +- src/Payments/SepaBankTransfer.resi | 6 +- src/Payments/SepaBankTransferLazy.res | 1 - src/RenderPaymentMethods.res | 3 +- src/Utilities/DynamicFieldsUtils.res | 204 ++++++++++++------------- src/Utilities/PaymentHelpers.res | 22 +-- 18 files changed, 131 insertions(+), 186 deletions(-) diff --git a/src/Components/AccordionContainer.res b/src/Components/AccordionContainer.res index cde3d8790..4914ab034 100644 --- a/src/Components/AccordionContainer.res +++ b/src/Components/AccordionContainer.res @@ -2,7 +2,7 @@ open RecoilAtoms module Loader = { @react.component let make = (~cardShimmerCount) => { - let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) + let list = Recoil.useRecoilValueFromAtom(list) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) let {layout} = Recoil.useRecoilValueFromAtom(optionAtom) let layoutClass = CardUtils.getLayoutClass(layout) @@ -61,7 +61,7 @@ module Loader = { @react.component let make = (~paymentOptions: array, ~checkoutEle: React.element) => { let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) - let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) + let list = Recoil.useRecoilValueFromAtom(list) let {layout} = Recoil.useRecoilValueFromAtom(optionAtom) let layoutClass = CardUtils.getLayoutClass(layout) let (showMore, setShowMore) = React.useState(_ => false) diff --git a/src/Components/Block.res b/src/Components/Block.res index 333694d02..3dfbb4398 100644 --- a/src/Components/Block.res +++ b/src/Components/Block.res @@ -1,10 +1,5 @@ @react.component -let make = ( - ~topElement: option=?, - ~bottomElement: option=?, - ~padding="p-5", - ~className="", -) => { +let make = (~topElement=?, ~bottomElement=?, ~padding="p-5", ~className="") => { let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) let topBlock = switch topElement { | Some(ele) => ele diff --git a/src/Payment.res b/src/Payment.res index 2c8b333a0..8d15eec44 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -12,10 +12,10 @@ let setUserError = message => { let make = (~paymentMode, ~integrateError, ~logger) => { let {localeString} = Recoil.useRecoilValueFromAtom(configAtom) let keys = Recoil.useRecoilValueFromAtom(keys) - let cardScheme = Recoil.useRecoilValueFromAtom(RecoilAtoms.cardBrand) - let showFields = Recoil.useRecoilValueFromAtom(RecoilAtoms.showCardFieldsAtom) + let cardScheme = Recoil.useRecoilValueFromAtom(cardBrand) + let showFields = Recoil.useRecoilValueFromAtom(showCardFieldsAtom) let selectedOption = Recoil.useRecoilValueFromAtom(selectedOptionAtom) - let paymentToken = Recoil.useRecoilValueFromAtom(RecoilAtoms.paymentTokenAtom) + let paymentToken = Recoil.useRecoilValueFromAtom(paymentTokenAtom) let (token, _) = paymentToken let {iframeId} = keys @@ -56,12 +56,6 @@ let make = (~paymentMode, ~integrateError, ~logger) => { cardBrand->getCardType }, [cardBrand]) - let clientTimeZone = dateTimeFormat().resolvedOptions().timeZone - let clientCountry = Utils.getClientCountry(clientTimeZone) - - let countryNames = Utils.getCountryNames(Country.country) - let countryProps = (clientCountry.countryName, countryNames) - let (postalCodes, setPostalCodes) = React.useState(_ => [PostalCodeType.defaultPostalCode]) React.useEffect(() => { @@ -343,16 +337,12 @@ let make = (~paymentMode, ~integrateError, ~logger) => { }, (cardNumber, cvcNumber, cardExpiry, isCVCValid, isExpiryValid, isCardValid)) React.useEffect(() => { - setCardError(_ => - isCardValid->Option.getOr(true) ? "" : localeString.inValidCardErrorText - ) + setCardError(_ => isCardValid->Option.getOr(true) ? "" : localeString.inValidCardErrorText) None }, [isCardValid]) React.useEffect(() => { - setCvcError(_ => - isCVCValid->Option.getOr(true) ? "" : localeString.inCompleteCVCErrorText - ) + setCvcError(_ => isCVCValid->Option.getOr(true) ? "" : localeString.inCompleteCVCErrorText) None }, [isCVCValid]) @@ -427,15 +417,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => { } else { } } diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 756b3e19a..73a82e5a1 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -8,13 +8,7 @@ let cardsToRender = (width: int) => { noOfCards } @react.component -let make = ( - ~cardProps, - ~expiryProps, - ~cvcProps, - ~countryProps, - ~paymentType: CardThemeType.mode, -) => { +let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mode) => { let sessionsObj = Recoil.useRecoilValueFromAtom(sessions) let { showCardFormByDefault, @@ -307,12 +301,12 @@ let make = ( | None => - + } | _ => - + }} @@ -322,7 +316,7 @@ let make = ( | SepaTransfer => - + | BacsTransfer => diff --git a/src/PaymentElementRenderer.res b/src/PaymentElementRenderer.res index df02ca75b..ed3bbfbd9 100644 --- a/src/PaymentElementRenderer.res +++ b/src/PaymentElementRenderer.res @@ -5,7 +5,6 @@ let make = ( ~cardProps: CardUtils.cardProps, ~expiryProps: CardUtils.expiryProps, ~cvcProps: CardUtils.cvcProps, - ~countryProps: (string, array), ) => { let _cardsToRender = width => { (width - 40) / 110 @@ -18,7 +17,7 @@ let make = ( - | _ => + | _ => } } diff --git a/src/PaymentElementRenderer.resi b/src/PaymentElementRenderer.resi index 0b212b402..a52c10213 100644 --- a/src/PaymentElementRenderer.resi +++ b/src/PaymentElementRenderer.resi @@ -4,5 +4,4 @@ let default: ( ~cardProps: CardUtils.cardProps, ~expiryProps: CardUtils.expiryProps, ~cvcProps: CardUtils.cvcProps, - ~countryProps: (string, array), ) => React.element diff --git a/src/PaymentElementRendererLazy.res b/src/PaymentElementRendererLazy.res index f9ac19b16..c49f5ca1a 100644 --- a/src/PaymentElementRendererLazy.res +++ b/src/PaymentElementRendererLazy.res @@ -5,7 +5,6 @@ type props = { cardProps: CardUtils.cardProps, expiryProps: CardUtils.expiryProps, cvcProps: CardUtils.cvcProps, - countryProps: (string, array), } let make: props => React.element = reactLazy(() => import_("./PaymentElementRenderer.bs.js")) diff --git a/src/PaymentOptions.res b/src/PaymentOptions.res index e8b3638a8..a578136ca 100644 --- a/src/PaymentOptions.res +++ b/src/PaymentOptions.res @@ -2,7 +2,7 @@ open RecoilAtoms module TabLoader = { @react.component let make = (~cardShimmerCount) => { - let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) + let list = Recoil.useRecoilValueFromAtom(list) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) open PaymentType open PaymentElementShimmer diff --git a/src/Payments/KlarnaPayment.res b/src/Payments/KlarnaPayment.res index 9581c9f00..7a6c1f802 100644 --- a/src/Payments/KlarnaPayment.res +++ b/src/Payments/KlarnaPayment.res @@ -1,7 +1,7 @@ open PaymentType open RecoilAtoms @react.component -let make = (~paymentType, ~countryProps, ~list: PaymentMethodsRecord.list) => { +let make = (~paymentType, ~list: PaymentMethodsRecord.list) => { let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom) let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom) let {fields} = Recoil.useRecoilValueFromAtom(optionAtom) @@ -15,7 +15,7 @@ let make = (~paymentType, ~countryProps, ~list: PaymentMethodsRecord.list) => { let (fullName, _) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState) let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState) - let (_clientCountry, countryNames) = countryProps + let countryNames = Utils.getCountryNames(Country.country) let (country, setCountry) = Recoil.useRecoilState(userCountry) let setCountry = val => { diff --git a/src/Payments/KlarnaPaymentLazy.res b/src/Payments/KlarnaPaymentLazy.res index a856702aa..e773d6861 100644 --- a/src/Payments/KlarnaPaymentLazy.res +++ b/src/Payments/KlarnaPaymentLazy.res @@ -3,7 +3,6 @@ open LazyUtils type props = { paymentType: CardThemeType.mode, list: PaymentMethodsRecord.list, - countryProps: (string, array), } let make: props => React.element = reactLazy(() => import_("./KlarnaPayment.bs.js")) diff --git a/src/Payments/PayPal.res b/src/Payments/PayPal.res index 2ffb110ff..a8cbee38d 100644 --- a/src/Payments/PayPal.res +++ b/src/Payments/PayPal.res @@ -16,7 +16,7 @@ let make = (~list: PaymentMethodsRecord.list) => { let (paypalClicked, setPaypalClicked) = React.useState(_ => false) let {publishableKey, sdkHandleOneClickConfirmPayment} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) - let areOneClickWalletsRendered = Recoil.useSetRecoilState(RecoilAtoms.areOneClickWalletsRendered) + let areOneClickWalletsRendered = Recoil.useSetRecoilState(areOneClickWalletsRendered) let (_, _, labelType) = options.wallets.style.type_ let _label = switch labelType { | Paypal(val) => val->PaypalSDKTypes.getLabel diff --git a/src/Payments/PaymentMethodsWrapper.res b/src/Payments/PaymentMethodsWrapper.res index 6367a0fee..5a2ddb197 100644 --- a/src/Payments/PaymentMethodsWrapper.res +++ b/src/Payments/PaymentMethodsWrapper.res @@ -40,8 +40,8 @@ let make = ( let cleanPhoneNumber = str => str->String.replaceRegExp(%re("/\s/g"), "") let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make()) - let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid) - let areRequiredFieldsEmpty = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsEmpty) + let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(areRequiredFieldsValid) + let areRequiredFieldsEmpty = Recoil.useRecoilValueFromAtom(areRequiredFieldsEmpty) let complete = areRequiredFieldsValid diff --git a/src/Payments/SepaBankTransfer.res b/src/Payments/SepaBankTransfer.res index d1fdea4f9..3cda203f3 100644 --- a/src/Payments/SepaBankTransfer.res +++ b/src/Payments/SepaBankTransfer.res @@ -2,11 +2,7 @@ open RecoilAtoms open Utils @react.component -let make = ( - ~paymentType: CardThemeType.mode, - ~list: PaymentMethodsRecord.list, - ~countryProps: (string, array), -) => { +let make = (~paymentType, ~list) => { let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let {fields} = Recoil.useRecoilValueFromAtom(optionAtom) let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) @@ -19,7 +15,7 @@ let make = ( ~billingDetails=fields.billingDetails, ~logger=loggerState, ) - let (_clientCountry, countryNames) = countryProps + let countryNames = Utils.getCountryNames(Country.country) let setComplete = Recoil.useSetRecoilState(fieldsComplete) let clientCountryCode = Country.country diff --git a/src/Payments/SepaBankTransfer.resi b/src/Payments/SepaBankTransfer.resi index b9d7e1996..8cebb61b1 100644 --- a/src/Payments/SepaBankTransfer.resi +++ b/src/Payments/SepaBankTransfer.resi @@ -1,6 +1,2 @@ @react.component -let default: ( - ~paymentType: CardThemeType.mode, - ~list: PaymentMethodsRecord.list, - ~countryProps: (string, array), -) => React.element +let default: (~paymentType: CardThemeType.mode, ~list: PaymentMethodsRecord.list) => React.element diff --git a/src/Payments/SepaBankTransferLazy.res b/src/Payments/SepaBankTransferLazy.res index 89fe4e117..ed4a07498 100644 --- a/src/Payments/SepaBankTransferLazy.res +++ b/src/Payments/SepaBankTransferLazy.res @@ -3,7 +3,6 @@ open LazyUtils type props = { paymentType: CardThemeType.mode, list: PaymentMethodsRecord.list, - countryProps: (string, array), } let make: props => React.element = reactLazy(() => import_("./SepaBankTransfer.bs.js")) diff --git a/src/RenderPaymentMethods.res b/src/RenderPaymentMethods.res index 4e207cb39..9e72ab009 100644 --- a/src/RenderPaymentMethods.res +++ b/src/RenderPaymentMethods.res @@ -8,7 +8,6 @@ let make = ( ~zipProps, ~handleElementFocus, ~blurState, - ~countryProps, ~isFocus, ) => { let {showLoader} = Recoil.useRecoilValueFromAtom(configAtom) @@ -85,7 +84,7 @@ let make = ( fallback={ }> - + | CardNumberElement => { let fieldNameArr = field.value->String.split(" ") let requiredFieldsArr = item.required_field->String.split(".") @@ -107,22 +109,22 @@ let useRequiredFieldsEmptyAndValid = ( ~cardExpiry, ~cvcNumber, ) => { - let email = Recoil.useRecoilValueFromAtom(RecoilAtoms.userEmailAddress) - let fullName = Recoil.useRecoilValueFromAtom(RecoilAtoms.userFullName) - let billingName = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBillingName) - let line1 = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressline1) - let line2 = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressline2) - let phone = Recoil.useRecoilValueFromAtom(RecoilAtoms.userPhoneNumber) - let state = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressState) - let city = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressCity) - let postalCode = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressPincode) - let blikCode = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBlikCode) - let country = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCountry) - let selectedBank = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBank) - let currency = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCurrency) - let setAreRequiredFieldsValid = Recoil.useSetRecoilState(RecoilAtoms.areRequiredFieldsValid) - let setAreRequiredFieldsEmpty = Recoil.useSetRecoilState(RecoilAtoms.areRequiredFieldsEmpty) - let {billingAddress} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) + let email = Recoil.useRecoilValueFromAtom(userEmailAddress) + let fullName = Recoil.useRecoilValueFromAtom(userFullName) + let billingName = Recoil.useRecoilValueFromAtom(userBillingName) + let line1 = Recoil.useRecoilValueFromAtom(userAddressline1) + let line2 = Recoil.useRecoilValueFromAtom(userAddressline2) + let phone = Recoil.useRecoilValueFromAtom(userPhoneNumber) + let state = Recoil.useRecoilValueFromAtom(userAddressState) + let city = Recoil.useRecoilValueFromAtom(userAddressCity) + let postalCode = Recoil.useRecoilValueFromAtom(userAddressPincode) + let blikCode = Recoil.useRecoilValueFromAtom(userBlikCode) + let country = Recoil.useRecoilValueFromAtom(userCountry) + let selectedBank = Recoil.useRecoilValueFromAtom(userBank) + let currency = Recoil.useRecoilValueFromAtom(userCurrency) + let setAreRequiredFieldsValid = Recoil.useSetRecoilState(areRequiredFieldsValid) + let setAreRequiredFieldsEmpty = Recoil.useSetRecoilState(areRequiredFieldsEmpty) + let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom) let fieldsArrWithBillingAddress = fieldsArr->addBillingAddressIfUseBillingAddress(billingAddress) @@ -141,8 +143,7 @@ let useRequiredFieldsEmptyAndValid = ( | PhoneNumber => phone.value !== "" | StateAndCity => state.value !== "" && city.value !== "" | CountryAndPincode(countryArr) => - (country !== "" || countryArr->Array.length === 0) && - postalCode.value !== "" + (country !== "" || countryArr->Array.length === 0) && postalCode.value !== "" | AddressCity => city.value !== "" | AddressPincode => postalCode.value !== "" @@ -161,44 +162,47 @@ let useRequiredFieldsEmptyAndValid = ( }) setAreRequiredFieldsValid(_ => areRequiredFieldsValid) - let areRequiredFieldsEmpty = - fieldsArrWithBillingAddress->Array.reduce(false, (acc, paymentMethodFields: PaymentMethodsRecord.paymentMethodsFields) => { - acc || - switch (paymentMethodFields) { - | Email => email.value === "" - | FullName => fullName.value === "" - | Country => country === "" && countryNames->Array.length > 0 - | AddressCountry(countryArr) => country === "" && countryArr->Array.length > 0 - | BillingName => billingName.value === "" - | AddressLine1 => line1.value === "" - | AddressLine2 => !billingAddress.isUseBillingAddress && line2.value === "" - | Bank => selectedBank === "" && bankNames->Array.length > 0 - | StateAndCity => city.value === "" || state.value === "" - | CountryAndPincode(countryArr) => - (country === "" && countryArr->Array.length > 0) || postalCode.value === "" - | PhoneNumber => phone.value === "" - | AddressCity => city.value === "" - | AddressPincode => postalCode.value === "" - | AddressState => state.value === "" - | BlikCode => blikCode.value === "" - | Currency(currencyArr) => currency === "" && currencyArr->Array.length > 0 - | CardNumber => cardNumber === "" - | CardExpiryMonth => - let (month, _) = CardUtils.getExpiryDates(cardExpiry) - month === "" - | CardExpiryYear => - let (_, year) = CardUtils.getExpiryDates(cardExpiry) - year === "" - | CardExpiryMonthAndYear => - let (month, year) = CardUtils.getExpiryDates(cardExpiry) - month === "" || year === "" - | CardCvc => cvcNumber === "" - | CardExpiryAndCvc => - let (month, year) = CardUtils.getExpiryDates(cardExpiry) - month === "" || year === "" || cvcNumber === "" - | _ => false - } - }) + let areRequiredFieldsEmpty = fieldsArrWithBillingAddress->Array.reduce(false, ( + acc, + paymentMethodFields: PaymentMethodsRecord.paymentMethodsFields, + ) => { + open CardUtils + acc || + switch paymentMethodFields { + | Email => email.value === "" + | FullName => fullName.value === "" + | Country => country === "" && countryNames->Array.length > 0 + | AddressCountry(countryArr) => country === "" && countryArr->Array.length > 0 + | BillingName => billingName.value === "" + | AddressLine1 => line1.value === "" + | AddressLine2 => !billingAddress.isUseBillingAddress && line2.value === "" + | Bank => selectedBank === "" && bankNames->Array.length > 0 + | StateAndCity => city.value === "" || state.value === "" + | CountryAndPincode(countryArr) => + (country === "" && countryArr->Array.length > 0) || postalCode.value === "" + | PhoneNumber => phone.value === "" + | AddressCity => city.value === "" + | AddressPincode => postalCode.value === "" + | AddressState => state.value === "" + | BlikCode => blikCode.value === "" + | Currency(currencyArr) => currency === "" && currencyArr->Array.length > 0 + | CardNumber => cardNumber === "" + | CardExpiryMonth => + let (month, _) = getExpiryDates(cardExpiry) + month === "" + | CardExpiryYear => + let (_, year) = getExpiryDates(cardExpiry) + year === "" + | CardExpiryMonthAndYear => + let (month, year) = getExpiryDates(cardExpiry) + month === "" || year === "" + | CardCvc => cvcNumber === "" + | CardExpiryAndCvc => + let (month, year) = getExpiryDates(cardExpiry) + month === "" || year === "" || cvcNumber === "" + | _ => false + } + }) setAreRequiredFieldsEmpty(_ => areRequiredFieldsEmpty) None }, ( @@ -231,48 +235,32 @@ let useSetInitialRequiredFields = ( ~requiredFields: array, ~paymentMethodType, ) => { - let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) - let (email, setEmail) = Recoil.useLoggedRecoilState(RecoilAtoms.userEmailAddress, "email", logger) - let (fullName, setFullName) = Recoil.useLoggedRecoilState( - RecoilAtoms.userFullName, - "fullName", - logger, - ) + let logger = Recoil.useRecoilValueFromAtom(loggerAtom) + let (email, setEmail) = Recoil.useLoggedRecoilState(userEmailAddress, "email", logger) + let (fullName, setFullName) = Recoil.useLoggedRecoilState(userFullName, "fullName", logger) let (billingName, setBillingName) = Recoil.useLoggedRecoilState( - RecoilAtoms.userBillingName, + userBillingName, "billingName", logger, ) - let (line1, setLine1) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressline1, "line1", logger) - let (line2, setLine2) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressline2, "line2", logger) - let (phone, setPhone) = Recoil.useLoggedRecoilState(RecoilAtoms.userPhoneNumber, "phone", logger) - let (state, setState) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressState, "state", logger) - let (city, setCity) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressCity, "city", logger) + let (line1, setLine1) = Recoil.useLoggedRecoilState(userAddressline1, "line1", logger) + let (line2, setLine2) = Recoil.useLoggedRecoilState(userAddressline2, "line2", logger) + let (phone, setPhone) = Recoil.useLoggedRecoilState(userPhoneNumber, "phone", logger) + let (state, setState) = Recoil.useLoggedRecoilState(userAddressState, "state", logger) + let (city, setCity) = Recoil.useLoggedRecoilState(userAddressCity, "city", logger) let (postalCode, setPostalCode) = Recoil.useLoggedRecoilState( - RecoilAtoms.userAddressPincode, + userAddressPincode, "postal_code", logger, ) - let (blikCode, setBlikCode) = Recoil.useLoggedRecoilState( - RecoilAtoms.userBlikCode, - "blikCode", - logger, - ) - let (country, setCountry) = Recoil.useLoggedRecoilState( - RecoilAtoms.userCountry, - "country", - logger, - ) + let (blikCode, setBlikCode) = Recoil.useLoggedRecoilState(userBlikCode, "blikCode", logger) + let (country, setCountry) = Recoil.useLoggedRecoilState(userCountry, "country", logger) let (selectedBank, setSelectedBank) = Recoil.useLoggedRecoilState( - RecoilAtoms.userBank, + userBank, "selectedBank", logger, ) - let (currency, setCurrency) = Recoil.useLoggedRecoilState( - RecoilAtoms.userCurrency, - "currency", - logger, - ) + let (currency, setCurrency) = Recoil.useLoggedRecoilState(userCurrency, "currency", logger) React.useEffect(() => { let getNameValue = (item: PaymentMethodsRecord.required_fields) => { @@ -390,20 +378,20 @@ let useRequiredFieldsBody = ( ~isAllStoredCardsHaveName, ~setRequiredFieldsBody, ) => { - let email = Recoil.useRecoilValueFromAtom(RecoilAtoms.userEmailAddress) - let fullName = Recoil.useRecoilValueFromAtom(RecoilAtoms.userFullName) - let billingName = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBillingName) - let line1 = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressline1) - let line2 = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressline2) - let phone = Recoil.useRecoilValueFromAtom(RecoilAtoms.userPhoneNumber) - let state = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressState) - let city = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressCity) - let postalCode = Recoil.useRecoilValueFromAtom(RecoilAtoms.userAddressPincode) - let blikCode = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBlikCode) - let country = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCountry) - let selectedBank = Recoil.useRecoilValueFromAtom(RecoilAtoms.userBank) - let currency = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCurrency) - let {billingAddress} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) + let email = Recoil.useRecoilValueFromAtom(userEmailAddress) + let fullName = Recoil.useRecoilValueFromAtom(userFullName) + let billingName = Recoil.useRecoilValueFromAtom(userBillingName) + let line1 = Recoil.useRecoilValueFromAtom(userAddressline1) + let line2 = Recoil.useRecoilValueFromAtom(userAddressline2) + let phone = Recoil.useRecoilValueFromAtom(userPhoneNumber) + let state = Recoil.useRecoilValueFromAtom(userAddressState) + let city = Recoil.useRecoilValueFromAtom(userAddressCity) + let postalCode = Recoil.useRecoilValueFromAtom(userAddressPincode) + let blikCode = Recoil.useRecoilValueFromAtom(userBlikCode) + let country = Recoil.useRecoilValueFromAtom(userCountry) + let selectedBank = Recoil.useRecoilValueFromAtom(userBank) + let currency = Recoil.useRecoilValueFromAtom(userCurrency) + let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom) let getFieldValueFromFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => { switch fieldType { @@ -646,19 +634,19 @@ let updateDynamicFields = ( } let useSubmitCallback = () => { - let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) - let (line1, setLine1) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressline1, "line1", logger) - let (line2, setLine2) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressline2, "line2", logger) - let (state, setState) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressState, "state", logger) + let logger = Recoil.useRecoilValueFromAtom(loggerAtom) + let (line1, setLine1) = Recoil.useLoggedRecoilState(userAddressline1, "line1", logger) + let (line2, setLine2) = Recoil.useLoggedRecoilState(userAddressline2, "line2", logger) + let (state, setState) = Recoil.useLoggedRecoilState(userAddressState, "state", logger) let (postalCode, setPostalCode) = Recoil.useLoggedRecoilState( - RecoilAtoms.userAddressPincode, + userAddressPincode, "postal_code", logger, ) - let (city, setCity) = Recoil.useLoggedRecoilState(RecoilAtoms.userAddressCity, "city", logger) - let {billingAddress} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) + let (city, setCity) = Recoil.useLoggedRecoilState(userAddressCity, "city", logger) + let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom) - let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) + let {localeString} = Recoil.useRecoilValueFromAtom(configAtom) React.useCallback((ev: Window.event) => { let json = ev.data->JSON.parseExn diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 83937b42d..4f4ed2f71 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -777,10 +777,11 @@ let rec intentCall = ( } let usePaymentSync = (optLogger: option, paymentType: payment) => { - let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) - let keys = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) - let switchToCustomPod = Recoil.useRecoilValueFromAtom(RecoilAtoms.switchToCustomPod) - let setIsManualRetryEnabled = Recoil.useSetRecoilState(RecoilAtoms.isManualRetryEnabled) + open RecoilAtoms + let list = Recoil.useRecoilValueFromAtom(list) + let keys = Recoil.useRecoilValueFromAtom(keys) + let switchToCustomPod = Recoil.useRecoilValueFromAtom(switchToCustomPod) + let setIsManualRetryEnabled = Recoil.useSetRecoilState(isManualRetryEnabled) (~handleUserError=false, ~confirmParam: ConfirmType.confirmParams, ~iframeId="", ()) => { switch keys.clientSecret { | Some(clientSecret) => @@ -845,14 +846,13 @@ let rec maskPayload = payloadJson => { } let usePaymentIntent = (optLogger: option, paymentType: payment) => { - let blockConfirm = Recoil.useRecoilValueFromAtom(RecoilAtoms.isConfirmBlocked) - let switchToCustomPod = Recoil.useRecoilValueFromAtom(RecoilAtoms.switchToCustomPod) - let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) - let keys = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) + open RecoilAtoms + let blockConfirm = Recoil.useRecoilValueFromAtom(isConfirmBlocked) + let switchToCustomPod = Recoil.useRecoilValueFromAtom(switchToCustomPod) + let list = Recoil.useRecoilValueFromAtom(list) + let keys = Recoil.useRecoilValueFromAtom(keys) - let (isManualRetryEnabled, setIsManualRetryEnabled) = Recoil.useRecoilState( - RecoilAtoms.isManualRetryEnabled, - ) + let (isManualRetryEnabled, setIsManualRetryEnabled) = Recoil.useRecoilState(isManualRetryEnabled) ( ~handleUserError=false, ~bodyArr: array<(string, JSON.t)>, From 2233ab17623dbd7a0bb1e0a9e5f3aed79a4fb2aa Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Thu, 18 Apr 2024 12:39:00 +0530 Subject: [PATCH 2/2] fix: unnecessary type defn --- src/Utilities/PaymentHelpers.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index b2cc4cd27..30a185cf5 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -858,7 +858,7 @@ let rec maskPayload = payloadJson => { } } -let usePaymentIntent = (optLogger: option, paymentType: payment) => { +let usePaymentIntent = (optLogger, paymentType) => { open RecoilAtoms let blockConfirm = Recoil.useRecoilValueFromAtom(isConfirmBlocked) let switchToCustomPod = Recoil.useRecoilValueFromAtom(switchToCustomPod)