Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ extension ApplePayAuthorizationDelegate: PKPaymentAuthorizationControllerDelegat

// Taxes may become pending again fail to resolve despite updating within the didUpdatePaymentMethod
// So we retry one time to see if the error clears on retry
_ = try await Task.retrying(priority: nil, maxRetryCount: 1) {
_ = try await Task.retrying(priority: nil, maxRetryCount: 1) { @MainActor in
try await self.controller.storefront.cartPaymentUpdate(
id: cartID,
totalAmount: totalAmount,
Expand All @@ -250,7 +250,9 @@ extension ApplePayAuthorizationDelegate: PKPaymentAuthorizationControllerDelegat
ShopifyAcceleratedCheckouts.logger.debug("paymentAuthorizationControllerDidFinish, state: \(state)")

controller.dismiss {
Task { try? await self.transition(to: .completed) }
Task { @MainActor in
try? await self.transition(to: .completed)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension PKPaymentAuthorizationController: PaymentAuthorizationController {}
typealias PKAuthorizationControllerFactory = (PKPaymentRequest) -> PaymentAuthorizationController

@available(iOS 16.0, *)
@MainActor
class ApplePayAuthorizationDelegate: NSObject, ObservableObject {
let configuration: ApplePayConfigurationWrapper
let abortError = ShopifyAcceleratedCheckouts.Error.invariant(expected: "cart")
Expand Down Expand Up @@ -173,7 +174,7 @@ class ApplePayAuthorizationDelegate: NSObject, ObservableObject {
break
default:
let cartID = try pkEncoder.cartID.get()
try? await _Concurrency.Task.retrying(clock: clock) {
try? await _Concurrency.Task.retrying(clock: clock) { @MainActor in
try await self.controller.storefront.cartRemovePersonalData(id: cartID)
}.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct ApplePayButton: View {
/// This is an internal view to allow Environment injection of the shared configuration app wide
@available(iOS 16.0, *)
@available(macOS, unavailable)
@MainActor
struct Internal_ApplePayButton: View {
private let label: PayWithApplePayButtonLabel
private let style: PayWithApplePayButtonStyle
Expand Down Expand Up @@ -143,7 +144,7 @@ struct Internal_ApplePayButton: View {
buttonType: label.pkPaymentButtonType,
buttonStyle: style.pkPaymentButtonStyle,
cornerRadius: cornerRadius ?? 8,
action: { Task { await controller.onPress() } }
action: { Task { @MainActor in await controller.onPress() } }
)
.id("\(colorScheme)-\(style.pkPaymentButtonStyle.rawValue)")
.frame(height: 48)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ShopifyCheckoutKit
import SwiftUI

@available(iOS 16.0, *)
@MainActor
protocol PayController: AnyObject {
var cart: StorefrontAPI.Types.Cart? { get set }
var storefront: StorefrontAPIProtocol { get set }
Expand All @@ -35,6 +36,7 @@ protocol PayController: AnyObject {
}

@available(iOS 16.0, *)
@MainActor
class ApplePayViewController: WalletController, PayController {
@Published var paymentController: PKPaymentAuthorizationController?

Expand Down Expand Up @@ -96,7 +98,7 @@ class ApplePayViewController: WalletController, PayController {

self.client = LifecycleObservingClient(base: client, onComplete: { [weak self] in
guard let self else { return }
Task {
Task { @MainActor in
try? await self.authorizationDelegate.transition(to: .completed)
}
})
Expand All @@ -113,9 +115,7 @@ class ApplePayViewController: WalletController, PayController {
ShopifyAcceleratedCheckouts.logger.error(
"[startPayment] Failed to setup cart: \(error)"
)
Task { @MainActor in
self.onCheckoutFail?(.sdkError(underlying: error, recoverable: false))
}
self.onCheckoutFail?(.sdkError(underlying: error, recoverable: false))
}

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal struct ShopPayButton: View {
/// Internal_ wrapper component allows `ShopifyAcceleratedCheckouts.Configuration` to be
/// DI into ShopPayViewController at init, avoiding optionality checks through ViewController
@available(iOS 16.0, *)
@MainActor
internal struct Internal_ShopPayButton: View {
private var controller: ShopPayViewController
private let cornerRadius: CGFloat?
Expand All @@ -87,7 +88,7 @@ internal struct Internal_ShopPayButton: View {
var body: some View {
Button(
action: {
Task { await controller.onPress() }
Task { @MainActor in await controller.onPress() }
},
label: {
HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ShopifyCheckoutKit
import SwiftUI

@available(iOS 16.0, *)
@MainActor
class ShopPayViewController: WalletController {
var eventHandlers: EventHandlers
var client: (any CheckoutCommunicationProtocol)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ShopifyCheckoutKit
import SwiftUI

@available(iOS 16.0, *)
@MainActor
class WalletController: ObservableObject {
@Published var identifier: CheckoutIdentifier
@Published var storefront: StorefrontAPIProtocol
Expand Down Expand Up @@ -58,7 +59,6 @@ class WalletController: ObservableObject {
}
}

@MainActor
func present(url: URL, client: (any CheckoutCommunicationProtocol)?) async throws {
guard let topViewController = getTopViewController() else {
throw ShopifyAcceleratedCheckouts.Error.invariant(expected: "topViewController")
Expand All @@ -71,7 +71,6 @@ class WalletController: ObservableObject {
)
}

@MainActor
func getTopViewController() -> UIViewController? {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first
Expand Down
Loading