From 782e87fb98b3a320b931aa55a0992d3f116709d2 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Wed, 13 Mar 2024 19:52:33 +0530 Subject: [PATCH] fix(PayNowButton): update loader and disable states of pay now button after confirm --- src/Components/PayNowButton.res | 14 +++++++++++++- src/orca-loader/Hyper.res | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Components/PayNowButton.res b/src/Components/PayNowButton.res index 6de1aa890..85d1ce3dc 100644 --- a/src/Components/PayNowButton.res +++ b/src/Components/PayNowButton.res @@ -1,6 +1,6 @@ @send external postMessage: (Window.window, JSON.t, string) => unit = "postMessage" -external eventToJson: ReactEvent.Mouse.t => JSON.t = "%identity" +external eventToJson: 'a => JSON.t = "%identity" module Loader = { @react.component @@ -59,9 +59,21 @@ let make = ( let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton + let handleMessage = (event: Types.event) => { + let json = event.data->eventToJson->OrcaUtils.getStringfromjson("")->OrcaUtils.safeParse + let dict = json->Utils.getDictFromJson + switch dict->Dict.get("submitSuccessful") { + | Some(_) => + setIsDisabled(_ => false) + setShowLoader(_ => false) + | None => () + } + } + let handleOnClick = _ => { setIsDisabled(_ => true) setShowLoader(_ => true) + EventListenerManager.addSmartEventListener("message", handleMessage, "onSubmitSuccessful") Utils.handlePostMessage([("handleSdkConfirm", confirmPayload)]) } diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index e770683a2..d1d1717f2 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -272,6 +272,10 @@ let make = (publishableKey, options: option, analyticsInfo: optionJs.Dict.get("submitSuccessful") { | Some(val) => + let message = [("submitSuccessful", val)]->Dict.fromArray + iframeRef.contents->Array.forEach(ifR => { + ifR->Window.iframePostMessage(message) + }) logApi( ~type_="method", ~optLogger=Some(logger),