diff --git a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift index bee8634adc..4d9b38724b 100644 --- a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift +++ b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift @@ -105,6 +105,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { static let subscriptionsUnknownPriceClicked = "subscriptionsUnknownPriceClicked" static let subscriptionsAddEmailSuccess = "subscriptionsAddEmailSuccess" static let subscriptionsWelcomeFaqClicked = "subscriptionsWelcomeFaqClicked" + static let getAccessToken = "getAccessToken" } // swiftlint:disable:next cyclomatic_complexity @@ -124,6 +125,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { case Handlers.subscriptionsUnknownPriceClicked: return subscriptionsUnknownPriceClicked case Handlers.subscriptionsAddEmailSuccess: return subscriptionsAddEmailSuccess case Handlers.subscriptionsWelcomeFaqClicked: return subscriptionsWelcomeFaqClicked + case Handlers.getAccessToken: return getAccessToken default: return nil } @@ -142,11 +144,8 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { } func getSubscription(params: Any, original: WKScriptMessage) async throws -> Encodable? { - if let authToken = accountManager.authToken, accountManager.accessToken != nil { - return Subscription(token: authToken) - } else { - return Subscription(token: "") - } + let authToken = accountManager.authToken ?? "" + return Subscription(token: authToken) } func setSubscription(params: Any, original: WKScriptMessage) async throws -> Encodable? { @@ -451,6 +450,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature { return nil } + func getAccessToken(params: Any, original: WKScriptMessage) async throws -> Encodable? { + if let accessToken = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs)).accessToken { + return ["token": accessToken] + } else { + return [String: String]() + } + } + // MARK: Push actions enum SubscribeActionName: String { diff --git a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionView.swift b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionView.swift index db764f58e1..a0e31c7d4b 100644 --- a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionView.swift +++ b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Preferences/PreferencesSubscriptionView.swift @@ -185,9 +185,13 @@ public struct PreferencesSubscriptionView: View { TextMenuItemCaption(UserText.preferencesSubscriptionExpiredCaption) } buttons: { // We need to improve re-purchase flow - /* Button(UserText.viewPlansButtonTitle) { model.purchaseAction() } - .buttonStyle(DefaultActionButtonStyle(enabled: true)) */ + Button(UserText.viewPlansExpiredButtonTitle) { model.purchaseAction() } + .buttonStyle(DefaultActionButtonStyle(enabled: true)) Menu { + Button(UserText.addToAnotherDeviceButton) { + model.userEventHandler(.addToAnotherDeviceClick) + showingSheet.toggle() + } Button(UserText.removeFromThisDeviceButton, action: { showingRemoveConfirmationDialog.toggle() }) diff --git a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Resources/Subscription.xcassets/Icons/subscription-expired-icon.imageset/subscription-expired-icon.pdf b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Resources/Subscription.xcassets/Icons/subscription-expired-icon.imageset/subscription-expired-icon.pdf index d43daeb9b9..a971e48c07 100644 Binary files a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Resources/Subscription.xcassets/Icons/subscription-expired-icon.imageset/subscription-expired-icon.pdf and b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/Resources/Subscription.xcassets/Icons/subscription-expired-icon.imageset/subscription-expired-icon.pdf differ diff --git a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/UserText.swift b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/UserText.swift index 3d344a38c9..f917d58b71 100644 --- a/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/UserText.swift +++ b/LocalPackages/SubscriptionUI/Sources/SubscriptionUI/UserText.swift @@ -55,7 +55,7 @@ enum UserText { } static func preferencesSubscriptionExpiredCaption(formattedDate: String) -> String { - let localized = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Your Privacy Pro subscription expired on %@.", comment: "Caption for the subscription preferences pane when the subscription has expired. The parameter is date of expiry.") + let localized = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Your Privacy Pro subscription expired on %@", comment: "Caption for the subscription preferences pane when the subscription has expired. The parameter is date of expiry.") return String(format: localized, formattedDate) } @@ -64,8 +64,8 @@ enum UserText { static let addToAnotherDeviceButton = NSLocalizedString("subscription.preferences.add.to.another.device.button", value: "Add to Another Device…", comment: "Button to add subscription to another device") static let manageSubscriptionButton = NSLocalizedString("subscription.preferences.manage.subscription.button", value: "Manage Subscription", comment: "Button to manage subscription") - static let changePlanOrBillingButton = NSLocalizedString("subscription.preferences.change.plan.or.billing.button", value: "Change Plan or Billing...", comment: "Button to add subscription to another device") - static let removeFromThisDeviceButton = NSLocalizedString("subscription.preferences.remove.from.this.device.button", value: "Remove From This Device...", comment: "Button to remove subscription from this device") + static let changePlanOrBillingButton = NSLocalizedString("subscription.preferences.change.plan.or.billing.button", value: "Change Plan or Billing…", comment: "Button to add subscription to another device") + static let removeFromThisDeviceButton = NSLocalizedString("subscription.preferences.remove.from.this.device.button", value: "Remove From This Device…", comment: "Button to remove subscription from this device") // MARK: Preferences when subscription is inactive static let preferencesSubscriptionInactiveHeader = NSLocalizedString("subscription.preferences.subscription.inactive.header", value: "Subscribe to Privacy Pro", comment: "Header for the subscription preferences pane when the subscription is inactive") @@ -81,6 +81,7 @@ enum UserText { // MARK: Preferences when subscription is expired static let preferencesSubscriptionExpiredCaption = NSLocalizedString("subscription.preferences.subscription.expired.caption", value: "Subscribe again to continue using Privacy Pro.", comment: "Caption for the subscription preferences pane when the subscription activation is pending") + static let viewPlansExpiredButtonTitle = NSLocalizedString("subscription.preferences.button.view.plans", value: "View Plans…", comment: "Button for viewing subscription plans on expired subscription") static let manageDevicesButton = NSLocalizedString("subscription.preferences.manage.devices.button", value: "Manage Devices", comment: "Button to manage devices") // MARK: - Change plan or billing dialogs