From 7221905856634f580ae6bd11eb31f08a636ec4cd Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 12:45:04 +0100 Subject: [PATCH 1/4] Add guard logic to getSubscription --- .../SubscriptionPagesUseSubscriptionFeature.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift b/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift index 7792b22677..7416683868 100644 --- a/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift +++ b/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift @@ -194,8 +194,16 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec // MARK: Broker Methods (Called from WebView via UserScripts) func getSubscription(params: Any, original: WKScriptMessage) async -> Encodable? { - await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded() - let authToken = accountManager.authToken ?? Constants.empty + guard accountManager.isUserAuthenticated else { return [Constants.token: Constants.empty] } + + let authToken: String + + switch await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded() { + case .success(let refreshedToken): + authToken = refreshedToken + case .failure: + authToken = Constants.empty + } return [Constants.token: authToken] } From 578e394ddd19bfe517520e028a5dfcbdc8d9fd81 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 13:11:55 +0100 Subject: [PATCH 2/4] Simplify the refresh auth token logic in getSubscription --- .../SubscriptionPagesUseSubscriptionFeature.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift b/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift index 7416683868..03412bae5a 100644 --- a/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift +++ b/DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift @@ -196,16 +196,12 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec func getSubscription(params: Any, original: WKScriptMessage) async -> Encodable? { guard accountManager.isUserAuthenticated else { return [Constants.token: Constants.empty] } - let authToken: String - switch await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded() { - case .success(let refreshedToken): - authToken = refreshedToken + case .success(let currentAuthToken): + return [Constants.token: currentAuthToken] case .failure: - authToken = Constants.empty + return [Constants.token: Constants.empty] } - - return [Constants.token: authToken] } func getSubscriptionOptions(params: Any, original: WKScriptMessage) async -> Encodable? { From 63a6dabf62f7a8a4b8528332d858ed25a48d00e3 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 13:24:45 +0100 Subject: [PATCH 3/4] Update to BSK hotfix branch --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 0d8bd1db19..3fa1704664 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -11723,7 +11723,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 221.0.0; + version = "221.0.0-1"; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e696bd0530..00a1da6b3b 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -138,7 +138,7 @@ { "identity" : "swift-argument-parser", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser", + "location" : "https://github.com/apple/swift-argument-parser.git", "state" : { "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", "version" : "1.4.0" From 190d5270d1944cfc671ccd86d952d61a070bd3a0 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 13:43:42 +0100 Subject: [PATCH 4/4] Update Package.resolved --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 00a1da6b3b..6035300ed3 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "9975e63265e617ce9c25ae1be6d531f6de5e6592", - "version" : "221.0.0" + "revision" : "276754fc1efab85c39a77da64e68439e7f105de3", + "version" : "221.0.0-1" } }, {