From be4db78c458ca7a3c8b44da8a80e4bfec45aed29 Mon Sep 17 00:00:00 2001 From: Jasonvdb Date: Thu, 23 Jul 2020 12:01:52 +0200 Subject: [PATCH] Backup prompt logic tweak --- MobileWallet/Backup/BackupPrompts.swift | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/MobileWallet/Backup/BackupPrompts.swift b/MobileWallet/Backup/BackupPrompts.swift index afd1deb2..ce9aa313 100644 --- a/MobileWallet/Backup/BackupPrompts.swift +++ b/MobileWallet/Backup/BackupPrompts.swift @@ -57,7 +57,7 @@ private class BackupPrompts { let cancelButton: String } - enum PromptTypes: CaseIterable { + enum PromptType: CaseIterable { case first case second case third @@ -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 @@ -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, @@ -184,10 +184,23 @@ 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) } } @@ -195,6 +208,7 @@ private class BackupPrompts { 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)