Skip to content

Commit

Permalink
fix: wallets on top for saved cards flow (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Jul 2, 2024
1 parent d0c836d commit eaaccb0
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions src/Utilities/PaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -382,43 +382,48 @@ let sortCustomerMethodsBasedOnPriority = (
priorityArr: array<string>,
~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)
}
}

0 comments on commit eaaccb0

Please sign in to comment.