From 52a87931a2d59947fb561ceab0b9b2ac1390a066 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Fri, 16 Dec 2022 15:36:04 +0500 Subject: [PATCH] Separate debug cleanup --- Example/ExampleApp/SceneDelegate.swift | 4 ++-- .../Services/SignCleanupService.swift | 15 +++++++++++---- Sources/WalletConnectSign/Sign/SignClient.swift | 11 +++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Example/ExampleApp/SceneDelegate.swift b/Example/ExampleApp/SceneDelegate.swift index c3ddd5743..38a75b651 100644 --- a/Example/ExampleApp/SceneDelegate.swift +++ b/Example/ExampleApp/SceneDelegate.swift @@ -10,7 +10,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) async { let metadata = AppMetadata( name: "Example Wallet", @@ -22,7 +22,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { Pair.configure(metadata: metadata) #if DEBUG if CommandLine.arguments.contains("-cleanInstall") { - try? Sign.instance.cleanup() + try? await Sign.instance.cleanup() } #endif diff --git a/Sources/WalletConnectSign/Services/SignCleanupService.swift b/Sources/WalletConnectSign/Services/SignCleanupService.swift index d3270d3bb..1da2aee3e 100644 --- a/Sources/WalletConnectSign/Services/SignCleanupService.swift +++ b/Sources/WalletConnectSign/Services/SignCleanupService.swift @@ -18,11 +18,11 @@ final class SignCleanupService { func cleanup() async throws { try await unsubscribe() + try cleanupStorages() + } - pairingStore.deleteAll() - sessionStore.deleteAll() - sessionToPairingTopic.deleteAll() - try kms.deleteAll() + func cleanup() throws { + try cleanupStorages() } } @@ -34,4 +34,11 @@ private extension SignCleanupService { try await networkInteractor.batchUnsubscribe(topics: pairing + session) } + + func cleanupStorages() throws { + pairingStore.deleteAll() + sessionStore.deleteAll() + sessionToPairingTopic.deleteAll() + try kms.deleteAll() + } } diff --git a/Sources/WalletConnectSign/Sign/SignClient.swift b/Sources/WalletConnectSign/Sign/SignClient.swift index 795bc22b1..dda1b477e 100644 --- a/Sources/WalletConnectSign/Sign/SignClient.swift +++ b/Sources/WalletConnectSign/Sign/SignClient.swift @@ -347,10 +347,21 @@ public final class SignClient { } /// Delete all stored data such as: pairings, sessions, keys + /// + /// - Note: Will unsubscribe from all topics public func cleanup() async throws { try await cleanupService.cleanup() } +#if DEBUG + /// Delete all stored data such as: pairings, sessions, keys + /// + /// - Note: Doesn't unsubscribe from topics + public func cleanup() throws { + try cleanupService.cleanup() + } +#endif + // MARK: - Private private func setUpEnginesCallbacks() {