Skip to content

Commit

Permalink
fix(PayNowButton): update loader and disable states of pay now button…
Browse files Browse the repository at this point in the history
… after confirm
  • Loading branch information
Vrishab Srivatsa committed Mar 13, 2024
1 parent 1bbc1f2 commit 782e87f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)])
}

Expand Down
4 changes: 4 additions & 0 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ let make = (publishableKey, options: option<Js.Json.t>, analyticsInfo: option<Js

switch dict->Js.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),
Expand Down

0 comments on commit 782e87f

Please sign in to comment.