Skip to content
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

Remove present code redemption sheet from paymentqueuewrapper #2

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

lizard-boy
Copy link

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-android and hybrids

Motivation

Description

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR moves the code redemption sheet functionality from PaymentQueueWrapper to a dedicated OfferCodeRedemptionSheetPresenter class, modernizing the API with async/await support and improving platform-specific handling.

  • Added new OfferCodeRedemptionSheetPresenter in /Sources/Purchasing/StoreKitAbstractions/OfferCodeRedemptionSheetPresenter.swift to handle sheet presentation with proper platform checks
  • Updated Purchases.swift with new async presentCodeRedemptionSheet(uiWindowScene:) method and deprecated sync version
  • Added comprehensive error cases in StoreKitStrings.swift for sheet presentation failures (macOS, missing window scene, app extensions)
  • Removed presentCodeRedemptionSheet from PaymentQueueWrapper and updated mocks/tests to use new presenter pattern

12 file(s) reviewed, 9 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +278 to +282
Task {
#if !targetEnvironment(macCatalyst)
try await self.presentOfferCodeRedemptionSheet(uiWindowScene: nil)
#endif
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Silently swallowing errors from the async call could cause issues. Consider adding error handling or logging.

Comment on lines +1088 to +1092
internal func presentOfferCodeRedemptionSheet(uiWindowScene: UIWindowScene?) async throws {
var windowScene = uiWindowScene
if windowScene == nil {
windowScene = try await systemInfo.currentWindowScene
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using early return pattern here to reduce nesting and improve readability

Comment on lines +1076 to +1077
@available(macCatalyst 16.0, *)
@objc func presentCodeRedemptionSheet(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: macCatalyst availability should be 14.0 to match iOS version, not 16.0

Comment on lines +88 to +90
if #available(iOS 16.0, iOSApplicationExtension 16.0, *) {
try await AppStore.presentOfferCodeRedeemSheet(in: windowScene)
} else {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Redundant availability check - this block is already guarded by the osMajorVersion check above

Comment on lines +93 to +98
#if !targetEnvironment(macCatalyst)
self.sk1PresentCodeRedemptionSheet()
#else
Logger.warn(Strings.storeKit.error_displaying_offer_code_redemption_sheet_unavailable_in_app_extension)
#endif
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This else block is unreachable due to the osMajorVersion check above

}
#endif

#if os(iOS) || VISION_OS
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Missing VISION_OS availability annotation that matches the protocol

Comment on lines +113 to +115
func sk1PresentCodeRedemptionSheet() {
self.paymentQueue.presentCodeRedemptionSheet()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider handling potential errors from presentCodeRedemptionSheet() call

Comment on lines +163 to +165
Task {
try await purchases.presentCodeRedemptionSheet(uiWindowScene: nil)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: passing nil for uiWindowScene parameter may cause issues in production - should document or validate this parameter

@@ -298,7 +300,8 @@ class BasePurchasesTests: TestCase {
purchasesOrchestrator: self.purchasesOrchestrator,
purchasedProductsFetcher: self.mockPurchasedProductsFetcher,
trialOrIntroPriceEligibilityChecker: self.cachingTrialOrIntroPriceEligibilityChecker,
storeMessagesHelper: self.mockStoreMessagesHelper)
storeMessagesHelper: self.mockStoreMessagesHelper,
offerCodeRedemptionSheetPresenter: mockOfferCodeSheetPresenter)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: mockOfferCodeSheetPresenter is passed without self, which is inconsistent with other parameters in this initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants