-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Moved HTTP requests to within iframe
To reduce network latency by eliminating the need for cross origin requests and the PREFLIGHT requests associated to them
- Loading branch information
Vrishab Srivatsa
committed
Jan 31, 2024
1 parent
e8a512c
commit fe49a56
Showing
3 changed files
with
531 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,83 @@ | ||
@react.component | ||
let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => { | ||
// open Utils | ||
// let logger = OrcaLogger.make( | ||
// ~sessionId, | ||
// ~source=Loader, | ||
// ~merchantId=publishableKey, | ||
// ~clientSecret, | ||
// (), | ||
// ) | ||
open Utils | ||
let logger = OrcaLogger.make( | ||
~sessionId, | ||
~source=Loader, | ||
~merchantId=publishableKey, | ||
~clientSecret, | ||
(), | ||
) | ||
|
||
// // let ( | ||
// // paymentMethodsResponse, | ||
// // customerPaymentMethodsResponse, | ||
// // sessionTokensResponse, | ||
// // ) = React.useMemo0(() => { | ||
// // ( | ||
// // PaymentHelpers.usePaymentMethodList( | ||
// // ~clientSecret, | ||
// // ~publishableKey, | ||
// // ~logger, | ||
// // ~switchToCustomPod=false, | ||
// // ~endpoint, | ||
// // ), | ||
// // PaymentHelpers.useCustomerDetails( | ||
// // ~clientSecret, | ||
// // ~publishableKey, | ||
// // ~optLogger=Some(logger), | ||
// // ~switchToCustomPod=false, | ||
// // ~endpoint, | ||
// // ), | ||
// // PaymentHelpers.useSessions( | ||
// // ~clientSecret, | ||
// // ~publishableKey, | ||
// // ~optLogger=Some(logger), | ||
// // ~switchToCustomPod=false, | ||
// // ~endpoint, | ||
// // (), | ||
// // ), | ||
// // ) | ||
// // }) | ||
let ( | ||
paymentMethodsResponse, | ||
customerPaymentMethodsResponse, | ||
sessionTokensResponse, | ||
) = React.useMemo0(() => { | ||
( | ||
PaymentHelpers.usePaymentMethodList( | ||
~clientSecret, | ||
~publishableKey, | ||
~logger, | ||
~switchToCustomPod=false, | ||
~endpoint, | ||
), | ||
PaymentHelpers.useCustomerDetails( | ||
~clientSecret, | ||
~publishableKey, | ||
~optLogger=Some(logger), | ||
~switchToCustomPod=false, | ||
~endpoint, | ||
), | ||
PaymentHelpers.useSessions( | ||
~clientSecret, | ||
~publishableKey, | ||
~optLogger=Some(logger), | ||
~switchToCustomPod=false, | ||
~endpoint, | ||
(), | ||
), | ||
) | ||
}) | ||
|
||
// // let sendPromiseData = (promise, key) => { | ||
// // open Promise | ||
// // promise | ||
// // ->then(res => { | ||
// // handlePostMessage([("response", res), ("data", key->Js.Json.string)]) | ||
// // resolve() | ||
// // }) | ||
// // ->catch(_err => { | ||
// // handlePostMessage([("response", Js.Json.null), ("data", key->Js.Json.string)]) | ||
// // resolve() | ||
// // }) | ||
// // ->ignore | ||
// // } | ||
let sendPromiseData = (promise, key) => { | ||
open Promise | ||
promise | ||
->then(res => { | ||
handlePostMessage([("response", res), ("data", key->Js.Json.string)]) | ||
resolve() | ||
}) | ||
->catch(_err => { | ||
handlePostMessage([("response", Js.Json.null), ("data", key->Js.Json.string)]) | ||
resolve() | ||
}) | ||
->ignore | ||
} | ||
|
||
// // React.useEffect0(() => { | ||
// // let handle = (ev: Window.event) => { | ||
// // let json = try { | ||
// // ev.data->Js.Json.parseExn | ||
// // } catch { | ||
// // | _ => Js.Json.null | ||
// // } | ||
// // let dict = json->Utils.getDictFromJson | ||
// // if dict->Js.Dict.get("sendPaymentMethodsResponse")->Belt.Option.isSome { | ||
// // paymentMethodsResponse->sendPromiseData("payment_methods") | ||
// // } else if dict->Js.Dict.get("sendCustomerPaymentMethodsResponse")->Belt.Option.isSome { | ||
// // customerPaymentMethodsResponse->sendPromiseData("customer_payment_methods") | ||
// // } else if dict->Js.Dict.get("sendSessionTokensResponse")->Belt.Option.isSome { | ||
// // sessionTokensResponse->sendPromiseData("session_tokens") | ||
// // } | ||
// // } | ||
// // Window.addEventListener("message", handle) | ||
// // handlePostMessage([("preMountLoaderInitCallback", true->Js.Json.boolean)]) | ||
// // Some( | ||
// // () => { | ||
// // Window.removeEventListener("message", handle) | ||
// // }, | ||
// // ) | ||
// // }) | ||
React.useEffect0(() => { | ||
let handle = (ev: Window.event) => { | ||
let json = try { | ||
ev.data->Js.Json.parseExn | ||
} catch { | ||
| _ => Js.Json.null | ||
} | ||
let dict = json->Utils.getDictFromJson | ||
if dict->Js.Dict.get("sendPaymentMethodsResponse")->Belt.Option.isSome { | ||
paymentMethodsResponse->sendPromiseData("payment_methods") | ||
} else if dict->Js.Dict.get("sendCustomerPaymentMethodsResponse")->Belt.Option.isSome { | ||
customerPaymentMethodsResponse->sendPromiseData("customer_payment_methods") | ||
} else if dict->Js.Dict.get("sendSessionTokensResponse")->Belt.Option.isSome { | ||
sessionTokensResponse->sendPromiseData("session_tokens") | ||
} | ||
} | ||
Window.addEventListener("message", handle) | ||
handlePostMessage([("preMountLoaderInitCallback", true->Js.Json.boolean)]) | ||
Some( | ||
() => { | ||
Window.removeEventListener("message", handle) | ||
}, | ||
) | ||
}) | ||
|
||
React.null | ||
} |
Oops, something went wrong.