Skip to content

Commit

Permalink
Make 90 day payment code compile with swift 6 compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenErn committed Jan 15, 2025
1 parent 1f51d38 commit 7e79f74
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
1 change: 1 addition & 0 deletions ios/MullvadVPN/Coordinators/WelcomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ final class WelcomeCoordinator: Coordinator, Poppable, Presenting {
)
}
}

extension WelcomeCoordinator: @preconcurrency WelcomeViewControllerDelegate {
func didRequestToShowFailToFetchProducts(controller: WelcomeViewController) {
let message = NSLocalizedString(
Expand Down
35 changes: 17 additions & 18 deletions ios/MullvadVPN/View controllers/Account/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import Operations
import StoreKit
import UIKit

struct PurchaseOptionDetails {
struct PurchaseOptionDetails: Sendable {
let products: [SKProduct]
let accountNumber: String
let didRequestPurchase: (SKProduct) -> Void
let didRequestPurchase: @Sendable (SKProduct) -> Void
}

enum AccountViewControllerAction: Sendable {
Expand Down Expand Up @@ -270,24 +270,24 @@ class AccountViewController: UIViewController, @unchecked Sendable {
setIsFetchingProducts(true)
_ = interactor.requestProducts(with: productIdentifiers) { [weak self] result in
guard let self else { return }
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
actionHandler?(.showPurchaseOptions(PurchaseOptionDetails(
products: products,
accountNumber: accountData.number,
didRequestPurchase: self.doPurchase
)))
} else {
Task { @MainActor in
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
actionHandler?(.showPurchaseOptions(PurchaseOptionDetails(
products: products,
accountNumber: accountData.number,
didRequestPurchase: { product in Task { @MainActor in self.doPurchase(product: product) }}
)))
} else {
actionHandler?(.showFailedToLoadProducts)
}
case .failure:
actionHandler?(.showFailedToLoadProducts)
}
case .failure:
actionHandler?(.showFailedToLoadProducts)
setIsFetchingProducts(false)
}
MainActor.assumeIsolated {
setIsFetchingProducts(false)
}
}
}

Expand Down Expand Up @@ -336,7 +336,6 @@ class AccountViewController: UIViewController, @unchecked Sendable {
let transaction = try checkVerified(verification)
await sendReceiptToAPI(accountNumber: accountData.identifier, receipt: verification)
await transaction.finish()

case .userCancelled:
print("User cancelled the purchase")
case .pending:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class WelcomeInteractor: @unchecked Sendable {

func requestProducts(
with productIdentifiers: Set<StoreSubscription>,
completionHandler: @escaping (Result<SKProductsResponse, Error>) -> Void
completionHandler: @Sendable @escaping (Result<SKProductsResponse, Error>) -> Void
) -> Cancellable {
storePaymentManager.requestProducts(
with: productIdentifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,24 @@ extension WelcomeViewController: @preconcurrency WelcomeContentViewDelegate {
contentView.isFetchingProducts = true
_ = interactor.requestProducts(with: productIdentifiers) { [weak self] result in
guard let self else { return }
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
delegate?.didRequestToViewPurchaseOptions(
controller: self,
availableProducts: products,
accountNumber: interactor.accountNumber
)
} else {
Task { @MainActor in
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
delegate?.didRequestToViewPurchaseOptions(
controller: self,
availableProducts: products,
accountNumber: interactor.accountNumber
)
} else {
delegate?.didRequestToShowFailToFetchProducts(controller: self)
}
case .failure:
delegate?.didRequestToShowFailToFetchProducts(controller: self)
}
case .failure:
delegate?.didRequestToShowFailToFetchProducts(controller: self)
contentView.isFetchingProducts = false
}
contentView.isFetchingProducts = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,25 @@ class OutOfTimeViewController: UIViewController, RootContainment {
applyViewState()
_ = interactor.requestProducts(with: productIdentifiers) { [weak self] result in
guard let self else { return }
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
delegate?.outOfTimeViewControllerDidRequestShowPurchaseOptions(
self,
products: products,
didRequestPurchase: self.doPurchase
)
} else {
Task { @MainActor in
switch result {
case let .success(success):
let products = success.products
if !products.isEmpty {
delegate?.outOfTimeViewControllerDidRequestShowPurchaseOptions(
self,
products: products,
didRequestPurchase: self.doPurchase
)
} else {
delegate?.outOfTimeViewControllerDidFailToFetchProducts(self)
}
case .failure:
delegate?.outOfTimeViewControllerDidFailToFetchProducts(self)
}
case .failure:
delegate?.outOfTimeViewControllerDidFailToFetchProducts(self)
isFetchingProducts = false
applyViewState()
}
isFetchingProducts = false
applyViewState()
}
}

Expand Down

0 comments on commit 7e79f74

Please sign in to comment.