Reorganise common code that will be used by Accelerated Checkouts#242
Conversation
| export function useShopifyEventHandlers(name?: string): EventHandlers { | ||
| const log = createDebugLogger(name ?? ''); | ||
| const {clearCart} = useCart(); | ||
|
|
||
| return useMemo(() => { | ||
| return { | ||
| onPress: () => { | ||
| log('onPress'); | ||
| }, | ||
| onFail: error => { | ||
| log('onFail', error); | ||
| }, | ||
| onComplete: event => { | ||
| log('onComplete', event.orderDetails.id); | ||
| clearCart(); | ||
| }, | ||
| onCancel: () => { | ||
| log('onCancel'); | ||
| }, | ||
| onWebPixelEvent: event => { | ||
| log('onWebPixelEvent', event.name); | ||
| }, | ||
| onClickLink: async url => { | ||
| log('onClickLink', url); | ||
|
|
||
| if (await Linking.canOpenURL(url)) { | ||
| await Linking.openURL(url); | ||
| } | ||
| }, | ||
| }; | ||
| }, [log, clearCart]); | ||
| } |
There was a problem hiding this comment.
These handlers will be reused in the sample app across the CheckoutSheetKit implementation as well as all the accelerated checkouts instances
5d46d32 to
e085858
Compare
| static func serialize(checkoutCompletedEvent event: CheckoutCompletedEvent) -> [String: Any] { | ||
| return encodeToJSON(from: event) | ||
| } | ||
|
|
||
| /** | ||
| * Converts a PixelEvent to a React Native compatible dictionary. | ||
| */ | ||
| static func serialize(pixelEvent event: PixelEvent) -> [String: Any] { | ||
| switch event { | ||
| case .standardEvent(let standardEvent): | ||
| let encoded = encodeToJSON(from: standardEvent) | ||
| return [ | ||
| "context": encoded["context"] ?? NSNull(), | ||
| "data": encoded["data"] ?? NSNull(), | ||
| "id": encoded["id"] ?? NSNull(), | ||
| "name": encoded["name"] ?? NSNull(), | ||
| "timestamp": encoded["timestamp"] ?? NSNull(), | ||
| "type": "STANDARD" | ||
| ] | ||
|
|
||
| case .customEvent(let customEvent): | ||
| return [ | ||
| "context": encodeToJSON(from: customEvent.context), | ||
| "customData": stringToJSON(from: customEvent.customData) ?? NSNull(), | ||
| "id": customEvent.id, | ||
| "name": customEvent.name, | ||
| "timestamp": customEvent.timestamp, | ||
| "type": "CUSTOM" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| static func serialize(clickEvent url: URL) -> [String: URL] { | ||
| return ["url": url] | ||
| } |
There was a problem hiding this comment.
These methods currently exist in the ShopifyCheckoutSheetKit.swift file, but the event handling will be reused in the AcceleratedCheckouts class (incoming), so I'm extracting them to an independent class.
6e4680d to
3b7f9cb
Compare
285adcc to
91c0b9e
Compare
c887bcf to
b2ebe3e
Compare
| "ios/ShopifyCheckoutSheetKit.mm", | ||
| "ios/ShopifyCheckoutSheetKit.swift", | ||
| "ios/ShopifyCheckoutSheetKit+EventSerialization.swift", | ||
| "ios/ShopifyCheckoutSheetKit+Extensions.swift", |
There was a problem hiding this comment.
Had to update the snapshot for these new files
d9a710d to
07e60da
Compare
| "recoverable": recoverable | ||
| ] | ||
|
|
||
| @unknown default: |
There was a problem hiding this comment.
is the @unknown needed here? I hadn't seen this before but seems like swift enums shouldn't require this
There was a problem hiding this comment.
It's a way of announcing issues if our switch is not exhaustive. If we don't have a case for a known issue, the compiler will complain here
07e60da to
590f709
Compare
- Add getOptimizedImageUrl utility for Shopify CDN image optimization - Add debugLog and createDebugLogger utilities with conditional development logging These utilities improve sample app performance and debugging capabilities and can be used independently of any feature development.
- Provides standardized event handlers with debug logging - Includes handlers for press, fail, complete, cancel, render state changes, pixel events, and link clicks - Integrates with existing cart context for order completion cleanup - Can be used independently of any specific checkout features
590f709 to
c354c9d
Compare
fabcd0b to
d6bd230
Compare
What changes are you making?
Forms the basis for the incoming Accelerated Checkouts feature.
This PR includes the following:
ShopifyCheckoutSheetKitclass to a dedicatedShopifyEventSerializationobject which will be reused by Accelerated CheckoutsUIColorextension to a dedicated file to provide some clean upPR Checklist
Important
Checklist for releasing a new version
package.jsonfile.Tip
See the Contributing documentation for instructions on how to publish a new version of the library.