Skip to content

Commit

Permalink
chore: add optimised code
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro2002 committed Nov 8, 2024
1 parent 739845f commit cf23ead
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,23 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
}, (cardNumber, cvcNumber, cardExpiry, isCVCValid, isExpiryValid, isCardValid))

React.useEffect(() => {
let cardError = switch (
isCardValid,
isCardSupported->Option.getOr(true),
isCardValid->Option.getOr(true),
cardNumber->String.length == 0,
) {
| (None, _, _, _) => ""
| (_, _, _, true) => ""
| (_, true, true, _) => ""
| (_, true, _, _) => localeString.inValidCardErrorText
| (_, _, _, _) =>
switch cardNumber->CardUtils.getCardBrand {
| "" => localeString.inValidCardErrorText
| cardBrandValue => localeString.cardBrandConfiguredErrorText(cardBrandValue)
let cardError = if isCardValid == None || cardNumber->String.length == 0 {
""
} else {
let isCardSupportedValue = isCardSupported->Option.getOr(true)
let isCardValidValue = isCardValid->Option.getOr(false)

if isCardSupportedValue && isCardValidValue {
""
} else if isCardSupportedValue {
localeString.inValidCardErrorText
} else {
let cardBrand = cardNumber->CardUtils.getCardBrand
if cardBrand == "" {
localeString.enterValidCardNumberErrorText
} else {
localeString.cardBrandConfiguredErrorText(cardBrand)
}
}
}
setCardError(_ => cardError)
Expand Down

0 comments on commit cf23ead

Please sign in to comment.