From 1f7784f0f2cc3910b9f62478fdbb92f108679871 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 24 Aug 2022 19:57:32 +0200 Subject: [PATCH 1/2] Add invalidateIfNeeded function --- Sources/WalletConnectRelay/RelayClient.swift | 2 +- .../AutomaticSocketConnectionHandler.swift | 1 - .../SocketConnectionHandler/BackgroundTaskRegistering.swift | 5 ++--- Sources/WalletConnectSign/Sign/SignClientFactory.swift | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/WalletConnectRelay/RelayClient.swift b/Sources/WalletConnectRelay/RelayClient.swift index 0c18c01d7..2c475b654 100644 --- a/Sources/WalletConnectRelay/RelayClient.swift +++ b/Sources/WalletConnectRelay/RelayClient.swift @@ -82,7 +82,7 @@ public final class RelayClient { keychainStorage: KeychainStorageProtocol = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk"), socketFactory: WebSocketFactory, socketConnectionType: SocketConnectionType = .automatic, - logger: ConsoleLogging = ConsoleLogger(loggingLevel: .off) + logger: ConsoleLogging = ConsoleLogger(loggingLevel: .debug) ) { let socketAuthenticator = SocketAuthenticator( clientIdStorage: ClientIdStorage(keychain: keychainStorage), diff --git a/Sources/WalletConnectRelay/SocketConnectionHandler/AutomaticSocketConnectionHandler.swift b/Sources/WalletConnectRelay/SocketConnectionHandler/AutomaticSocketConnectionHandler.swift index 5a5cec5f6..20eab6208 100644 --- a/Sources/WalletConnectRelay/SocketConnectionHandler/AutomaticSocketConnectionHandler.swift +++ b/Sources/WalletConnectRelay/SocketConnectionHandler/AutomaticSocketConnectionHandler.swift @@ -36,7 +36,6 @@ class AutomaticSocketConnectionHandler: SocketConnectionHandler { } appStateObserver.onWillEnterForeground = { [unowned self] in - backgroundTaskRegistrar.invalidate() socket.connect() } } diff --git a/Sources/WalletConnectRelay/SocketConnectionHandler/BackgroundTaskRegistering.swift b/Sources/WalletConnectRelay/SocketConnectionHandler/BackgroundTaskRegistering.swift index 7b08c94a6..a652bef74 100644 --- a/Sources/WalletConnectRelay/SocketConnectionHandler/BackgroundTaskRegistering.swift +++ b/Sources/WalletConnectRelay/SocketConnectionHandler/BackgroundTaskRegistering.swift @@ -5,7 +5,6 @@ import UIKit protocol BackgroundTaskRegistering { func register(name: String, completion: @escaping () -> Void) - func invalidate() } class BackgroundTaskRegistrar: BackgroundTaskRegistering { @@ -15,7 +14,7 @@ class BackgroundTaskRegistrar: BackgroundTaskRegistering { func register(name: String, completion: @escaping () -> Void) { #if os(iOS) - backgroundTaskID = .invalid + invalidateIfNeeded() backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: name) { [unowned self] in UIApplication.shared.endBackgroundTask(backgroundTaskID) backgroundTaskID = .invalid @@ -24,7 +23,7 @@ class BackgroundTaskRegistrar: BackgroundTaskRegistering { #endif } - func invalidate() { + private func invalidateIfNeeded() { #if os(iOS) if backgroundTaskID != .invalid { UIApplication.shared.endBackgroundTask(backgroundTaskID) diff --git a/Sources/WalletConnectSign/Sign/SignClientFactory.swift b/Sources/WalletConnectSign/Sign/SignClientFactory.swift index 8ab60ee52..b5fb7a52c 100644 --- a/Sources/WalletConnectSign/Sign/SignClientFactory.swift +++ b/Sources/WalletConnectSign/Sign/SignClientFactory.swift @@ -16,7 +16,7 @@ public struct SignClientFactory { /// /// WalletConnect Client is not a singleton but once you create an instance, you should not deinitialize it. Usually only one instance of a client is required in the application. public static func create(metadata: AppMetadata, relayClient: RelayClient) -> SignClient { - let logger = ConsoleLogger(loggingLevel: .off) + let logger = ConsoleLogger(loggingLevel: .debug) let keyValueStorage = UserDefaults.standard let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") return SignClientFactory.create(metadata: metadata, logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, relayClient: relayClient) From 344041c379e4b13bcd292684dc029ec77c6d3884 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 24 Aug 2022 20:02:14 +0200 Subject: [PATCH 2/2] update logging level --- Sources/WalletConnectRelay/RelayClient.swift | 2 +- Sources/WalletConnectSign/Sign/SignClientFactory.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WalletConnectRelay/RelayClient.swift b/Sources/WalletConnectRelay/RelayClient.swift index 2c475b654..0c18c01d7 100644 --- a/Sources/WalletConnectRelay/RelayClient.swift +++ b/Sources/WalletConnectRelay/RelayClient.swift @@ -82,7 +82,7 @@ public final class RelayClient { keychainStorage: KeychainStorageProtocol = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk"), socketFactory: WebSocketFactory, socketConnectionType: SocketConnectionType = .automatic, - logger: ConsoleLogging = ConsoleLogger(loggingLevel: .debug) + logger: ConsoleLogging = ConsoleLogger(loggingLevel: .off) ) { let socketAuthenticator = SocketAuthenticator( clientIdStorage: ClientIdStorage(keychain: keychainStorage), diff --git a/Sources/WalletConnectSign/Sign/SignClientFactory.swift b/Sources/WalletConnectSign/Sign/SignClientFactory.swift index b5fb7a52c..8ab60ee52 100644 --- a/Sources/WalletConnectSign/Sign/SignClientFactory.swift +++ b/Sources/WalletConnectSign/Sign/SignClientFactory.swift @@ -16,7 +16,7 @@ public struct SignClientFactory { /// /// WalletConnect Client is not a singleton but once you create an instance, you should not deinitialize it. Usually only one instance of a client is required in the application. public static func create(metadata: AppMetadata, relayClient: RelayClient) -> SignClient { - let logger = ConsoleLogger(loggingLevel: .debug) + let logger = ConsoleLogger(loggingLevel: .off) let keyValueStorage = UserDefaults.standard let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") return SignClientFactory.create(metadata: metadata, logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, relayClient: relayClient)