diff --git a/ios/brave-ios/Sources/AIChat/AIChatStrings.swift b/ios/brave-ios/Sources/AIChat/AIChatStrings.swift index fa7e37413917..207cb6bc973f 100644 --- a/ios/brave-ios/Sources/AIChat/AIChatStrings.swift +++ b/ios/brave-ios/Sources/AIChat/AIChatStrings.swift @@ -537,6 +537,13 @@ extension Strings { value: "Premium Subscription", comment: "Title showing premium subscription - not determined monthly por yearly" ) + public static let subscriptionNoneTitle = NSLocalizedString( + "aichat.subscriptionNoneTitle", + tableName: "BraveLeo", + bundle: .module, + value: "None", + comment: "Title showing the user has no subscription." + ) public static let advancedSettingsAutocompleteTitle = NSLocalizedString( "aichat.advancedSettingsAutocompleteTitle", tableName: "BraveLeo", diff --git a/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatAdvancedSettingsView.swift b/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatAdvancedSettingsView.swift index 6623b79c9077..07b3202db283 100644 --- a/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatAdvancedSettingsView.swift +++ b/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatAdvancedSettingsView.swift @@ -129,7 +129,7 @@ public struct AIChatAdvancedSettingsView: View { } // No order found - return "None" + return Strings.AIChat.subscriptionNoneTitle } private var expirationDateTitle: String { @@ -163,6 +163,10 @@ public struct AIChatAdvancedSettingsView: View { return dateFormatter.string(from: date) } + if let expiryDate = viewModel.inAppPurchaseSubscriptionExpiryDate { + return dateFormatter.string(from: expiryDate) + } + // Display the info from SkusSDK if let expiryDate = viewModel.skuOrderExpirationDate { return dateFormatter.string(from: expiryDate) @@ -198,7 +202,7 @@ public struct AIChatAdvancedSettingsView: View { if viewModel.canDisplaySubscriptionStatus && (model.premiumStatus == .active || model.premiumStatus == .activeDisconnected) { - if viewModel.isSubscriptionStatusLoading { + if viewModel.isSubscriptionStatusLoaded { AIChatAdvancedSettingsLabelDetailView( title: Strings.AIChat.advancedSettingsSubscriptionStatusTitle, detail: subscriptionStatusTitle @@ -330,9 +334,8 @@ public struct AIChatAdvancedSettingsView: View { } } - // Check if there's an AppStore receipt and subscriptions have been loaded - if !viewModel.isSubscriptionStatusLoading && viewModel.inAppPurchaseSubscriptionState != nil - { + // Check if there's an AppStore purchase + if viewModel.inAppPurchaseSubscriptionState != nil { NavigationLink { StoreKitReceiptSimpleView() } label: { diff --git a/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatSubscriptionDetailModelView.swift b/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatSubscriptionDetailModelView.swift index 7c6f69006ca1..9586f21c87c4 100644 --- a/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatSubscriptionDetailModelView.swift +++ b/ios/brave-ios/Sources/AIChat/Components/Settings/AIChatSubscriptionDetailModelView.swift @@ -101,13 +101,13 @@ public class AIChatSubscriptionDetailModelView: ObservableObject { } var inAppPurchasedProductType: BraveStoreProduct? { - if storeSDK.leoSubscriptionStatus != nil { - for product in storeSDK.purchasedProducts.all { - if product.id == BraveStoreProduct.leoMonthly.rawValue { + if let status = storeSDK.leoSubscriptionStatus { + if case .verified(let transaction) = status.transaction { + if transaction.productID == BraveStoreProduct.leoMonthly.rawValue { return .leoMonthly } - if product.id == BraveStoreProduct.leoYearly.rawValue { + if transaction.productID == BraveStoreProduct.leoYearly.rawValue { return .leoYearly } } @@ -121,13 +121,25 @@ public class AIChatSubscriptionDetailModelView: ObservableObject { } var inAppPurchaseSubscriptionPeriod: StoreKit.Product.SubscriptionPeriod? { - if storeSDK.leoSubscriptionStatus != nil { - if let leoMonthlySubscription = storeSDK.leoMonthlyProduct?.subscription?.subscriptionPeriod { - return leoMonthlySubscription + if let status = storeSDK.leoSubscriptionStatus { + if case .verified(let transaction) = status.transaction { + if transaction.productID == BraveStoreProduct.leoMonthly.rawValue { + return storeSDK.leoMonthlyProduct?.subscription?.subscriptionPeriod + } + + if transaction.productID == BraveStoreProduct.leoYearly.rawValue { + return storeSDK.leoYearlyProduct?.subscription?.subscriptionPeriod + } } + } + + return nil + } - if let leoYearlySubscription = storeSDK.leoYearlyProduct?.subscription?.subscriptionPeriod { - return leoYearlySubscription + var inAppPurchaseSubscriptionExpiryDate: Date? { + if let status = storeSDK.leoSubscriptionStatus { + if case .verified(let transaction) = status.transaction { + return transaction.expirationDate } } @@ -156,7 +168,7 @@ public class AIChatSubscriptionDetailModelView: ObservableObject { return false } - var isSubscriptionStatusLoading: Bool { + var isSubscriptionStatusLoaded: Bool { return storeSDK.leoSubscriptionStatus?.state != nil || credentialSummary != nil }