-
Notifications
You must be signed in to change notification settings - Fork 25
Add support for checkout.submit #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: prototype/development
Are you sure you want to change the base?
Conversation
Wire up the CheckoutSubmitStartEvent to the SwiftUI modifier pattern,
allowing SwiftUI apps to handle checkout submit events via:
.onSubmitStart { event in
// Handle submit start
event.respondWith(payload: response)
}
Adds testOnSubmitStart to verify the SwiftUI modifier correctly wires up the CheckoutSubmitStartEvent to the delegate wrapper.
51af86c to
4f32f72
Compare
56d6680 to
10fa83c
Compare
| // MARK: - Encodable Conformance | ||
|
|
||
| extension CheckoutSubmitRequest { | ||
| public func encode(to encoder: Encoder) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be declared in the OutboundRPCRequest extension?
Using the associatedType ResponsePayload generic you should have access to the Codable
|
|
||
| // Cancel any pending outbound requests to prevent continuation leaks | ||
| Task { [pendingRequests] in | ||
| await pendingRequests.cancelAll() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if this should also be cleared if URL changes? I think load could be called multiple times on the same Webview
| // Get the raw response data from the pending request | ||
| let responseData: Data = try await withCheckedThrowingContinuation { continuation in | ||
| Task { | ||
| await pendingRequests.register(id: request.id, continuation: continuation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have a race condition with CheckoutBridge.sendRequest?
Could all of this go in an async context?
|
|
||
| Task { | ||
| do { | ||
| let responseData = try JSONEncoder().encode(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A back and forth happening here on these response types
userContentController( _: WKUserContentController, didReceive message: WKScriptMessage ) Does the following
- Calls CheckoutBridge.decode
- Calls
handleBridgeEvent
So the entry point for these responses is decode to envelope, then encode back to data, and we complete the pendingRequests withData
Possible optimisation opportunity
|
I suppose we're not exposing this in the imperative API. Which feels like it's probably OK? |
|
Definitely on the right track |
ca6ed8f to
f492e4a
Compare
What changes are you making?
Before you merge
Important
Releasing a new version of the kit?
podspecfile.Releasing a new major version?
Tip
See the Contributing documentation for instructions on how to publish a new version of the library.