diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index 289af12bc..92096fef2 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 + 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 + } 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) + } } -