-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/0/1205865262436820/f **Description**: Waitlist flow for DBP
- Loading branch information
Showing
26 changed files
with
759 additions
and
94 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
15 changes: 15 additions & 0 deletions
15
...uckGo/Assets.xcassets/Images/DataBrokerProtectionWaitlist/DBP-Icon.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "DBP-Icon.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file added
BIN
+4.17 KB
...DuckGo/Assets.xcassets/Images/DataBrokerProtectionWaitlist/DBP-Icon.imageset/DBP-Icon.pdf
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// DataBrokerProtectionDebugMenu.swift | ||
// | ||
// Copyright © 2023 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. | ||
// | ||
|
||
#if DBP | ||
|
||
import DataBrokerProtection | ||
import Foundation | ||
import AppKit | ||
import Common | ||
|
||
@MainActor | ||
final class DataBrokerProtectionDebugMenu: NSMenu { | ||
|
||
private let waitlistTokenItem = NSMenuItem(title: "Waitlist Token:") | ||
private let waitlistTimestampItem = NSMenuItem(title: "Waitlist Timestamp:") | ||
private let waitlistInviteCodeItem = NSMenuItem(title: "Waitlist Invite Code:") | ||
private let waitlistTermsAndConditionsAcceptedItem = NSMenuItem(title: "T&C Accepted:") | ||
|
||
init() { | ||
super.init(title: "Personal Information Removal") | ||
|
||
buildItems { | ||
NSMenuItem(title: "Waitlist") { | ||
NSMenuItem(title: "Reset Waitlist State", action: #selector(DataBrokerProtectionDebugMenu.resetWaitlistState)) | ||
.targetting(self) | ||
NSMenuItem(title: "Reset T&C Acceptance", action: #selector(DataBrokerProtectionDebugMenu.resetTermsAndConditionsAcceptance)) | ||
.targetting(self) | ||
|
||
NSMenuItem(title: "Send Notification", action: #selector(DataBrokerProtectionDebugMenu.sendWaitlistAvailableNotification)) | ||
.targetting(self) | ||
|
||
NSMenuItem(title: "Fetch Invite Code", action: #selector(DataBrokerProtectionDebugMenu.fetchInviteCode)) | ||
.targetting(self) | ||
NSMenuItem.separator() | ||
|
||
waitlistTokenItem | ||
waitlistTimestampItem | ||
waitlistInviteCodeItem | ||
waitlistTermsAndConditionsAcceptedItem | ||
} | ||
} | ||
} | ||
|
||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Menu State Update | ||
|
||
override func update() { | ||
updateWaitlistItems() | ||
} | ||
|
||
// MARK: - Menu functions | ||
|
||
@objc private func resetWaitlistState() { | ||
DataBrokerProtectionWaitlist().waitlistStorage.deleteWaitlistState() | ||
UserDefaultsAuthenticationData().reset() | ||
UserDefaults().removeObject(forKey: UserDefaultsWrapper<Bool>.Key.dataBrokerProtectionTermsAndConditionsAccepted.rawValue) | ||
NotificationCenter.default.post(name: .dataBrokerProtectionWaitlistAccessChanged, object: nil) | ||
os_log("DBP waitlist state cleaned", log: .dataBrokerProtection) | ||
} | ||
|
||
@objc private func resetTermsAndConditionsAcceptance() { | ||
UserDefaults().removeObject(forKey: UserDefaultsWrapper<Bool>.Key.dataBrokerProtectionTermsAndConditionsAccepted.rawValue) | ||
NotificationCenter.default.post(name: .dataBrokerProtectionWaitlistAccessChanged, object: nil) | ||
os_log("DBP waitlist terms and conditions cleaned", log: .dataBrokerProtection) | ||
} | ||
|
||
@objc private func sendWaitlistAvailableNotification() { | ||
DataBrokerProtectionWaitlist().sendInviteCodeAvailableNotification(completion: nil) | ||
|
||
os_log("DBP waitlist notification sent", log: .dataBrokerProtection) | ||
} | ||
|
||
@objc private func fetchInviteCode() { | ||
os_log("Fetching invite code...", log: .dataBrokerProtection) | ||
|
||
Task { | ||
try? await DataBrokerProtectionWaitlist().redeemDataBrokerProtectionInviteCodeIfAvailable() | ||
} | ||
} | ||
|
||
// MARK: - Utility Functions | ||
|
||
private func updateWaitlistItems() { | ||
let waitlistStorage = WaitlistKeychainStore(waitlistIdentifier: DataBrokerProtectionWaitlist.identifier) | ||
waitlistTokenItem.title = "Waitlist Token: \(waitlistStorage.getWaitlistToken() ?? "N/A")" | ||
waitlistInviteCodeItem.title = "Waitlist Invite Code: \(waitlistStorage.getWaitlistInviteCode() ?? "N/A")" | ||
|
||
if let timestamp = waitlistStorage.getWaitlistTimestamp() { | ||
waitlistTimestampItem.title = "Waitlist Timestamp: \(String(describing: timestamp))" | ||
} else { | ||
waitlistTimestampItem.title = "Waitlist Timestamp: N/A" | ||
} | ||
|
||
let accepted = UserDefaults().bool(forKey: UserDefaultsWrapper<Bool>.Key.dataBrokerProtectionTermsAndConditionsAccepted.rawValue) | ||
waitlistTermsAndConditionsAcceptedItem.title = "T&C Accepted: \(accepted ? "Yes" : "No")" | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.