-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscription Email restore & Other flows (#2365)
Task/Issue URL: https://app.asana.com/0/72649045549333/1205054784245717/f Description: Allows restoring a subscription using your email Allows adding email to a subscription Allows managing email from a subscription
- Loading branch information
1 parent
55445fb
commit bcf8c70
Showing
22 changed files
with
443 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
DuckDuckGo/Subscription/ViewModel/SubscriptionEmailViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// SubscriptionEmailViewModel.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import UserScript | ||
import Combine | ||
import Core | ||
|
||
#if SUBSCRIPTION | ||
@available(iOS 15.0, *) | ||
final class SubscriptionEmailViewModel: ObservableObject { | ||
|
||
let accountManager: AccountManager | ||
let userScript: SubscriptionPagesUserScript | ||
let subFeature: SubscriptionPagesUseSubscriptionFeature | ||
|
||
var emailURL = URL.activateSubscriptionViaEmail | ||
var viewTitle = UserText.subscriptionRestoreEmail | ||
@Published var subscriptionEmail: String? | ||
@Published var shouldReloadWebView = false | ||
@Published var activateSubscription = false | ||
@Published var managingSubscriptionEmail = false | ||
|
||
private var cancellables = Set<AnyCancellable>() | ||
|
||
init(userScript: SubscriptionPagesUserScript, | ||
subFeature: SubscriptionPagesUseSubscriptionFeature, | ||
accountManager: AccountManager) { | ||
self.userScript = userScript | ||
self.subFeature = subFeature | ||
self.accountManager = accountManager | ||
initializeView() | ||
setupTransactionObservers() | ||
} | ||
|
||
private func initializeView() { | ||
if accountManager.isUserAuthenticated { | ||
// If user is authenticated, we want to "Add or manage email" instead of activating | ||
emailURL = accountManager.email == nil ? URL.addEmailToSubscription : URL.manageSubscriptionEmail | ||
viewTitle = accountManager.email == nil ? UserText.subscriptionRestoreAddEmailTitle : UserText.subscriptionManageEmailTitle | ||
|
||
// Also we assume subscription requires managing, and not activation | ||
managingSubscriptionEmail = true | ||
} | ||
} | ||
|
||
private func setupTransactionObservers() { | ||
subFeature.$emailActivationComplete | ||
.receive(on: DispatchQueue.main) | ||
.sink { [weak self] value in | ||
if value { | ||
self?.completeActivation() | ||
} | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
private func completeActivation() { | ||
subFeature.emailActivationComplete = false | ||
activateSubscription = true | ||
} | ||
|
||
} | ||
#endif |
Oops, something went wrong.