Skip to content

Commit

Permalink
Fix Leo Yearly Status showing monthly sometimes instead of Yearly unt…
Browse files Browse the repository at this point in the history
…… (uplift to 1.74.x) (#26912)

Uplift of #26739 (squashed) to beta
  • Loading branch information
brave-builds authored Dec 9, 2024
1 parent 1f4cd2d commit 7228742
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
7 changes: 7 additions & 0 deletions ios/brave-ios/Sources/AIChat/AIChatStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public struct AIChatAdvancedSettingsView: View {
}

// No order found
return "None"
return Strings.AIChat.subscriptionNoneTitle
}

private var expirationDateTitle: String {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -156,7 +168,7 @@ public class AIChatSubscriptionDetailModelView: ObservableObject {
return false
}

var isSubscriptionStatusLoading: Bool {
var isSubscriptionStatusLoaded: Bool {
return storeSDK.leoSubscriptionStatus?.state != nil || credentialSummary != nil
}

Expand Down

0 comments on commit 7228742

Please sign in to comment.