Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KMS] KeychainError description #1146

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Example/WalletApp/ApplicationLayer/ConfigurationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ final class ConfigurationService {

Notify.instance.setLogging(level: .debug)

if let clientId = try? Networking.interactor.getClientId() {
LoggingService.instance.setUpUser(account: importAccount.account.absoluteString, clientId: clientId)
ProfilingService.instance.setUpProfiling(account: importAccount.account.absoluteString, clientId: clientId)
}
LoggingService.instance.startLogging()

Task {
do {
try await Notify.instance.register(account: importAccount.account, domain: "com.walletconnect", onSign: importAccount.onSign)
} catch {
DispatchQueue.main.async {
let logMessage = LogMessage(message: "Push Server registration failed with: \(error.localizedDescription)")
ProfilingService.instance.send(logMessage: logMessage)
UIApplication.currentWindow.rootViewController?.showAlert(title: "Register error", error: error)
}
}
}

if let clientId = try? Networking.interactor.getClientId() {
LoggingService.instance.setUpUser(account: importAccount.account.absoluteString, clientId: clientId)
ProfilingService.instance.setUpProfiling(account: importAccount.account.absoluteString, clientId: clientId)
}
LoggingService.instance.startLogging()
}
}
1 change: 1 addition & 0 deletions Example/WalletApp/ApplicationLayer/ProfilingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class ProfilingService {

handleLogs(from: Networking.instance.logsPublisher)
handleLogs(from: Notify.instance.logsPublisher)
handleLogs(from: Push.instance.logsPublisher)
}

private func handleLogs(from publisher: AnyPublisher<Log, Never>) {
Expand Down
6 changes: 5 additions & 1 deletion Sources/WalletConnectKMS/Keychain/KeychainError.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import Foundation

// TODO: Integrate with WalletConnectError
struct KeychainError: Error {
struct KeychainError: Error, LocalizedError {

let status: OSStatus

init(_ status: OSStatus) {
self.status = status
}

var errorDescription: String? {
return "OSStatus: \(status), message: \(status.message)"
}
}

extension KeychainError: CustomStringConvertible {
Expand Down
3 changes: 1 addition & 2 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class NotifyClient {
}

public var logsPublisher: AnyPublisher<Log, Never> {
logger.logsPublisher
.eraseToAnyPublisher()
return logger.logsPublisher
}

private let deleteNotifySubscriptionRequester: DeleteNotifySubscriptionRequester
Expand Down
9 changes: 8 additions & 1 deletion Sources/WalletConnectPush/PushClient.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import Foundation
import Combine

public class PushClient: PushClientProtocol {
private let registerService: PushRegisterService
private let logger: ConsoleLogging

init(registerService: PushRegisterService) {
public var logsPublisher: AnyPublisher<Log, Never> {
return logger.logsPublisher
}

init(registerService: PushRegisterService, logger: ConsoleLogging) {
self.registerService = registerService
self.logger = logger
}

public func register(deviceToken: Data) async throws {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectPush/PushClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public struct PushClientFactory {

let registerService = PushRegisterService(httpClient: httpClient, projectId: projectId, clientIdStorage: clientIdStorage, pushAuthenticator: pushAuthenticator, logger: logger, environment: environment)

return PushClient(registerService: registerService)
return PushClient(registerService: registerService, logger: logger)
}
}
4 changes: 3 additions & 1 deletion Sources/WalletConnectPush/Register/PushRegisterService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ actor PushRegisterService {
guard response.status == .success else {
throw Errors.registrationFailed
}
logger.debug("Successfully registered at Echo Server")
logger.debug("Successfully registered at Push Server")
} catch {
if (error as? HTTPError) == .couldNotConnect && !fallback {
logger.debug("Trying fallback")
fallback = true
await echoHostFallback()
try await register(deviceToken: deviceToken)
}
logger.debug("Push Server registration error: \(error.localizedDescription)")
throw error
}
}
Expand Down
25 changes: 16 additions & 9 deletions Sources/WalletConnectUtils/Logger/Log.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import Foundation

public struct LogMessage {

public let message: String
public let properties: [String: String]?
public var aggregated: String {
var aggregatedProperties = ""

properties?.forEach { key, value in
aggregatedProperties += "\(key): \(value), "
}
public var aggregated: String {
var aggregatedProperties = ""

if !aggregatedProperties.isEmpty {
aggregatedProperties = String(aggregatedProperties.dropLast(2))
}
properties?.forEach { key, value in
aggregatedProperties += "\(key): \(value), "
}

return "\(message), properties: [\(aggregatedProperties)]"
if !aggregatedProperties.isEmpty {
aggregatedProperties = String(aggregatedProperties.dropLast(2))
}

return "\(message), properties: [\(aggregatedProperties)]"
}

public init(message: String, properties: [String : String]? = nil) {
self.message = message
self.properties = properties
}
}

public enum Log {
Expand Down