Skip to content

Commit

Permalink
Backup prompt logic tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Jul 23, 2020
1 parent d8a9c60 commit be4db78
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions MobileWallet/Backup/BackupPrompts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private class BackupPrompts {
let cancelButton: String
}

enum PromptTypes: CaseIterable {
enum PromptType: CaseIterable {
case first
case second
case third
Expand Down Expand Up @@ -138,7 +138,7 @@ private class BackupPrompts {
return
}

for type in PromptTypes.allCases {
for type in PromptType.allCases.reversed() {
//If they have been shown this once, skip over this prompt
guard UserDefaults.standard.bool(forKey: type.userDefaultsKey) == false else {
continue
Expand All @@ -163,7 +163,7 @@ private class BackupPrompts {
continue
}

UserDefaults.standard.set(true, forKey: type.userDefaultsKey)
setAsShown(type)
let content = type.content
UserFeedback.shared.callToAction(
title: content.title,
Expand All @@ -184,17 +184,31 @@ private class BackupPrompts {
}
}

/// Sets all triggers as "shown" if it matches the passed trigger and/or is below the passed trigger. i.e. The second tigger will set the first and second as shown.
/// - Parameter type: Prompt type (first, second, third)
private func setAsShown(_ type: PromptType) {
var setAsShown: Bool = false
for t in PromptType.allCases.reversed() {
if t == type {
setAsShown = true
}

UserDefaults.standard.set(setAsShown, forKey: t.userDefaultsKey)
}
}

/// For testing in debug only
func resetTriggers() {
guard TariSettings.shared.environment == .debug else { return }
for type in PromptTypes.allCases {
for type in PromptType.allCases {
UserDefaults.standard.set(false, forKey: type.userDefaultsKey)
}
}
}

extension UIViewController {
func checkBackupPrompt(delay: TimeInterval) {
// return BackupPrompts.shared.resetTriggers()
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
guard let self = self else { return }
BackupPrompts.shared.check(self)
Expand Down

0 comments on commit be4db78

Please sign in to comment.