From ab1d5f0c886a105b2bbc8fe3441afded6387ede8 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 29 Nov 2023 15:06:41 +0100 Subject: [PATCH] fatal error on unsuccessful userdefaults init --- Sources/Auth/AuthClientFactory.swift | 4 +++- .../WalletConnectNetworking/NetworkingClientFactory.swift | 4 +++- Sources/WalletConnectPairing/PairingClientFactory.swift | 4 +++- Sources/WalletConnectPush/PushClientFactory.swift | 6 ++++-- Sources/WalletConnectRelay/RelayClientFactory.swift | 6 ++++-- Sources/WalletConnectSign/Sign/SignClientFactory.swift | 4 +++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Sources/Auth/AuthClientFactory.swift b/Sources/Auth/AuthClientFactory.swift index da5bf4025..1251a77cc 100644 --- a/Sources/Auth/AuthClientFactory.swift +++ b/Sources/Auth/AuthClientFactory.swift @@ -10,7 +10,9 @@ public struct AuthClientFactory { groupIdentifier: String ) -> AuthClient { let logger = ConsoleLogger(loggingLevel: .off) - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") let iatProvider = DefaultIATProvider() diff --git a/Sources/WalletConnectNetworking/NetworkingClientFactory.swift b/Sources/WalletConnectNetworking/NetworkingClientFactory.swift index b1d159c31..b7d898d90 100644 --- a/Sources/WalletConnectNetworking/NetworkingClientFactory.swift +++ b/Sources/WalletConnectNetworking/NetworkingClientFactory.swift @@ -7,7 +7,9 @@ public struct NetworkingClientFactory { groupIdentifier: String ) -> NetworkingInteractor { let logger = ConsoleLogger(prefix: "πŸ•ΈοΈ", loggingLevel: .off) - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") return NetworkingClientFactory.create(relayClient: relayClient, logger: logger, keychainStorage: keychainStorage, keyValueStorage: keyValueStorage) } diff --git a/Sources/WalletConnectPairing/PairingClientFactory.swift b/Sources/WalletConnectPairing/PairingClientFactory.swift index 6a7e8c852..89bfef58e 100644 --- a/Sources/WalletConnectPairing/PairingClientFactory.swift +++ b/Sources/WalletConnectPairing/PairingClientFactory.swift @@ -7,7 +7,9 @@ public struct PairingClientFactory { groupIdentifier: String ) -> PairingClient { let logger = ConsoleLogger(loggingLevel: .off) - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") return PairingClientFactory.create(logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, networkingClient: networkingClient) } diff --git a/Sources/WalletConnectPush/PushClientFactory.swift b/Sources/WalletConnectPush/PushClientFactory.swift index 60a3a9ad6..75f9874bc 100644 --- a/Sources/WalletConnectPush/PushClientFactory.swift +++ b/Sources/WalletConnectPush/PushClientFactory.swift @@ -9,8 +9,10 @@ public struct PushClientFactory { ) -> PushClient { let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard - + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } + return PushClientFactory.create( projectId: projectId, pushHost: pushHost, diff --git a/Sources/WalletConnectRelay/RelayClientFactory.swift b/Sources/WalletConnectRelay/RelayClientFactory.swift index 34eac70db..0891517ae 100644 --- a/Sources/WalletConnectRelay/RelayClientFactory.swift +++ b/Sources/WalletConnectRelay/RelayClientFactory.swift @@ -12,8 +12,10 @@ public struct RelayClientFactory { socketConnectionType: SocketConnectionType ) -> RelayClient { - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard - + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } + let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") let logger = ConsoleLogger(prefix: "πŸš„" ,loggingLevel: .off) diff --git a/Sources/WalletConnectSign/Sign/SignClientFactory.swift b/Sources/WalletConnectSign/Sign/SignClientFactory.swift index 4da9b3787..2ae1ccaf9 100644 --- a/Sources/WalletConnectSign/Sign/SignClientFactory.swift +++ b/Sources/WalletConnectSign/Sign/SignClientFactory.swift @@ -18,7 +18,9 @@ public struct SignClientFactory { groupIdentifier: String ) -> SignClient { let logger = ConsoleLogger(loggingLevel: .debug) - let keyValueStorage = UserDefaults(suiteName: groupIdentifier) ?? UserDefaults.standard + guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else { + fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)") + } let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") return SignClientFactory.create(metadata: metadata, logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, pairingClient: pairingClient, networkingClient: networkingClient) }