diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 2d6803821..3546bee9e 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -66,6 +66,10 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | None => savedCardsWithoutDefaultPaymentMethod } + finalSavedPaymentMethods->Array.sort((a, b) => + compareLogic(Date.fromString(a.lastUsedAt), Date.fromString(b.lastUsedAt)) + ) + setSavedMethods(_ => finalSavedPaymentMethods) setLoadSavedCards(_ => finalSavedPaymentMethods->Array.length == 0 diff --git a/src/Types/PaymentType.res b/src/Types/PaymentType.res index adf21f04c..7fa528e48 100644 --- a/src/Types/PaymentType.res +++ b/src/Types/PaymentType.res @@ -128,6 +128,7 @@ type customerMethods = { paymentMethodType: option, defaultPaymentMethodSet: bool, requiresCvv: bool, + lastUsedAt: string, } type savedCardsLoadState = LoadingSavedCards | LoadedSavedCards(array, bool) | NoResult(bool) @@ -184,6 +185,7 @@ let defaultCustomerMethods = { paymentMethodType: None, defaultPaymentMethodSet: false, requiresCvv: true, + lastUsedAt: "", } let defaultLayout = { defaultCollapsed: false, @@ -877,6 +879,7 @@ let createCustomerObjArr = dict => { paymentMethodType: getPaymentMethodType(dict), defaultPaymentMethodSet: getBool(dict, "default_payment_method_set", false), requiresCvv: getBool(dict, "requires_cvv", true), + lastUsedAt: getString(dict, "last_used_at", ""), } }) LoadedSavedCards(customerPaymentMethods, isGuestCustomer) @@ -899,6 +902,7 @@ let getCustomerMethods = (dict, str) => { paymentMethodType: getPaymentMethodType(dict), defaultPaymentMethodSet: getBool(dict, "default_payment_method_set", false), requiresCvv: getBool(dict, "requires_cvv", true), + lastUsedAt: getString(dict, "last_used_at", ""), } }) LoadedSavedCards(customerPaymentMethods, false) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index dd475b9f4..8336197e7 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1283,6 +1283,16 @@ let getStateNameFromStateCodeAndCountry = (list: JSON.t, stateCode: string, coun let removeHyphen = str => str->String.replaceRegExp(%re("/-/g"), "") +let compareLogic = (a, b) => { + if a == b { + 0. + } else if a > b { + -1. + } else { + 1. + } +} + let currencyNetworksDict = [ ("BTC", ["bitcoin", "bnb_smart_chain"]),