diff --git a/Library/Sources/AppUIMain/Views/Profile/ProfileCoordinator.swift b/Library/Sources/AppUIMain/Views/Profile/ProfileCoordinator.swift index 973e5196..850bb25c 100644 --- a/Library/Sources/AppUIMain/Views/Profile/ProfileCoordinator.swift +++ b/Library/Sources/AppUIMain/Views/Profile/ProfileCoordinator.swift @@ -136,7 +136,7 @@ private extension ProfileCoordinator { func onCommitEditingStandard() async throws { let savedProfile = try await profileEditor.save(to: profileManager, preferencesManager: preferencesManager) do { - try iapManager.verify(savedProfile, isShared: profileEditor.isShared) + try iapManager.verify(savedProfile, extra: profileEditor.extraFeatures) } catch AppError.ineligibleProfile(let requiredFeatures) { paywallReason = .init(requiredFeatures, needsConfirmation: true) return @@ -147,7 +147,7 @@ private extension ProfileCoordinator { // restricted: verify before saving func onCommitEditingRestricted() async throws { do { - try iapManager.verify(profileEditor.activeModules, isShared: profileEditor.isShared) + try iapManager.verify(profileEditor.activeModules, extra: profileEditor.extraFeatures) } catch AppError.ineligibleProfile(let requiredFeatures) { paywallReason = .init(requiredFeatures) return @@ -162,6 +162,19 @@ private extension ProfileCoordinator { } } +private extension ProfileEditor { + var extraFeatures: Set { + var list: Set = [] + if isShared { + list.insert(.sharing) + } + if isAvailableForTV { + list.insert(.appleTV) + } + return list + } +} + // MARK: - Previews #Preview { diff --git a/Library/Sources/CommonLibrary/IAP/AppFeatureRequiring+Profile.swift b/Library/Sources/CommonLibrary/IAP/AppFeatureRequiring+Profile.swift index 23dc9f91..608ac00d 100644 --- a/Library/Sources/CommonLibrary/IAP/AppFeatureRequiring+Profile.swift +++ b/Library/Sources/CommonLibrary/IAP/AppFeatureRequiring+Profile.swift @@ -34,11 +34,7 @@ extension Profile: AppFeatureRequiring { } return builder } - var requirements = builders.features - if attributes.isAvailableForTV == true { - requirements.insert(.appleTV) - } - return requirements + return builders.features } } diff --git a/Library/Sources/CommonLibrary/IAP/IAPManager+Verify.swift b/Library/Sources/CommonLibrary/IAP/IAPManager+Verify.swift index 0ecfe76d..b7f1ebee 100644 --- a/Library/Sources/CommonLibrary/IAP/IAPManager+Verify.swift +++ b/Library/Sources/CommonLibrary/IAP/IAPManager+Verify.swift @@ -27,18 +27,18 @@ import Foundation import PassepartoutKit extension IAPManager { - public func verify(_ profile: Profile, isShared: Bool = false) throws { + public func verify(_ profile: Profile, extra: Set? = nil) throws { var features = profile.features - if isShared { - features.insert(.sharing) + extra?.forEach { + features.insert($0) } try verify(features) } - public func verify(_ modulesBuilders: [any ModuleBuilder], isShared: Bool = false) throws { + public func verify(_ modulesBuilders: [any ModuleBuilder], extra: Set? = nil) throws { var features = modulesBuilders.features - if isShared { - features.insert(.sharing) + extra?.forEach { + features.insert($0) } try verify(features) }