From cf23eadbc0615a5cf84d8c00a362cc9c8cbe9ed8 Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Fri, 8 Nov 2024 11:09:35 +0530 Subject: [PATCH] chore: add optimised code --- src/Payment.res | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Payment.res b/src/Payment.res index ecfbd13c..9bd39436 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -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)