Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription refactoring #5 #2930

Merged
merged 42 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e3c1f5b
subscription ui handling
federicocappelli Jun 11, 2024
a55f49d
Merge branch 'main' into fcappelli/subscription_refactoring_3
federicocappelli Jun 11, 2024
8b834ac
cleanup
federicocappelli Jun 11, 2024
3c17998
xcode scheme version reverted
federicocappelli Jun 11, 2024
c9e1583
cleanup
federicocappelli Jun 11, 2024
b7a01f9
lint
federicocappelli Jun 11, 2024
6f85a8b
cleanup
federicocappelli Jun 11, 2024
ba3e808
lint
federicocappelli Jun 11, 2024
d9e96e0
presentSubscriptionAccessViewController crash fixed
federicocappelli Jun 13, 2024
eb0ff43
cleanup
federicocappelli Jun 13, 2024
ec4dcb0
var subscriptionAccessViewController removed
federicocappelli Jun 13, 2024
dcbe150
Merge branch 'main' into fcappelli/subscription_refactoring_3
federicocappelli Jun 13, 2024
9f8e091
merge fixes
federicocappelli Jun 13, 2024
1e623af
api service refactroing
federicocappelli Jun 13, 2024
651d57d
mocks added and API services refactored
federicocappelli Jun 14, 2024
85927d6
all flows abstracted with a protocol
federicocappelli Jun 17, 2024
d45b082
StripePurchaseFlowMock, AppStoreRestoreFlowMock, AppStorePurchaseFlow…
federicocappelli Jun 17, 2024
928cfe3
Merge branch 'main' into fcappelli/subscription_refactoring_4
federicocappelli Jun 17, 2024
fbfc74a
BSK from branch
federicocappelli Jun 17, 2024
479498a
BSK updated
federicocappelli Jun 17, 2024
9321f52
BSK updated
federicocappelli Jun 17, 2024
8b0ce5b
BSK updated
federicocappelli Jun 17, 2024
f9fd448
alert removed
federicocappelli Jun 18, 2024
b3a7839
Merge branch 'main' into fcappelli/subscription_refactoring_4
federicocappelli Jun 18, 2024
cbe167c
BSK Update
federicocappelli Jun 18, 2024
e46259b
new tests
federicocappelli Jun 19, 2024
9962d16
classes and protocols renamed
federicocappelli Jun 20, 2024
6c41be1
renaming
federicocappelli Jun 20, 2024
ed72bec
BSK update
federicocappelli Jun 20, 2024
6bbc6cf
Merge branch 'fcappelli/subscription_refactoring_4' into fcappelli/su…
federicocappelli Jun 20, 2024
c44cf72
more tests
federicocappelli Jun 20, 2024
67ef4c7
Merge branch 'fcappelli/subscription_refactoring_4' into fcappelli/su…
federicocappelli Jun 24, 2024
7d525a7
Merge branch 'main' into fcappelli/subscription_refactoring_5
federicocappelli Jun 24, 2024
1fcac76
SubscriptionAppStoreRestorerTests completed
federicocappelli Jun 25, 2024
df634e5
lots of unit tests
federicocappelli Jun 26, 2024
f2befc6
Subscription classes refactoring for unit testing
federicocappelli Jul 2, 2024
5242e3f
Merge branch 'main' into fcappelli/subscription_refactoring_5
federicocappelli Jul 2, 2024
a49e9e1
lint
federicocappelli Jul 2, 2024
a6e1bf9
DI improved
federicocappelli Jul 4, 2024
52a759e
Merge from main
federicocappelli Jul 5, 2024
90a5c44
Merge branch 'main' into fcappelli/subscription_refactoring_5
federicocappelli Jul 5, 2024
4a42397
BSK 165.0.0
federicocappelli Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "912001a8676345e96a8be360d5a6e3dca6d8e0ec",
"version" : "164.2.0"
"branch" : "fcappelli/subscription_refactoring_5",
"revision" : "a12f0127eb507701f80ff9bff69fc6e52d730d98"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
39 changes: 0 additions & 39 deletions DuckDuckGo/Common/Extensions/TimeIntervalExtension.swift

This file was deleted.

18 changes: 11 additions & 7 deletions DuckDuckGo/Preferences/View/PreferencesRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,22 @@ enum Preferences {
openActivateViaEmailURL: {
let url = Application.appDelegate.subscriptionManager.url(for: .activateViaEmail)
WindowControllersManager.shared.showTab(with: .subscription(url))
},
restorePurchases: {
}, restorePurchases: {
if #available(macOS 12.0, *) {
Task {
let subscriptionAppStoreRestorer = SubscriptionAppStoreRestorer(subscriptionManager: Application.appDelegate.subscriptionManager,
uiHandler: Application.appDelegate.subscriptionUIHandler)
let subscriptionManager = Application.appDelegate.subscriptionManager
federicocappelli marked this conversation as resolved.
Show resolved Hide resolved
let appStoreRestoreFlow = DefaultAppStoreRestoreFlow(accountManager: subscriptionManager.accountManager,
storePurchaseManager: subscriptionManager.storePurchaseManager(),
subscriptionEndpointService: subscriptionManager.subscriptionEndpointService,
authEndpointService: subscriptionManager.authEndpointService)
let subscriptionAppStoreRestorer = DefaultSubscriptionAppStoreRestorer(
subscriptionManager: Application.appDelegate.subscriptionManager,
appStoreRestoreFlow: appStoreRestoreFlow,
uiHandler: Application.appDelegate.subscriptionUIHandler)
await subscriptionAppStoreRestorer.restoreAppStoreSubscription()
}
}
},
uiActionHandler: handleUIEvent
)
}, uiActionHandler: handleUIEvent)

return PreferencesSubscriptionModel(openURLHandler: openURL,
userEventHandler: handleUIEvent,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Subscription/SubscriptionRedirectManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class PrivacyProSubscriptionRedirectManager: SubscriptionRedirectManager {
}
}

private extension URL {
fileprivate extension URL {

func addingQueryItems(from url: URL) -> URL {
// If the origin value is of type "do+something" appending the percentEncodedQueryItem crashes the browser as + is replaced by a space.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ import enum StoreKit.StoreKitError
import PixelKit

@available(macOS 12.0, *)
struct SubscriptionAppStoreRestorer {
protocol SubscriptionAppStoreRestorer {
var uiHandler: SubscriptionUIHandling { get }
func restoreAppStoreSubscription() async
}

@available(macOS 12.0, *)
struct DefaultSubscriptionAppStoreRestorer: SubscriptionAppStoreRestorer {
private let subscriptionManager: SubscriptionManager
@MainActor var window: NSWindow? { WindowControllersManager.shared.lastKeyMainWindowController?.window }
let subscriptionErrorReporter = SubscriptionErrorReporter()
private let subscriptionErrorReporter: SubscriptionErrorReporter
private let appStoreRestoreFlow: AppStoreRestoreFlow
let uiHandler: SubscriptionUIHandling

public init(subscriptionManager: SubscriptionManager,
subscriptionErrorReporter: SubscriptionErrorReporter = DefaultSubscriptionErrorReporter(),
appStoreRestoreFlow: AppStoreRestoreFlow,
uiHandler: SubscriptionUIHandling) {
self.subscriptionManager = subscriptionManager
self.subscriptionErrorReporter = subscriptionErrorReporter
self.appStoreRestoreFlow = appStoreRestoreFlow
self.uiHandler = uiHandler
}

Expand All @@ -59,7 +68,6 @@ struct SubscriptionAppStoreRestorer {
}

private func continueRestore() async {
let appStoreRestoreFlow = DefaultAppStoreRestoreFlow(subscriptionManager: subscriptionManager)
let result = await appStoreRestoreFlow.restoreAccountFromPastPurchase()
await uiHandler.dismissProgressViewController()
switch result {
Expand Down Expand Up @@ -87,12 +95,12 @@ struct SubscriptionAppStoreRestorer {

// MARK: - UI interactions

func showSomethingWentWrongAlert() async {
private func showSomethingWentWrongAlert() async {
PixelKit.fire(PrivacyProPixel.privacyProPurchaseFailure, frequency: .dailyAndCount)
await uiHandler.show(alertType: .somethingWentWrong)
}

func showSubscriptionNotFoundAlert() async {
private func showSubscriptionNotFoundAlert() async {
switch await uiHandler.show(alertType: .subscriptionNotFound) {
case .alertFirstButtonReturn:
let url = subscriptionManager.url(for: .purchase)
Expand All @@ -102,7 +110,7 @@ struct SubscriptionAppStoreRestorer {
}
}

func showSubscriptionInactiveAlert() async {
private func showSubscriptionInactiveAlert() async {
switch await uiHandler.show(alertType: .subscriptionInactive) {
case .alertFirstButtonReturn:
let url = subscriptionManager.url(for: .purchase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ enum SubscriptionError: Error {
generalError
}

struct SubscriptionErrorReporter {
protocol SubscriptionErrorReporter {
func report(subscriptionActivationError: SubscriptionError)
}

struct DefaultSubscriptionErrorReporter: SubscriptionErrorReporter {

// swiftlint:disable:next cyclomatic_complexity
func report(subscriptionActivationError: SubscriptionError) {
Expand Down
Loading
Loading