Skip to content

Commit

Permalink
17. Subscription Review Fixes (#2547)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1204099484721401/1206757416402738/f

Description:

Copy and layout updates in Subscription > Add device
Properly update account email when changes in the Add Device page
Prevent showing the "Subscription Activation in progress" error while fetching subscription info
  • Loading branch information
afterxleep authored Mar 14, 2024
1 parent af3f938 commit 8993b63
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
19 changes: 11 additions & 8 deletions DuckDuckGo/SettingsSubscriptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,20 @@ struct SettingsSubscriptionView: View {
var body: some View {
if viewModel.state.subscription.enabled {
Section(header: Text(UserText.settingsPProSection)) {

if viewModel.state.subscription.hasActiveSubscription {

// Allow managing the subscription if we have some entitlements
if viewModel.shouldShowDBP || viewModel.shouldShowITP || viewModel.shouldShowNetP {
subscriptionDetailsView

if !viewModel.isLoadingSubscriptionState {

// If no entitlements it should mean the backend is still out of sync
} else {
noEntitlementsAvailableView
// Allow managing the subscription if we have some entitlements
if viewModel.shouldShowDBP || viewModel.shouldShowITP || viewModel.shouldShowNetP {
subscriptionDetailsView

// If no entitlements it should mean the backend is still out of sync
} else {
noEntitlementsAvailableView
}
}

} else {
purchaseSubscriptionView

Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ final class SettingsViewModel: ObservableObject {
// Sheet Presentation & Navigation
@Published var isRestoringSubscription: Bool = false
@Published var shouldDisplayRestoreSubscriptionError: Bool = false
@Published var isLoadingSubscriptionState: Bool = false
@Published var shouldShowNetP = false
@Published var shouldShowDBP = false
@Published var shouldShowITP = false
Expand Down Expand Up @@ -351,6 +352,7 @@ extension SettingsViewModel {
return
}

isLoadingSubscriptionState = true
// Fetch available subscriptions from the backend (or sign out)
switch await SubscriptionService.getSubscription(accessToken: token) {

Expand All @@ -372,8 +374,11 @@ extension SettingsViewModel {
}
}
}
isLoadingSubscriptionState = false

default:
// Account is active but there's not a valid subscription / entitlements
isLoadingSubscriptionState = false
signOutUser()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ final class SubscriptionRestoreViewModel: ObservableObject {
}

func initializeView() {
Task { await updateAccountEmail() }
Pixel.fire(pixel: .privacyProSettingsAddDevice)
subscriptionEmail = accountManager.email
if accountManager.isUserAuthenticated {
Expand Down Expand Up @@ -119,6 +120,15 @@ final class SubscriptionRestoreViewModel: ObservableObject {
}
}

@MainActor
private func updateAccountEmail() async {
if let token = accountManager.authToken,
case let .success(accountDetails) = await accountManager.fetchAccountDetails(with: token) {
accountManager.storeAccount(token: token, email: accountDetails.email, externalID: accountDetails.externalID)
subscriptionEmail = accountDetails.email
}
}


}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ struct SubscriptionRestoreView: View {
}
.padding(Constants.cellPadding)
.background(Color(designSystemColor: .panel))
.cornerRadius(Constants.cornerRadius)
.overlay(
RoundedRectangle(cornerRadius: Constants.cornerRadius)
.stroke(Color(designSystemColor: .lines), lineWidth: Constants.borderWidth)
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,8 @@ But if you *do* want a peek under the hood, you can find more information about

// Add to other devices (AppleID / Email)
public static let subscriptionAddDeviceTitle = NSLocalizedString("subscription.add.device.title", value: "Add Device", comment: "Add to another device view title")
public static let subscriptionAddDeviceHeaderTitle = NSLocalizedString("subscription.add.device.header.title", value: "Use your subscription on all your devices", comment: "Add subscription to other device title ")
public static let subscriptionAddDeviceDescription = NSLocalizedString("subscription.add.device.description", value: "Access your Privacy Pro subscription on other devices via an email address.", comment: "Subscription Add device Info")
public static let subscriptionAddDeviceHeaderTitle = NSLocalizedString("subscription.add.device.header.title", value: "Use your subscription on other devices", comment: "Add subscription to other device title ")
public static let subscriptionAddDeviceDescription = NSLocalizedString("subscription.add.device.description", value: "Access your Privacy Pro subscription via an email address.", comment: "Subscription Add device Info")
public static let subscriptionAvailableInApple = NSLocalizedString("subscription.available.apple", value: "Privacy Pro is available on any device signed in to the same Apple ID.", comment: "Subscription availability message on Apple devices")
public static let subscriptionManageEmailResendInstructions = NSLocalizedString("subscription.add.device.resend.instructions", value: "Resend Instructions", comment: "Resend activation instructions button")

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2005,10 +2005,10 @@ But if you *do* want a peek under the hood, you can find more information about
"subscription.add.device.button" = "Add to Another Device";

/* Subscription Add device Info */
"subscription.add.device.description" = "Access your Privacy Pro subscription on other devices via an email address.";
"subscription.add.device.description" = "Access your Privacy Pro subscription via an email address.";

/* Add subscription to other device title */
"subscription.add.device.header.title" = "Use your subscription on all your devices";
"subscription.add.device.header.title" = "Use your subscription on other devices";

/* Resend activation instructions button */
"subscription.add.device.resend.instructions" = "Resend Instructions";
Expand Down

0 comments on commit 8993b63

Please sign in to comment.