Skip to content

Commit

Permalink
refactor: redundant code removal
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored and seekshiva committed Jun 14, 2024
1 parent 0ebc610 commit 9eaf328
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/orca-loader/PaymentSessionMethods.res
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
let sortFunctions = (a, b) => {
open Utils
let temp1 = Date.fromString(a->getDictFromJson->getString("last_used_at", ""))
let temp2 = Date.fromString(b->getDictFromJson->getString("last_used_at", ""))

if temp1 === temp2 {
0.
} else if temp1 > temp2 {
-1.
} else {
1.
}
}

let getCustomerSavedPaymentMethods = (
~clientSecret,
~publishableKey,
Expand Down Expand Up @@ -46,6 +32,9 @@ let getCustomerSavedPaymentMethods = (
->Option.getOr(false)
})

let getLastUsedAtDate = val =>
Date.fromString(val->getDictFromJson->getString("last_used_at", ""))

let paymentNotExist = (
~message="There is no default saved payment method data for this customer",
) =>
Expand All @@ -67,7 +56,9 @@ let getCustomerSavedPaymentMethods = (

let getCustomerLastUsedPaymentMethodData = () => {
let customerPaymentMethodsCopy = customerDetailsArray->Array.copy
customerPaymentMethodsCopy->Array.sort(sortFunctions)
customerPaymentMethodsCopy->Array.sort((a, b) =>
compareLogic(a->getLastUsedAtDate, b->getLastUsedAtDate)
)

switch customerPaymentMethodsCopy->Array.get(0) {
| Some(customerLastPaymentUsed) => customerLastPaymentUsed
Expand Down Expand Up @@ -167,7 +158,9 @@ let getCustomerSavedPaymentMethods = (

let confirmWithLastUsedPaymentMethod = payload => {
let customerPaymentMethodsCopy = customerDetailsArray->Array.copy
customerPaymentMethodsCopy->Array.sort(sortFunctions)
customerPaymentMethodsCopy->Array.sort((a, b) =>
compareLogic(a->getLastUsedAtDate, b->getLastUsedAtDate)
)

switch customerPaymentMethodsCopy->Array.get(0) {
| Some(customerLastPaymentUsed) =>
Expand Down

0 comments on commit 9eaf328

Please sign in to comment.