From cf4196d78815b553661a56fb1c91430240ed8f40 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Tue, 23 Apr 2024 14:13:13 +0530 Subject: [PATCH 1/4] refactor: paymentMethodList changes --- src/Components/AccordionContainer.res | 8 ++++---- src/LoaderController.res | 24 +++++++++++++----------- src/PaymentElement.res | 20 ++++++++++---------- src/PaymentElementRenderer.res | 4 ++-- src/PaymentOptions.res | 4 ++-- src/Utilities/PaymentHelpers.res | 8 ++++---- src/Utilities/RecoilAtoms.res | 2 +- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Components/AccordionContainer.res b/src/Components/AccordionContainer.res index 4914ab034..a2fd9cf77 100644 --- a/src/Components/AccordionContainer.res +++ b/src/Components/AccordionContainer.res @@ -2,13 +2,13 @@ open RecoilAtoms module Loader = { @react.component let make = (~cardShimmerCount) => { - let list = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) let {layout} = Recoil.useRecoilValueFromAtom(optionAtom) let layoutClass = CardUtils.getLayoutClass(layout) open PaymentType open PaymentElementShimmer - switch list { + switch paymentMethodList { | SemiLoaded => Array.make(~length=cardShimmerCount - 1, "") ->Array.mapWithIndex((_, i) => { @@ -61,7 +61,7 @@ module Loader = { @react.component let make = (~paymentOptions: array, ~checkoutEle: React.element) => { let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) - let list = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let {layout} = Recoil.useRecoilValueFromAtom(optionAtom) let layoutClass = CardUtils.getLayoutClass(layout) let (showMore, setShowMore) = React.useState(_ => false) @@ -81,7 +81,7 @@ let make = (~paymentOptions: array, ~checkoutEle: React.element) => { !showMore && !layoutClass.spacedAccordionItems && index == 0 && - list == SemiLoaded && + paymentMethodList == SemiLoaded && cardOptionDetails->Array.length == 1 ) { `${themeObj.borderRadius} ${themeObj.borderRadius} 0px 0px` diff --git a/src/LoaderController.res b/src/LoaderController.res index e0b5a9aba..cb94999d4 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -5,7 +5,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime //<...>// let (configAtom, setConfig) = Recoil.useRecoilState(configAtom) let (keys, setKeys) = Recoil.useRecoilState(keys) - let (paymentlist, setList) = Recoil.useRecoilState(list) + let (paymentMethodList, setPaymentMethodList) = Recoil.useRecoilState(paymentMethodList) let (_, setSessions) = Recoil.useRecoilState(sessions) let (options, setOptions) = Recoil.useRecoilState(elementOptions) let (optionsPayment, setOptionsPayment) = Recoil.useRecoilState(optionAtom) @@ -126,7 +126,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime handlePostMessage([("iframeMounted", true->JSON.Encode.bool)]) handlePostMessage([("applePayMounted", true->JSON.Encode.bool)]) logger.setLogInitiated() - let updatedState: PaymentType.loadType = switch paymentlist { + let updatedState: PaymentType.loadType = switch paymentMethodList { | Loading => showCardFormByDefault && checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading | x => x @@ -142,7 +142,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime | Loading => logger.setLogInfo(~value="Loading", ~eventName=LOADER_CHANGED, ~latency=finalLoadLatency, ()) | SemiLoaded => { - setList(_ => updatedState) + setPaymentMethodList(_ => updatedState) logger.setLogInfo( ~value="SemiLoaded", ~eventName=LOADER_CHANGED, @@ -361,8 +361,8 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime ) } if dict->getDictIsSome("paymentMethodList") { - let list = dict->getJsonObjectFromDict("paymentMethodList") - let listDict = list->getDictFromJson + let paymentMethodList = dict->getJsonObjectFromDict("paymentMethodList") + let listDict = paymentMethodList->getDictFromJson if optionsPayment.business.name === "" { setOptionsPayment(prev => { ...prev, @@ -377,14 +377,16 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime Date.now() -. launchTime } let updatedState: PaymentType.loadType = - list == Dict.make()->JSON.Encode.object - ? LoadError(list) + paymentMethodList == Dict.make()->JSON.Encode.object + ? LoadError(paymentMethodList) : switch listDict->Dict.get("error") { - | Some(_) => LoadError(list) + | Some(_) => LoadError(paymentMethodList) | None => let isNonEmptyPaymentMethodList = listDict->getArray("payment_methods")->Array.length > 0 - isNonEmptyPaymentMethodList ? Loaded(list) : LoadError(list) + isNonEmptyPaymentMethodList + ? Loaded(paymentMethodList) + : LoadError(paymentMethodList) } let evalMethodsList = () => @@ -424,7 +426,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime } } - setList(_ => updatedState) + setPaymentMethodList(_ => updatedState) } if dict->getDictIsSome("customerPaymentMethods") { let customerPaymentMethods = dict->PaymentType.createCustomerObjArr @@ -439,7 +441,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime } let evalMethodsList = () => - switch paymentlist { + switch paymentMethodList { | Loaded(_) => logger.setLogInfo( ~value="Loaded", diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 04a3cd033..2f977ef85 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -21,7 +21,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod let optionAtomValue = Recoil.useRecoilValueFromAtom(optionAtom) let isApplePayReady = Recoil.useRecoilValueFromAtom(isApplePayReady) let isGooglePayReady = Recoil.useRecoilValueFromAtom(isGooglePayReady) - let methodslist = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let paymentOrder = paymentMethodOrder->getOptionalArr->removeDuplicate let (sessions, setSessions) = React.useState(_ => Dict.make()->JSON.Encode.object) let (paymentOptions, setPaymentOptions) = React.useState(_ => []) @@ -115,7 +115,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod ) let (walletList, paymentOptionsList, actualList) = React.useMemo(() => { - switch methodslist { + switch paymentMethodList { | Loaded(paymentlist) => let paymentOrder = paymentOrder->Array.length > 0 ? paymentOrder : PaymentModeType.defaultOrder @@ -140,7 +140,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | _ => ([], [], []) } }, ( - methodslist, + paymentMethodList, paymentMethodOrder, isApplePayReady, isGooglePayReady, @@ -149,7 +149,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod )) React.useEffect(() => { - switch methodslist { + switch paymentMethodList { | Loaded(paymentlist) => let plist = paymentlist->getDictFromJson->PaymentMethodsRecord.itemToObjMapper @@ -186,7 +186,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | _ => () } None - }, (methodslist, walletList, paymentOptionsList, actualList)) + }, (paymentMethodList, walletList, paymentOptionsList, actualList)) React.useEffect(() => { switch sessionsObj { | Loaded(ssn) => setSessions(_ => ssn) @@ -226,7 +226,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod ? prev : layoutClass.defaultCollapsed ? "" - : switch methodslist { + : switch paymentMethodList { | SemiLoaded | LoadError(_) => showCardFormByDefault && checkPriorityList(paymentMethodOrder) ? "card" : "" @@ -238,7 +238,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod } ) None - }, (layoutClass.defaultCollapsed, paymentOptions, methodslist, selectedOption)) + }, (layoutClass.defaultCollapsed, paymentOptions, paymentMethodList, selectedOption)) React.useEffect(() => { if layoutClass.\"type" == Tabs { let isCard: bool = cardOptions->Array.includes(selectedOption) @@ -391,7 +391,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod React.useEffect(() => { let evalMethodsList = () => - switch methodslist { + switch paymentMethodList { | SemiLoaded | LoadError(_) | Loaded(_) => handlePostMessage([("ready", true->JSON.Encode.bool)]) | _ => () @@ -409,7 +409,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod } } None - }, (methodslist, customerPaymentMethods)) + }, (paymentMethodList, customerPaymentMethods)) <> Option.isSome}> @@ -467,7 +467,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod - {switch methodslist { + {switch paymentMethodList { | LoadError(_) => React.null | _ => Array.length == 0 && walletOptions->Array.length == 0}> diff --git a/src/PaymentElementRenderer.res b/src/PaymentElementRenderer.res index ed3bbfbd9..0931b4e71 100644 --- a/src/PaymentElementRenderer.res +++ b/src/PaymentElementRenderer.res @@ -11,8 +11,8 @@ let make = ( } let {showLoader} = Recoil.useRecoilValueFromAtom(configAtom) let sessions = Recoil.useRecoilValueFromAtom(sessions) - let list = Recoil.useRecoilValueFromAtom(list) - switch (sessions, list) { + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) + switch (sessions, paymentMethodList) { | (_, Loading) => diff --git a/src/PaymentOptions.res b/src/PaymentOptions.res index a578136ca..82749de93 100644 --- a/src/PaymentOptions.res +++ b/src/PaymentOptions.res @@ -2,11 +2,11 @@ open RecoilAtoms module TabLoader = { @react.component let make = (~cardShimmerCount) => { - let list = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) open PaymentType open PaymentElementShimmer - switch list { + switch paymentMethodList { | SemiLoaded => Array.make(~length=cardShimmerCount - 1, "") ->Array.mapWithIndex((_, i) => { diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index d7746678e..f80b6d179 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -728,7 +728,7 @@ let rec intentCall = ( let usePaymentSync = (optLogger: option, paymentType: payment) => { open RecoilAtoms - let list = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let keys = Recoil.useRecoilValueFromAtom(keys) let switchToCustomPod = Recoil.useRecoilValueFromAtom(switchToCustomPod) let setIsManualRetryEnabled = Recoil.useSetRecoilState(isManualRetryEnabled) @@ -760,7 +760,7 @@ let usePaymentSync = (optLogger: option, paymentType: pay (), )->ignore } - switch list { + switch paymentMethodList { | Loaded(_) => paymentSync() | _ => () } @@ -799,7 +799,7 @@ let usePaymentIntent = (optLogger, paymentType) => { open RecoilAtoms let blockConfirm = Recoil.useRecoilValueFromAtom(isConfirmBlocked) let switchToCustomPod = Recoil.useRecoilValueFromAtom(switchToCustomPod) - let list = Recoil.useRecoilValueFromAtom(list) + let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) let keys = Recoil.useRecoilValueFromAtom(keys) let (isManualRetryEnabled, setIsManualRetryEnabled) = Recoil.useRecoilState(isManualRetryEnabled) @@ -925,7 +925,7 @@ let usePaymentIntent = (optLogger, paymentType) => { callIntent(bodyStr) } - switch list { + switch paymentMethodList { | LoadError(data) | Loaded(data) => let paymentList = data->getDictFromJson->PaymentMethodsRecord.itemToObjMapper diff --git a/src/Utilities/RecoilAtoms.res b/src/Utilities/RecoilAtoms.res index 52aa93726..5f15a891f 100644 --- a/src/Utilities/RecoilAtoms.res +++ b/src/Utilities/RecoilAtoms.res @@ -6,7 +6,7 @@ let portalNodes = Recoil.atom("portalNodes", PortalState.defaultDict) let elementOptions = Recoil.atom("elementOptions", ElementType.defaultOptions) let optionAtom = Recoil.atom("options", PaymentType.defaultOptions) let sessions = Recoil.atom("sessions", PaymentType.Loading) -let list = Recoil.atom("paymentMethodList", PaymentType.Loading) +let paymentMethodList = Recoil.atom("paymentMethodList", PaymentType.Loading) let loggerAtom = Recoil.atom("component", OrcaLogger.defaultLoggerConfig) let sessionId = Recoil.atom("sessionId", "") let isConfirmBlocked = Recoil.atom("isConfirmBlocked", false) From 5e1054e9df62ef6094b322ad21234c7262fbe011 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Tue, 23 Apr 2024 14:15:59 +0530 Subject: [PATCH 2/4] docs: template changes --- .github/PULL_REQUEST_TEMPLATE.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c91742e85..7cf01bff4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,17 +14,6 @@ -## Motivation and Context - - - ## How did you test it?