Skip to content

Commit

Permalink
refactor: changed cardError code: replaced if statements with switch
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro2002 committed Nov 8, 2024
1 parent 13f3c7e commit 739845f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,17 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
}, (cardNumber, cvcNumber, cardExpiry, isCVCValid, isExpiryValid, isCardValid))

React.useEffect(() => {
let cardError = if isCardValid == None || cardNumber->String.length == 0 {
""
} else if isCardSupported->Option.getOr(true) && isCardValid->Option.getOr(true) {
""
} else if isCardSupported->Option.getOr(true) {
localeString.inValidCardErrorText
} else {
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)
Expand Down

0 comments on commit 739845f

Please sign in to comment.