From ec7d5717c11b0666c2bcf8a183eba44dfd71032f Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 2 Jul 2024 15:23:42 +0530 Subject: [PATCH 1/3] fix: wallets on top for saved cards flow --- src/PaymentElement.res | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 8a0ca1eb5..2e0d0297d 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -89,11 +89,14 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod let paymentOrder = paymentMethodOrder->getOptionalArr->removeDuplicate - let sortSavedMethodsBasedOnPriority = + let sortSavedMethodsBasedOnPriority = switch paymentOrder { + | [] => finalSavedPaymentMethods + | paymentOrder => finalSavedPaymentMethods->PaymentUtils.sortCustomerMethodsBasedOnPriority( paymentOrder, ~displayDefaultSavedPaymentIcon, ) + } setSavedMethods(_ => sortSavedMethodsBasedOnPriority) setLoadSavedCards(_ => From e439bc888fa914f9514463d074c1031bc13b45c7 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 2 Jul 2024 16:05:42 +0530 Subject: [PATCH 2/3] fix: comments addressed --- src/PaymentElement.res | 5 +-- src/Utilities/PaymentUtils.res | 69 ++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 2e0d0297d..8a0ca1eb5 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -89,14 +89,11 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod let paymentOrder = paymentMethodOrder->getOptionalArr->removeDuplicate - let sortSavedMethodsBasedOnPriority = switch paymentOrder { - | [] => finalSavedPaymentMethods - | paymentOrder => + let sortSavedMethodsBasedOnPriority = finalSavedPaymentMethods->PaymentUtils.sortCustomerMethodsBasedOnPriority( paymentOrder, ~displayDefaultSavedPaymentIcon, ) - } setSavedMethods(_ => sortSavedMethodsBasedOnPriority) setLoadSavedCards(_ => diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index 289af12bc..f309a5609 100644 --- a/src/Utilities/PaymentUtils.res +++ b/src/Utilities/PaymentUtils.res @@ -382,43 +382,48 @@ let sortCustomerMethodsBasedOnPriority = ( priorityArr: array, ~displayDefaultSavedPaymentIcon=true, ) => { - let priorityArr = priorityArr->Array.length > 0 ? priorityArr : PaymentModeType.defaultOrder - - let getPaymentMethod = (customerMethod: PaymentType.customerMethods) => { - if customerMethod.paymentMethod === "card" { - customerMethod.paymentMethod - } else { - switch customerMethod.paymentMethodType { - | Some(paymentMethodType) => paymentMethodType - | _ => customerMethod.paymentMethod + switch priorityArr { + | [] => sortArr + | _ => + let priorityArr = priorityArr->Array.length > 0 ? priorityArr : PaymentModeType.defaultOrder + + let getPaymentMethod = (customerMethod: PaymentType.customerMethods) => { + if customerMethod.paymentMethod === "card" { + customerMethod.paymentMethod + } else { + switch customerMethod.paymentMethodType { + | Some(paymentMethodType) => paymentMethodType + | _ => customerMethod.paymentMethod + } } } - } - let getCustomerMethodPriority = (paymentMethod: string) => { - let priorityArrLength = priorityArr->Array.length - let index = priorityArr->Array.indexOf(paymentMethod) + let getCustomerMethodPriority = (paymentMethod: string) => { + let priorityArrLength = priorityArr->Array.length + let index = priorityArr->Array.indexOf(paymentMethod) - index === -1 ? priorityArrLength : index - } + index === -1 ? priorityArrLength : index + } - let handleCustomerMethodsSort = ( - firstCustomerMethod: PaymentType.customerMethods, - secondCustomerMethod: PaymentType.customerMethods, - ) => { - let firstPaymentMethod = firstCustomerMethod->getPaymentMethod - let secondPaymentMethod = secondCustomerMethod->getPaymentMethod - - if ( - displayDefaultSavedPaymentIcon && - (firstCustomerMethod.defaultPaymentMethodSet || secondCustomerMethod.defaultPaymentMethodSet) - ) { - firstCustomerMethod.defaultPaymentMethodSet ? -1 : 1 - } else { - firstPaymentMethod->getCustomerMethodPriority - secondPaymentMethod->getCustomerMethodPriority + let handleCustomerMethodsSort = ( + firstCustomerMethod: PaymentType.customerMethods, + secondCustomerMethod: PaymentType.customerMethods, + ) => { + let firstPaymentMethod = firstCustomerMethod->getPaymentMethod + let secondPaymentMethod = secondCustomerMethod->getPaymentMethod + + if ( + displayDefaultSavedPaymentIcon && + (firstCustomerMethod.defaultPaymentMethodSet || + secondCustomerMethod.defaultPaymentMethodSet) + ) { + firstCustomerMethod.defaultPaymentMethodSet ? -1 : 1 + } else { + firstPaymentMethod->getCustomerMethodPriority - + secondPaymentMethod->getCustomerMethodPriority + } } - } - sortArr->Belt.SortArray.stableSortBy(handleCustomerMethodsSort) + sortArr->Belt.SortArray.stableSortBy(handleCustomerMethodsSort) + } } - From 6e2d927f38739d5fb8aead880ed8dbd7c1e9d199 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 2 Jul 2024 16:26:42 +0530 Subject: [PATCH 3/3] fix: comments addressed --- src/Utilities/PaymentUtils.res | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index f309a5609..92096fef2 100644 --- a/src/Utilities/PaymentUtils.res +++ b/src/Utilities/PaymentUtils.res @@ -382,11 +382,11 @@ let sortCustomerMethodsBasedOnPriority = ( priorityArr: array, ~displayDefaultSavedPaymentIcon=true, ) => { - switch priorityArr { - | [] => sortArr - | _ => - let priorityArr = priorityArr->Array.length > 0 ? priorityArr : PaymentModeType.defaultOrder - + if priorityArr->Array.length === 0 { + sortArr + } else { + // * Need to discuss why this is used. + // let priorityArr = priorityArr->Array.length > 0 ? priorityArr : PaymentModeType.defaultOrder let getPaymentMethod = (customerMethod: PaymentType.customerMethods) => { if customerMethod.paymentMethod === "card" { customerMethod.paymentMethod