Skip to content

Commit

Permalink
fix: parse exn error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja committed Aug 5, 2024
1 parent 094c2fa commit f6b5e5b
Show file tree
Hide file tree
Showing 37 changed files with 51 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/Components/AddressPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ let make = (~paymentType, ~className="") => {
}, [country.value])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if line1.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BillingNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let make = (~paymentType, ~customFieldName=None, ~requiredFields as optionalRequ
let nameRef = React.useRef(Nullable.null)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if billingName.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/BlikCodePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let make = () => {
}, [blikCode.isValid])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if blikCode.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/EmailPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let make = (~paymentType) => {
}, [email.isValid])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if email.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FullNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) =
let nameRef = React.useRef(Nullable.null)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if fullName.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FullScreenPortal.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let make = (~children) => {
React.useEffectOnEveryRender(() => {
let handle = (ev: Window.event) => {
try {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->getDictFromJson

if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
Expand Down
9 changes: 5 additions & 4 deletions src/Components/PaymentLoader.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@react.component
let make = () => {
open Utils
let (branding, setBranding) = React.useState(_ => "auto")

React.useEffect0(() => {
Utils.handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let dict = json->Utils.getDictFromJson
setBranding(_ => dict->Utils.getDictFromDict("options")->Utils.getString("branding", "auto"))
let json = ev.data->safeParse
let dict = json->getDictFromJson
setBranding(_ => dict->getDictFromDict("options")->getString("branding", "auto"))
}
Window.addEventListener("message", handle)
Some(() => {Window.removeEventListener("message", handle)})
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PixPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let make = (~label="") => {
}, [pixCPF.value])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if pixKey.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ let make = (
ApplePayHelpers.useHandleApplePayResponse(~connectors=[], ~intent, ~isSavedMethodsFlow=true)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper

let isCustomerAcceptanceRequired = customerMethod.recurringEnabled->not
Expand Down
2 changes: 1 addition & 1 deletion src/Components/VpaIdPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let make = (~paymentType) => {
}

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if vpaId.value == "" {
Expand Down
2 changes: 1 addition & 1 deletion src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
open Promise
let handleFun = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
ev.data->safeParse
} catch {
| _ => Dict.make()->JSON.Encode.object
}
Expand Down
14 changes: 8 additions & 6 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,14 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
}, [paymentMode])

React.useEffect0(() => {
open Utils
let handleFun = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
ev.data->safeParse
} catch {
| _ => Dict.make()->JSON.Encode.object
}
let dict = json->Utils.getDictFromJson
let dict = json->getDictFromJson
if dict->Dict.get("doBlur")->Option.isSome {
logger.setLogInfo(~value="doBlur Triggered", ~eventName=BLUR, ())
setBlurState(_ => true)
Expand All @@ -343,19 +344,20 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
setIsCVCValid(_ => None)
}
}
Utils.handleMessage(handleFun, "Error in parsing sent Data")
handleMessage(handleFun, "Error in parsing sent Data")
})

React.useEffect(() => {
open Utils
let handleDoSubmit = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let jsonDict = json->Utils.getDictFromJson
let json = ev.data->safeParse
let jsonDict = json->getDictFromJson
let confirm = jsonDict->ConfirmType.itemToObjMapper
if confirm.doSubmit {
submitValue(ev, confirm.confirmParams)
}
}
Utils.handleMessage(handleDoSubmit, "")
handleMessage(handleDoSubmit, "")
}, (cardNumber, cvcNumber, cardExpiry, isCVCValid, isExpiryValid, isCardValid))

React.useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
cardsToRender(cardsContainerWidth)
}, [cardsContainerWidth])
let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit && selectedOption == "" {
postFailedSubmitResponse(~errortype="validation_error", ~message="Select a payment method")
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let make = (~paymentType: CardThemeType.mode) => {
UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType="ach_bank_debit")

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper

if confirm.doSubmit {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/AddBankDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let make = (~paymentMethodType) => {

React.useEffect0(() => {
let onPlaidCallback = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
if dict->getBool("isPlaid", false) {
let publicToken = dict->getDictFromDict("data")->getString("publicToken", "")
Expand Down Expand Up @@ -64,7 +64,7 @@ let make = (~paymentMethodType) => {
})

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
postFailedSubmitResponse(
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let make = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper

if confirm.doSubmit {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let default = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BankTransfersPopup.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let make = (~transferType) => {
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
let metadata = dict->getJsonObjectFromDict("metadata")
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BecsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let make = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/Boleto.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let make = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper

if confirm.doSubmit {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ let make = (
)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
let (month, year) = CardUtils.getExpiryDates(cardExpiry)

Expand Down
2 changes: 1 addition & 1 deletion src/Payments/DateOfBirth.res
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let make = () => {
let (isNotEligible, setIsNotEligible) = React.useState(_ => false)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
switch selectedDate->Nullable.toOption {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ let make = (
React.useEffect0(() => {
let handleGooglePayMessages = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
ev.data->safeParse
} catch {
| _ => Dict.make()->JSON.Encode.object
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let make = (~paymentType) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
let (connectors, _) =
paymentMethodListValue->PaymentUtils.getConnectors(PayLater(Klarna(Redirect)))
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PlaidSDKIframe.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let make = () => {

React.useEffect0(() => {
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let metaData = json->getDictFromJson->getDictFromDict("metadata")
let linkToken = metaData->getString("linkToken", "")
if linkToken->String.length > 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let make = (

let handle = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
ev.data->safeParse
} catch {
| _ => JSON.Encode.null
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let make = () => {
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
let metadata = dict->getJsonObjectFromDict("metadata")
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/SepaBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let make = (~paymentType: CardThemeType.mode) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper

if confirm.doSubmit {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/SepaBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let make = (~paymentType) => {
}, [complete])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if complete {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/VoucherDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = () => {
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
let metadata = dict->getJsonObjectFromDict("metadata")
Expand Down
2 changes: 1 addition & 1 deletion src/ThreeDSAuth.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make = () => {
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->getDictFromJson
if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
let metadata = dict->getJsonObjectFromDict("metadata")
Expand Down
2 changes: 1 addition & 1 deletion src/ThreeDSMethod.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let make = () => {
React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let dict = json->Utils.getDictFromJson
if dict->Dict.get("fullScreenIframeMounted")->Option.isSome {
let metadata = dict->getJsonObjectFromDict("metadata")
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ let useHandleApplePayResponse = (
React.useEffect(() => {
let handleApplePayMessages = (ev: Window.event) => {
let json = try {
ev.data->JSON.parseExn
ev.data->safeParse
} catch {
| _ => Dict.make()->JSON.Encode.object
}
Expand Down Expand Up @@ -255,7 +255,7 @@ let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => {

React.useCallback((ev: Window.event) => {
if !isWallet {
let json = ev.data->JSON.parseExn
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit && areRequiredFieldsValid && !areRequiredFieldsEmpty {
options.readOnly ? () : handleApplePayButtonClicked(~sessionObj, ~componentName)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ let useSubmitCallback = () => {
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)

React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let json = ev.data->Utils.safeParse
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if line1.value == "" {
Expand Down
Loading

0 comments on commit f6b5e5b

Please sign in to comment.