From 081b395fd8de9599ebd130b75b9ccd325406f692 Mon Sep 17 00:00:00 2001 From: Daniel Bernal Date: Thu, 2 May 2024 17:33:40 +0200 Subject: [PATCH] Add getAccessToken handler --- .../Subscription/SubscriptionPagesUserScript.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift b/DuckDuckGo/Tab/UserScripts/Subscription/SubscriptionPagesUserScript.swift index 655a90308f..875a2df4ae 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 } @@ -448,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 {