From 60f5f974fbc672cfea96d6b3112ba0e9bbcc3a6d Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 19 May 2022 15:11:28 +0200 Subject: [PATCH 01/22] Add Auth singleton --- Sources/WalletConnectAuth/Auth.swift | 147 +++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Sources/WalletConnectAuth/Auth.swift diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift new file mode 100644 index 000000000..e72b5f307 --- /dev/null +++ b/Sources/WalletConnectAuth/Auth.swift @@ -0,0 +1,147 @@ + +import Foundation +import WalletConnectUtils + +public class Auth { + struct Config { + let metadata: AppMetadata + let projectId: String + } + static let instance = Auth() + private let client: AuthClient + private static var config: Config? + + private init() { + guard let config = Auth.config else { + fatalError("Error - you must configure before accessing Auth.instance") + } + client = AuthClient(metadata: config.metadata, projectId: config.projectId, relayHost: "relay.walletconnect.com") + } + + static func configure(_ config: Config) { + Auth.config = config + } +} + +extension Auth { + + /// For the Proposer to propose a session to a responder. + /// Function will create pending pairing sequence or propose a session on existing pairing. When responder client approves pairing, session is be proposed automatically by your client. + /// - Parameter sessionPermissions: The session permissions the responder will be requested for. + /// - Parameter topic: Optional parameter - use it if you already have an established pairing with peer client. + /// - Returns: Pairing URI that should be shared with responder out of bound. Common way is to present it as a QR code. Pairing URI will be nil if you are going to establish a session on existing Pairing and `topic` function parameter was provided. + public func connect(requiredNamespaces: [String : ProposalNamespace], topic: String? = nil) async throws -> String? { + try await client.connect(requiredNamespaces: requiredNamespaces) + } + + /// For responder to receive a session proposal from a proposer + /// Responder should call this function in order to accept peer's pairing proposal and be able to subscribe for future session proposals. + /// - Parameter uri: Pairing URI that is commonly presented as a QR code by a dapp. + /// + /// Should Error: + /// - When URI is invalid format or missing params + /// - When topic is already in use + public func pair(uri: String) async throws { + try await client.pair(uri: uri) + } + + /// For the responder to approve a session proposal. + /// - Parameters: + /// - proposal: Session Proposal received from peer client in a WalletConnect delegate function: `didReceive(sessionProposal: Session.Proposal)` + /// - accounts: A Set of accounts that the dapp will be allowed to request methods executions on. + /// - methods: A Set of methods that the dapp will be allowed to request. + /// - events: A Set of events + public func approve(proposalId: String, namespaces: [String : SessionNamespace]) throws { + try client.approve(proposalId: proposalId, namespaces: namespaces) + } + + /// For the responder to reject a session proposal. + /// - Parameters: + /// - proposal: Session Proposal received from peer client in a WalletConnect delegate. + /// - reason: Reason why the session proposal was rejected. Conforms to CAIP25. + public func reject(proposal: Session.Proposal, reason: RejectionReason) { + client.reject(proposal: proposal, reason: reason) + } + + /// For the responder to update session methods + /// - Parameters: + /// - topic: Topic of the session that is intended to be updated. + /// - methods: Sets of methods that will replace existing ones. + public func update(topic: String, namespaces: [String : SessionNamespace]) async throws { + try await client.update(topic: topic, namespaces: namespaces) + } + + /// For controller to update expiry of a session + /// - Parameters: + /// - topic: Topic of the Session, it can be a pairing or a session topic. + /// - ttl: Time in seconds that a target session is expected to be extended for. Must be greater than current time to expire and than 7 days + public func extend(topic: String) async throws { + try await client.extend(topic: topic) + } + + /// For the proposer to send JSON-RPC requests to responding peer. + /// - Parameters: + /// - params: Parameters defining request and related session + public func request(params: Request) async throws { + try await client.request(params: params) + } + + /// For the responder to respond on pending peer's session JSON-RPC Request + /// - Parameters: + /// - topic: Topic of the session for which the request was received. + /// - response: Your JSON RPC response or an error. + public func respond(topic: String, response: JsonRpcResult) { + client.respond(topic: topic, response: response) + } + + /// Ping method allows to check if client's peer is online and is subscribing for your sequence topic + /// + /// Should Error: + /// - When the session topic is not found + /// - When the response is neither result or error + /// - When the peer fails to respond within timeout + /// + /// - Parameters: + /// - topic: Topic of the sequence, it can be a pairing or a session topic. + /// - completion: Result will be success on response or error on timeout. -- TODO: timeout + public func ping(topic: String, completion: @escaping ((Result) -> ())) { + client.ping(topic: topic, completion: completion) + } + + /// - Parameters: + /// - topic: Session topic + /// - params: Event Parameters + /// - completion: calls a handler upon completion + public func emit(topic: String, event: Session.Event, chainId: Blockchain) async throws { + try await client.emit(topic: topic, event: event, chainId: chainId) + } + + /// - Parameters: + /// - topic: Session topic that you want to delete + /// - reason: Reason of session deletion + public func disconnect(topic: String, reason: Reason) async throws { + try await client.disconnect(topic: topic, reason: reason) + } + + /// - Returns: All settled sessions that are active + public func getSettledSessions() -> [Session] { + client.getSettledSessions() + } + + /// - Returns: All settled pairings that are active + public func getSettledPairings() -> [Pairing] { + client.getSettledPairings() + } + + /// - Returns: Pending requests received with wc_sessionRequest + /// - Parameter topic: topic representing session for which you want to get pending requests. If nil, you will receive pending requests for all active sessions. + public func getPendingRequests(topic: String? = nil) -> [Request] { + client.getPendingRequests(topic: topic) + } + + /// - Parameter id: id of a wc_sessionRequest jsonrpc request + /// - Returns: json rpc record object for given id or nil if record for give id does not exits + public func getSessionRequestRecord(id: Int64) -> WalletConnectUtils.JsonRpcRecord? { + client.getSessionRequestRecord(id: id) + } +} From 1e6adafe1abe5945fa640ff327216ff346380b6a Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 19 May 2022 15:21:27 +0200 Subject: [PATCH 02/22] savepoint --- Sources/WalletConnectAuth/Auth.swift | 8 +++----- Sources/WalletConnectAuth/AuthConfig.swift | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 Sources/WalletConnectAuth/AuthConfig.swift diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index e72b5f307..d53f174d9 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -1,12 +1,9 @@ import Foundation import WalletConnectUtils +import WalletConnectRelay public class Auth { - struct Config { - let metadata: AppMetadata - let projectId: String - } static let instance = Auth() private let client: AuthClient private static var config: Config? @@ -15,7 +12,8 @@ public class Auth { guard let config = Auth.config else { fatalError("Error - you must configure before accessing Auth.instance") } - client = AuthClient(metadata: config.metadata, projectId: config.projectId, relayHost: "relay.walletconnect.com") + let relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) + client = AuthClient(metadata: config.metadata, relayClient: relayClient) } static func configure(_ config: Config) { diff --git a/Sources/WalletConnectAuth/AuthConfig.swift b/Sources/WalletConnectAuth/AuthConfig.swift new file mode 100644 index 000000000..3817a5a85 --- /dev/null +++ b/Sources/WalletConnectAuth/AuthConfig.swift @@ -0,0 +1,16 @@ +import WalletConnectRelay +import Foundation + +public extension Auth { + struct Config { + let metadata: AppMetadata + let projectId: String + let socketConnectionType: SocketConnectionType + + public init(metadata: AppMetadata, projectId: String, socketConnectionType: SocketConnectionType = .automatic) { + self.metadata = metadata + self.projectId = projectId + self.socketConnectionType = socketConnectionType + } + } +} From 0b53541af4fdb51f39e4697aca16f614dbe7cf0e Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 09:17:51 +0200 Subject: [PATCH 03/22] Add combine publishers --- Example/DApp/ClientDelegate.swift | 3 -- Sources/WalletConnectAuth/Auth.swift | 52 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Example/DApp/ClientDelegate.swift b/Example/DApp/ClientDelegate.swift index 228572e59..44f7ed9b7 100644 --- a/Example/DApp/ClientDelegate.swift +++ b/Example/DApp/ClientDelegate.swift @@ -36,9 +36,6 @@ class ClientDelegate: AuthClientDelegate { onSessionResponse?(sessionResponse) } - func didUpdate(sessionTopic: String, accounts: Set) { - } - func didReject(proposal: Session.Proposal, reason: Reason) { } diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index d53f174d9..d8701d49f 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -2,6 +2,7 @@ import Foundation import WalletConnectUtils import WalletConnectRelay +import Combine public class Auth { static let instance = Auth() @@ -19,6 +20,57 @@ public class Auth { static func configure(_ config: Config) { Auth.config = config } + + var sessionProposalPublisherSubject = PassthroughSubject() + var sessionProposalPublisher: AnyPublisher { + sessionProposalPublisherSubject.eraseToAnyPublisher() + } + + var sessionSettlePublisherSubject = PassthroughSubject() + var sessionSettlePublisher: AnyPublisher { + sessionSettlePublisherSubject.eraseToAnyPublisher() + } + + var sessionDeletePublisherSubject = PassthroughSubject<(String, Reason), Never>() + var sessionDeletePublisher: AnyPublisher<(String, Reason), Never> { + sessionDeletePublisherSubject.eraseToAnyPublisher() + } + + var sessionResponsePublisherSubject = PassthroughSubject() + var sessionResponsePublisher: AnyPublisher { + sessionResponsePublisherSubject.eraseToAnyPublisher() + } + + var sessionRejectionPublisherSubject = PassthroughSubject<(Session.Proposal, Reason), Never>() + var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> { + sessionRejectionPublisherSubject.eraseToAnyPublisher() + } + + var sessionUpdatePublisherSubject = PassthroughSubject<(String, [String : SessionNamespace]), Never>() + var sessionUpdatePublisher: AnyPublisher<(String, [String : SessionNamespace]), Never> { + sessionUpdatePublisherSubject.eraseToAnyPublisher() + } + +} + +extension Auth: AuthClientDelegate { + public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { + <#code#> + } + + public func didDelete(sessionTopic: String, reason: Reason) { + <#code#> + } + + public func didSettle(session: Session) { + <#code#> + } + + public func didConnect() { + <#code#> + } + + } extension Auth { From 53c985f173c605593e17bcfc6259764fd9e4823b Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:03:14 +0200 Subject: [PATCH 04/22] savepoint --- Sources/WalletConnectAuth/Auth.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index d8701d49f..329daf43e 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -21,6 +21,11 @@ public class Auth { Auth.config = config } + var connectionStatusPublisherSubject = PassthroughSubject() + var connectionStatusPublisher: AnyPublisher { + connectionStatusPublisherSubject.eraseToAnyPublisher() + } + var sessionProposalPublisherSubject = PassthroughSubject() var sessionProposalPublisher: AnyPublisher { sessionProposalPublisherSubject.eraseToAnyPublisher() @@ -55,15 +60,15 @@ public class Auth { extension Auth: AuthClientDelegate { public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { - <#code#> + sessionUpdatePublisherSubject.send((sessionTopic, namespaces)) } public func didDelete(sessionTopic: String, reason: Reason) { - <#code#> + sessionDeletePublisherSubject.send((sessionTopic, reason)) } public func didSettle(session: Session) { - <#code#> + sessionSettlePublisherSubject.send(session) } public func didConnect() { From bc27d67fe5df76df21a1c73d55f4bc649ef05013 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:09:13 +0200 Subject: [PATCH 05/22] change build number --- Example/ExampleApp.xcodeproj/project.pbxproj | 4 ++-- Sources/WalletConnectAuth/Auth.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index 1c0e6c716..fb14b319d 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -783,7 +783,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 11; DEVELOPMENT_TEAM = W5R8AG9K22; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = DApp/Info.plist; @@ -817,7 +817,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 11; DEVELOPMENT_TEAM = W5R8AG9K22; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = DApp/Info.plist; diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index 329daf43e..d5233b680 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -72,7 +72,7 @@ extension Auth: AuthClientDelegate { } public func didConnect() { - <#code#> + } From 559c5fe745ac3f30185eb704f3257f567b81b125 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:19:57 +0200 Subject: [PATCH 06/22] add socket connection status publisher --- Example/DApp/ClientDelegate.swift | 2 +- .../Wallet/WalletViewController.swift | 2 +- Sources/WalletConnectAuth/Auth.swift | 17 ++++++++--------- Sources/WalletConnectAuth/AuthClient.swift | 7 +------ .../WalletConnectAuth/AuthClientDelegate.swift | 6 ++---- Tests/IntegrationTests/ClientDelegate.swift | 2 +- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Example/DApp/ClientDelegate.swift b/Example/DApp/ClientDelegate.swift index 44f7ed9b7..ef084bd42 100644 --- a/Example/DApp/ClientDelegate.swift +++ b/Example/DApp/ClientDelegate.swift @@ -20,7 +20,7 @@ class ClientDelegate: AuthClientDelegate { client.delegate = self } - func didConnect() { + func didChangeSocketConnectionStatus() { print("Client connected") } diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index b0f4f00f4..42f68873f 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -185,7 +185,7 @@ extension WalletViewController: ProposalViewControllerDelegate { } extension WalletViewController: AuthClientDelegate { - func didConnect() { + func didChangeSocketConnectionStatus() { onClientConnected?() print("Client connected") diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index d5233b680..3c0103ca3 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -21,9 +21,9 @@ public class Auth { Auth.config = config } - var connectionStatusPublisherSubject = PassthroughSubject() - var connectionStatusPublisher: AnyPublisher { - connectionStatusPublisherSubject.eraseToAnyPublisher() + var socketConnectionStatusPublisherSubject = PassthroughSubject() + var socketConnectionStatusPublisher: AnyPublisher { + socketConnectionStatusPublisherSubject.eraseToAnyPublisher() } var sessionProposalPublisherSubject = PassthroughSubject() @@ -59,6 +59,10 @@ public class Auth { } extension Auth: AuthClientDelegate { + public func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { + socketConnectionStatusPublisherSubject.send(status) + } + public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { sessionUpdatePublisherSubject.send((sessionTopic, namespaces)) } @@ -70,12 +74,7 @@ extension Auth: AuthClientDelegate { public func didSettle(session: Session) { sessionSettlePublisherSubject.send(session) } - - public func didConnect() { - - } - - + } extension Auth { diff --git a/Sources/WalletConnectAuth/AuthClient.swift b/Sources/WalletConnectAuth/AuthClient.swift index 622d67c1c..1ef9bdedf 100644 --- a/Sources/WalletConnectAuth/AuthClient.swift +++ b/Sources/WalletConnectAuth/AuthClient.swift @@ -103,12 +103,7 @@ public final class AuthClient { private func setUpConnectionObserving(relayClient: RelayClient) { relayClient.socketConnectionStatusPublisher.sink { [weak self] status in - switch status { - case .connected: - self?.delegate?.didConnect() - case .disconnected: - self?.delegate?.didDisconnect() - } + self?.delegate?.didChangeSocketConnectionStatus(status) }.store(in: &publishers) } diff --git a/Sources/WalletConnectAuth/AuthClientDelegate.swift b/Sources/WalletConnectAuth/AuthClientDelegate.swift index c247f9f89..2e7a7e5ac 100644 --- a/Sources/WalletConnectAuth/AuthClientDelegate.swift +++ b/Sources/WalletConnectAuth/AuthClientDelegate.swift @@ -1,5 +1,6 @@ import Foundation +import WalletConnectRelay /// A protocol that defines methods that AuthClient instance call on it's delegate to handle sequences level events public protocol AuthClientDelegate: AnyObject { @@ -52,10 +53,7 @@ public protocol AuthClientDelegate: AnyObject { func didReject(proposal: Session.Proposal, reason: Reason) /// Tells the delegate that client has connected WebSocket - func didConnect() - - /// Tells the delegate that client has disconnected WebSocket - func didDisconnect() + func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) } public extension AuthClientDelegate { diff --git a/Tests/IntegrationTests/ClientDelegate.swift b/Tests/IntegrationTests/ClientDelegate.swift index 867b8a4df..42e06b379 100644 --- a/Tests/IntegrationTests/ClientDelegate.swift +++ b/Tests/IntegrationTests/ClientDelegate.swift @@ -49,7 +49,7 @@ class ClientDelegate: AuthClientDelegate { func didReceive(sessionResponse: Response) { onSessionResponse?(sessionResponse) } - func didConnect() { + func didChangeSocketConnectionStatus() { onConnected?() } func didDisconnect() {} From dc0c1fa4a87dfbc31c5ccc964c4bca48bb83dc7e Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:25:05 +0200 Subject: [PATCH 07/22] fix sample apps builds --- Example/DApp/ClientDelegate.swift | 8 ++++---- Example/ExampleApp/Wallet/WalletViewController.swift | 10 ++++++++-- Sources/WalletConnectAuth/Auth.swift | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Example/DApp/ClientDelegate.swift b/Example/DApp/ClientDelegate.swift index ef084bd42..e6ae3ac59 100644 --- a/Example/DApp/ClientDelegate.swift +++ b/Example/DApp/ClientDelegate.swift @@ -2,6 +2,10 @@ import WalletConnectAuth import WalletConnectRelay class ClientDelegate: AuthClientDelegate { + func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { + print(status) + } + var client: AuthClient var onSessionSettled: ((Session)->())? var onSessionResponse: ((Response)->())? @@ -20,10 +24,6 @@ class ClientDelegate: AuthClientDelegate { client.delegate = self } - func didChangeSocketConnectionStatus() { - print("Client connected") - } - func didSettle(session: Session) { onSessionSettled?(session) } diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index 42f68873f..5ab0fb604 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -185,9 +185,15 @@ extension WalletViewController: ProposalViewControllerDelegate { } extension WalletViewController: AuthClientDelegate { + func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { + if status == .connected { + onClientConnected?() + print("Client connected") + } + } + func didChangeSocketConnectionStatus() { - onClientConnected?() - print("Client connected") + } diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index 3c0103ca3..85ec98ae9 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -4,6 +4,7 @@ import WalletConnectUtils import WalletConnectRelay import Combine +public typealias SocketConnectionStatus = WalletConnectRelay.SocketConnectionStatus public class Auth { static let instance = Auth() private let client: AuthClient From b48d8b9fd99f893894f72f248e41dcb8975d35dd Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:27:07 +0200 Subject: [PATCH 08/22] savepoiint --- Example/ExampleApp.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index fb14b319d..074055429 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -733,7 +733,7 @@ CODE_SIGN_ENTITLEMENTS = Wallet.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 9; + CURRENT_PROJECT_VERSION = 11; DEVELOPMENT_TEAM = W5R8AG9K22; INFOPLIST_FILE = ExampleApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; @@ -758,7 +758,7 @@ CODE_SIGN_ENTITLEMENTS = Wallet.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 9; + CURRENT_PROJECT_VERSION = 11; DEVELOPMENT_TEAM = W5R8AG9K22; INFOPLIST_FILE = ExampleApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; @@ -783,7 +783,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = W5R8AG9K22; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = DApp/Info.plist; @@ -817,7 +817,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = W5R8AG9K22; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = DApp/Info.plist; From 9b11805094f7fd1f8e977d4dbc2c34ef0db98ad7 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:40:00 +0200 Subject: [PATCH 09/22] savepoint --- Example/DApp/SceneDelegate.swift | 9 ++++++++- Sources/WalletConnectAuth/Auth.swift | 18 +++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Example/DApp/SceneDelegate.swift b/Example/DApp/SceneDelegate.swift index 0128d48d2..4ac4aad3e 100644 --- a/Example/DApp/SceneDelegate.swift +++ b/Example/DApp/SceneDelegate.swift @@ -13,9 +13,16 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(windowScene: windowScene) - ClientDelegate.shared.onSessionDelete = { [unowned self] in + let metadata = AppMetadata( + name: "Swift Dapp", + description: "a description", + url: "wallet.connect", + icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) + Auth.configure(Auth.Config(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a")) + Auth.instance.sessionDeletePublisher.sink { [unowned self] in showSelectChainScreen() } + ClientDelegate.shared.onSessionResponse = { [unowned self] response in presentResponse(for: response) } diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index 85ec98ae9..5d4b41088 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -6,7 +6,7 @@ import Combine public typealias SocketConnectionStatus = WalletConnectRelay.SocketConnectionStatus public class Auth { - static let instance = Auth() + static public let instance = Auth() private let client: AuthClient private static var config: Config? @@ -18,42 +18,42 @@ public class Auth { client = AuthClient(metadata: config.metadata, relayClient: relayClient) } - static func configure(_ config: Config) { + static public func configure(_ config: Config) { Auth.config = config } var socketConnectionStatusPublisherSubject = PassthroughSubject() - var socketConnectionStatusPublisher: AnyPublisher { + public var socketConnectionStatusPublisher: AnyPublisher { socketConnectionStatusPublisherSubject.eraseToAnyPublisher() } var sessionProposalPublisherSubject = PassthroughSubject() - var sessionProposalPublisher: AnyPublisher { + public var sessionProposalPublisher: AnyPublisher { sessionProposalPublisherSubject.eraseToAnyPublisher() } var sessionSettlePublisherSubject = PassthroughSubject() - var sessionSettlePublisher: AnyPublisher { + public var sessionSettlePublisher: AnyPublisher { sessionSettlePublisherSubject.eraseToAnyPublisher() } var sessionDeletePublisherSubject = PassthroughSubject<(String, Reason), Never>() - var sessionDeletePublisher: AnyPublisher<(String, Reason), Never> { + public var sessionDeletePublisher: AnyPublisher<(String, Reason), Never> { sessionDeletePublisherSubject.eraseToAnyPublisher() } var sessionResponsePublisherSubject = PassthroughSubject() - var sessionResponsePublisher: AnyPublisher { + public var sessionResponsePublisher: AnyPublisher { sessionResponsePublisherSubject.eraseToAnyPublisher() } var sessionRejectionPublisherSubject = PassthroughSubject<(Session.Proposal, Reason), Never>() - var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> { + public var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> { sessionRejectionPublisherSubject.eraseToAnyPublisher() } var sessionUpdatePublisherSubject = PassthroughSubject<(String, [String : SessionNamespace]), Never>() - var sessionUpdatePublisher: AnyPublisher<(String, [String : SessionNamespace]), Never> { + public var sessionUpdatePublisher: AnyPublisher<(String, [String : SessionNamespace]), Never> { sessionUpdatePublisherSubject.eraseToAnyPublisher() } From 4accdfa8a1a20f657d096c891db3733ec0640d63 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:48:35 +0200 Subject: [PATCH 10/22] add Auth to sample dapp --- .../DApp/ Accounts/AccountsViewController.swift | 3 +-- .../AccountRequestViewController.swift | 3 +-- Example/DApp/Connect/ConnectViewController.swift | 4 ++-- Example/DApp/ResponseViewController.swift | 2 +- Example/DApp/SceneDelegate.swift | 16 ++++++++++------ .../SelectChain/SelectChainViewController.swift | 10 ++++++---- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Example/DApp/ Accounts/AccountsViewController.swift b/Example/DApp/ Accounts/AccountsViewController.swift index b1a85fbc2..620fc400b 100644 --- a/Example/DApp/ Accounts/AccountsViewController.swift +++ b/Example/DApp/ Accounts/AccountsViewController.swift @@ -9,7 +9,6 @@ struct AccountDetails { final class AccountsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { - let client = ClientDelegate.shared.client let session: Session var accountsDetails: [AccountDetails] = [] var onDisconnect: (()->())? @@ -54,7 +53,7 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT private func disconnect() { Task { do { - try await client.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect")) + try await Auth.instance.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect")) DispatchQueue.main.async { [weak self] in self?.onDisconnect?() } diff --git a/Example/DApp/AccountRequest/AccountRequestViewController.swift b/Example/DApp/AccountRequest/AccountRequestViewController.swift index 862d26dc9..33ae48423 100644 --- a/Example/DApp/AccountRequest/AccountRequestViewController.swift +++ b/Example/DApp/AccountRequest/AccountRequestViewController.swift @@ -7,7 +7,6 @@ import WalletConnectUtils class AccountRequestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { private let session: Session - private let client: AuthClient = ClientDelegate.shared.client private let chainId: String private let account: String private let methods = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"] @@ -61,7 +60,7 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab let request = Request(topic: session.topic, method: method, params: requestParams, chainId: Blockchain(chainId)!) Task { do { - try await client.request(params: request) + try await Auth.instance.request(params: request) DispatchQueue.main.async { [weak self] in self?.presentConfirmationAlert() } diff --git a/Example/DApp/Connect/ConnectViewController.swift b/Example/DApp/Connect/ConnectViewController.swift index 6aa33618c..498927525 100644 --- a/Example/DApp/Connect/ConnectViewController.swift +++ b/Example/DApp/Connect/ConnectViewController.swift @@ -5,7 +5,7 @@ import WalletConnectAuth class ConnectViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { let uriString: String - let activePairings: [Pairing] = ClientDelegate.shared.client.getSettledPairings() + let activePairings: [Pairing] = Auth.instance.getSettledPairings() let segmentedControl = UISegmentedControl(items: ["Pairings", "New Pairing"]) init(uri: String) { @@ -99,7 +99,7 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie let methods: Set = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"] let namespaces: [String: ProposalNamespace] = ["eip155": ProposalNamespace(chains: blockchains, methods: methods, events: [], extension: nil)] Task { - _ = try await ClientDelegate.shared.client.connect(requiredNamespaces: namespaces, topic: pairingTopic) + _ = try await Auth.instance.connect(requiredNamespaces: namespaces, topic: pairingTopic) connectWithExampleWallet() } } diff --git a/Example/DApp/ResponseViewController.swift b/Example/DApp/ResponseViewController.swift index 34fe0d56a..c7c4b45b4 100644 --- a/Example/DApp/ResponseViewController.swift +++ b/Example/DApp/ResponseViewController.swift @@ -24,7 +24,7 @@ class ResponseViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let record = ClientDelegate.shared.client.getSessionRequestRecord(id: response.result.id)! + let record = Auth.instance.getSessionRequestRecord(id: response.result.id)! switch response.result { case .response(let response): responseView.nameLabel.text = "Received Response\n\(record.request.method)" diff --git a/Example/DApp/SceneDelegate.swift b/Example/DApp/SceneDelegate.swift index 4ac4aad3e..3857605e8 100644 --- a/Example/DApp/SceneDelegate.swift +++ b/Example/DApp/SceneDelegate.swift @@ -1,10 +1,12 @@ import UIKit import WalletConnectAuth +import Combine class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? + private var publishers = [AnyCancellable]() func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { @@ -19,14 +21,16 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { url: "wallet.connect", icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) Auth.configure(Auth.Config(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a")) - Auth.instance.sessionDeletePublisher.sink { [unowned self] in + Auth.instance.sessionDeletePublisher.sink { [unowned self] _ in showSelectChainScreen() - } - - ClientDelegate.shared.onSessionResponse = { [unowned self] response in + }.store(in: &publishers) + + Auth.instance.sessionResponsePublisher.sink { [unowned self] response in presentResponse(for: response) - } - if let session = ClientDelegate.shared.client.getSettledSessions().first { + }.store(in: &publishers) + + + if let session = Auth.instance.getSettledSessions().first { showAccountsScreen(session) } else { showSelectChainScreen() diff --git a/Example/DApp/SelectChain/SelectChainViewController.swift b/Example/DApp/SelectChain/SelectChainViewController.swift index 2e069fae9..23428b806 100644 --- a/Example/DApp/SelectChain/SelectChainViewController.swift +++ b/Example/DApp/SelectChain/SelectChainViewController.swift @@ -3,6 +3,7 @@ import Foundation import WalletConnectAuth import UIKit +import Combine struct Chain { let name: String @@ -13,17 +14,18 @@ class SelectChainViewController: UIViewController, UITableViewDataSource { private let selectChainView: SelectChainView = { SelectChainView() }() + private var publishers = [AnyCancellable]() + let chains = [Chain(name: "Ethereum", id: "eip155:1"), Chain(name: "Polygon", id: "eip155:137")] - let client = ClientDelegate.shared.client var onSessionSettled: ((Session)->())? override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "Available Chains" selectChainView.tableView.dataSource = self selectChainView.connectButton.addTarget(self, action: #selector(connect), for: .touchUpInside) - ClientDelegate.shared.onSessionSettled = { [unowned self] session in + Auth.instance.sessionSettlePublisher.sink {[unowned self] session in onSessionSettled?(session) - } + }.store(in: &publishers) } override func loadView() { @@ -39,7 +41,7 @@ class SelectChainViewController: UIViewController, UITableViewDataSource { let blockchains: Set = [Blockchain("eip155:1")!, Blockchain("eip155:137")!] let namespaces: [String: ProposalNamespace] = ["eip155": ProposalNamespace(chains: blockchains, methods: methods, events: [], extension: nil)] Task { - let uri = try await client.connect(requiredNamespaces: namespaces) + let uri = try await Auth.instance.connect(requiredNamespaces: namespaces) showConnectScreen(uriString: uri!) } } From 9f5601e7504e07094624fbb61038e1e2a6b49595 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:49:10 +0200 Subject: [PATCH 11/22] remove client delegate --- Example/DApp/ClientDelegate.swift | 46 -------------------- Example/ExampleApp.xcodeproj/project.pbxproj | 4 -- 2 files changed, 50 deletions(-) delete mode 100644 Example/DApp/ClientDelegate.swift diff --git a/Example/DApp/ClientDelegate.swift b/Example/DApp/ClientDelegate.swift deleted file mode 100644 index e6ae3ac59..000000000 --- a/Example/DApp/ClientDelegate.swift +++ /dev/null @@ -1,46 +0,0 @@ -import WalletConnectAuth -import WalletConnectRelay - -class ClientDelegate: AuthClientDelegate { - func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { - print(status) - } - - var client: AuthClient - var onSessionSettled: ((Session)->())? - var onSessionResponse: ((Response)->())? - var onSessionDelete: (()->())? - - static var shared: ClientDelegate = ClientDelegate() - private init() { - let metadata = AppMetadata( - name: "Swift Dapp", - description: "a description", - url: "wallet.connect", - icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) - let relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: "8ba9ee138960775e5231b70cc5ef1c3a") - self.client = AuthClient(metadata: metadata, relayClient: relayClient) - client.logger.setLogging(level: .debug) - client.delegate = self - } - - func didSettle(session: Session) { - onSessionSettled?(session) - } - - func didDelete(sessionTopic: String, reason: Reason) { - onSessionDelete?() - } - - func didReceive(sessionResponse: Response) { - onSessionResponse?(sessionResponse) - } - - func didReject(proposal: Session.Proposal, reason: Reason) { - - } - - func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { - - } -} diff --git a/Example/ExampleApp.xcodeproj/project.pbxproj b/Example/ExampleApp.xcodeproj/project.pbxproj index 074055429..e950d8d7b 100644 --- a/Example/ExampleApp.xcodeproj/project.pbxproj +++ b/Example/ExampleApp.xcodeproj/project.pbxproj @@ -40,7 +40,6 @@ 84CE64392798228D00142511 /* Web3 in Frameworks */ = {isa = PBXBuildFile; productRef = 84CE64382798228D00142511 /* Web3 */; }; 84CE643D2798322600142511 /* ConnectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE643C2798322600142511 /* ConnectViewController.swift */; }; 84CE6444279AB5AD00142511 /* SelectChainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE6443279AB5AD00142511 /* SelectChainViewController.swift */; }; - 84CE6446279ABBF300142511 /* ClientDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE6445279ABBF300142511 /* ClientDelegate.swift */; }; 84CE6448279AE68600142511 /* AccountRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE6447279AE68600142511 /* AccountRequestViewController.swift */; }; 84CE644B279EA1FA00142511 /* AccountRequestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE644A279EA1FA00142511 /* AccountRequestView.swift */; }; 84CE644E279ED2FF00142511 /* SelectChainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE644D279ED2FF00142511 /* SelectChainView.swift */; }; @@ -113,7 +112,6 @@ 84CE642C27981DF000142511 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84CE643C2798322600142511 /* ConnectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectViewController.swift; sourceTree = ""; }; 84CE6443279AB5AD00142511 /* SelectChainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectChainViewController.swift; sourceTree = ""; }; - 84CE6445279ABBF300142511 /* ClientDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientDelegate.swift; sourceTree = ""; }; 84CE6447279AE68600142511 /* AccountRequestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRequestViewController.swift; sourceTree = ""; }; 84CE644A279EA1FA00142511 /* AccountRequestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRequestView.swift; sourceTree = ""; }; 84CE644D279ED2FF00142511 /* SelectChainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectChainView.swift; sourceTree = ""; }; @@ -276,7 +274,6 @@ 84CE642027981DED00142511 /* SceneDelegate.swift */, 84CE645427A29D4C00142511 /* ResponseViewController.swift */, 84CE6449279EA1E600142511 /* AccountRequest */, - 84CE6445279ABBF300142511 /* ClientDelegate.swift */, 84CE644C279ED2EC00142511 /* SelectChain */, 84CE6450279ED41D00142511 /* Connect */, 84CE644F279ED3FB00142511 /* Accounts */, @@ -540,7 +537,6 @@ files = ( 84CE6430279820F600142511 /* AccountsViewController.swift in Sources */, 84CE645527A29D4D00142511 /* ResponseViewController.swift in Sources */, - 84CE6446279ABBF300142511 /* ClientDelegate.swift in Sources */, 84CE641F27981DED00142511 /* AppDelegate.swift in Sources */, 84CE6452279ED42B00142511 /* ConnectView.swift in Sources */, 84CE6448279AE68600142511 /* AccountRequestViewController.swift in Sources */, From f8fd18d525db1b156439ef2c1e9af7eb8261fae9 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:54:19 +0200 Subject: [PATCH 12/22] fix dapp with Auth consumption --- Example/DApp/SelectChain/SelectChainViewController.swift | 2 -- Sources/WalletConnectAuth/Auth.swift | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Example/DApp/SelectChain/SelectChainViewController.swift b/Example/DApp/SelectChain/SelectChainViewController.swift index 23428b806..cc6be5375 100644 --- a/Example/DApp/SelectChain/SelectChainViewController.swift +++ b/Example/DApp/SelectChain/SelectChainViewController.swift @@ -30,8 +30,6 @@ class SelectChainViewController: UIViewController, UITableViewDataSource { override func loadView() { view = selectChainView - - } @objc diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index 5d4b41088..c2988306c 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -16,6 +16,7 @@ public class Auth { } let relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) client = AuthClient(metadata: config.metadata, relayClient: relayClient) + client.delegate = self } static public func configure(_ config: Config) { @@ -75,6 +76,14 @@ extension Auth: AuthClientDelegate { public func didSettle(session: Session) { sessionSettlePublisherSubject.send(session) } + + public func didReceive(sessionResponse: Response) { + sessionResponsePublisherSubject.send(sessionResponse) + } + + public func didReject(proposal: Session.Proposal, reason: Reason) { + + } } From 79b5e073b9bb7397c381106c58862a7e7d9a8d5e Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 10:58:01 +0200 Subject: [PATCH 13/22] subscribe main scheduler --- Example/DApp/SceneDelegate.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Example/DApp/SceneDelegate.swift b/Example/DApp/SceneDelegate.swift index 3857605e8..73a85be39 100644 --- a/Example/DApp/SceneDelegate.swift +++ b/Example/DApp/SceneDelegate.swift @@ -21,10 +21,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { url: "wallet.connect", icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) Auth.configure(Auth.Config(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a")) - Auth.instance.sessionDeletePublisher.sink { [unowned self] _ in - showSelectChainScreen() - }.store(in: &publishers) - + Auth.instance.sessionDeletePublisher + .receive(on: DispatchQueue.main) + .sink { [unowned self] _ in + showSelectChainScreen() + }.store(in: &publishers) + Auth.instance.sessionResponsePublisher.sink { [unowned self] response in presentResponse(for: response) }.store(in: &publishers) From b0c6c02817284733822e25eb9108883390a097b4 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 12:03:00 +0200 Subject: [PATCH 14/22] add all delegate methods to Auth --- Sources/WalletConnectAuth/Auth.swift | 31 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index c2988306c..55a80ce6b 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -61,30 +61,47 @@ public class Auth { } extension Auth: AuthClientDelegate { - public func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { - socketConnectionStatusPublisherSubject.send(status) + + public func didReceive(sessionProposal: Session.Proposal) { + + } + + public func didReceive(sessionRequest: Request) { + } - public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { - sessionUpdatePublisherSubject.send((sessionTopic, namespaces)) + public func didReceive(sessionResponse: Response) { + sessionResponsePublisherSubject.send(sessionResponse) } public func didDelete(sessionTopic: String, reason: Reason) { sessionDeletePublisherSubject.send((sessionTopic, reason)) } + + public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { + sessionUpdatePublisherSubject.send((sessionTopic, namespaces)) + } + + public func didUpdate(sessionTopic: String, expiry: Date) { + + } + public func didSettle(session: Session) { sessionSettlePublisherSubject.send(session) } - public func didReceive(sessionResponse: Response) { - sessionResponsePublisherSubject.send(sessionResponse) + public func didReceive(event: Session.Event, sessionTopic: String, chainId: Blockchain?) { + } public func didReject(proposal: Session.Proposal, reason: Reason) { } - + + public func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { + socketConnectionStatusPublisherSubject.send(status) + } } extension Auth { From 85ec300388dbf79c74ff944b47f0f67bd258b19e Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 12:13:41 +0200 Subject: [PATCH 15/22] Add missing Auth publishers --- Sources/WalletConnectAuth/Auth.swift | 39 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth.swift index 55a80ce6b..d8a03c0c4 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth.swift @@ -23,16 +23,21 @@ public class Auth { Auth.config = config } - var socketConnectionStatusPublisherSubject = PassthroughSubject() - public var socketConnectionStatusPublisher: AnyPublisher { - socketConnectionStatusPublisherSubject.eraseToAnyPublisher() - } - var sessionProposalPublisherSubject = PassthroughSubject() public var sessionProposalPublisher: AnyPublisher { sessionProposalPublisherSubject.eraseToAnyPublisher() } + var sessionRequestPublisherSubject = PassthroughSubject() + public var sessionRequestPublisher: AnyPublisher { + sessionRequestPublisherSubject.eraseToAnyPublisher() + } + + var socketConnectionStatusPublisherSubject = PassthroughSubject() + public var socketConnectionStatusPublisher: AnyPublisher { + socketConnectionStatusPublisherSubject.eraseToAnyPublisher() + } + var sessionSettlePublisherSubject = PassthroughSubject() public var sessionSettlePublisher: AnyPublisher { sessionSettlePublisherSubject.eraseToAnyPublisher() @@ -53,21 +58,30 @@ public class Auth { sessionRejectionPublisherSubject.eraseToAnyPublisher() } - var sessionUpdatePublisherSubject = PassthroughSubject<(String, [String : SessionNamespace]), Never>() - public var sessionUpdatePublisher: AnyPublisher<(String, [String : SessionNamespace]), Never> { + var sessionUpdatePublisherSubject = PassthroughSubject<(sessionTopic: String, namespaces: [String : SessionNamespace]), Never>() + public var sessionUpdatePublisher: AnyPublisher<(sessionTopic: String, namespaces: [String : SessionNamespace]), Never> { sessionUpdatePublisherSubject.eraseToAnyPublisher() } + var sessionEventPublisherSubject = PassthroughSubject<(event: Session.Event, sessionTopic: String, chainId: Blockchain?), Never>() + public var sessionEventPublisher: AnyPublisher<(event: Session.Event, sessionTopic: String, chainId: Blockchain?), Never> { + sessionEventPublisherSubject.eraseToAnyPublisher() + } + + var sessionUpdateExpiryPublisherSubject = PassthroughSubject<(sessionTopic: String, expiry: Date), Never>() + public var sessionUpdateExpiryPublisher: AnyPublisher<(sessionTopic: String, expiry: Date), Never> { + sessionUpdateExpiryPublisherSubject.eraseToAnyPublisher() + } } extension Auth: AuthClientDelegate { public func didReceive(sessionProposal: Session.Proposal) { - + sessionProposalPublisherSubject.send(sessionProposal) } public func didReceive(sessionRequest: Request) { - + sessionRequestPublisherSubject.send(sessionRequest) } public func didReceive(sessionResponse: Response) { @@ -78,13 +92,12 @@ extension Auth: AuthClientDelegate { sessionDeletePublisherSubject.send((sessionTopic, reason)) } - public func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { sessionUpdatePublisherSubject.send((sessionTopic, namespaces)) } public func didUpdate(sessionTopic: String, expiry: Date) { - + sessionUpdateExpiryPublisherSubject.send((sessionTopic, expiry)) } public func didSettle(session: Session) { @@ -92,11 +105,11 @@ extension Auth: AuthClientDelegate { } public func didReceive(event: Session.Event, sessionTopic: String, chainId: Blockchain?) { - + sessionEventPublisherSubject.send((event, sessionTopic, chainId)) } public func didReject(proposal: Session.Proposal, reason: Reason) { - + sessionRejectionPublisherSubject.send((proposal, reason)) } public func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { From 7fef5dbe7f0aec898106a7a9da27581350511b55 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 12:16:11 +0200 Subject: [PATCH 16/22] restructure project --- Sources/WalletConnectAuth/{ => Auth}/Auth.swift | 1 - Sources/WalletConnectAuth/{ => Auth}/AuthClient.swift | 0 Sources/WalletConnectAuth/{ => Auth}/AuthClientDelegate.swift | 0 Sources/WalletConnectAuth/{ => Auth}/AuthConfig.swift | 0 Sources/WalletConnectAuth/Auth/SocketConnectionStatus.swift | 3 +++ 5 files changed, 3 insertions(+), 1 deletion(-) rename Sources/WalletConnectAuth/{ => Auth}/Auth.swift (99%) rename Sources/WalletConnectAuth/{ => Auth}/AuthClient.swift (100%) rename Sources/WalletConnectAuth/{ => Auth}/AuthClientDelegate.swift (100%) rename Sources/WalletConnectAuth/{ => Auth}/AuthConfig.swift (100%) create mode 100644 Sources/WalletConnectAuth/Auth/SocketConnectionStatus.swift diff --git a/Sources/WalletConnectAuth/Auth.swift b/Sources/WalletConnectAuth/Auth/Auth.swift similarity index 99% rename from Sources/WalletConnectAuth/Auth.swift rename to Sources/WalletConnectAuth/Auth/Auth.swift index d8a03c0c4..325340b1b 100644 --- a/Sources/WalletConnectAuth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth/Auth.swift @@ -4,7 +4,6 @@ import WalletConnectUtils import WalletConnectRelay import Combine -public typealias SocketConnectionStatus = WalletConnectRelay.SocketConnectionStatus public class Auth { static public let instance = Auth() private let client: AuthClient diff --git a/Sources/WalletConnectAuth/AuthClient.swift b/Sources/WalletConnectAuth/Auth/AuthClient.swift similarity index 100% rename from Sources/WalletConnectAuth/AuthClient.swift rename to Sources/WalletConnectAuth/Auth/AuthClient.swift diff --git a/Sources/WalletConnectAuth/AuthClientDelegate.swift b/Sources/WalletConnectAuth/Auth/AuthClientDelegate.swift similarity index 100% rename from Sources/WalletConnectAuth/AuthClientDelegate.swift rename to Sources/WalletConnectAuth/Auth/AuthClientDelegate.swift diff --git a/Sources/WalletConnectAuth/AuthConfig.swift b/Sources/WalletConnectAuth/Auth/AuthConfig.swift similarity index 100% rename from Sources/WalletConnectAuth/AuthConfig.swift rename to Sources/WalletConnectAuth/Auth/AuthConfig.swift diff --git a/Sources/WalletConnectAuth/Auth/SocketConnectionStatus.swift b/Sources/WalletConnectAuth/Auth/SocketConnectionStatus.swift new file mode 100644 index 000000000..f9cf90b1e --- /dev/null +++ b/Sources/WalletConnectAuth/Auth/SocketConnectionStatus.swift @@ -0,0 +1,3 @@ +import WalletConnectRelay + +public typealias SocketConnectionStatus = WalletConnectRelay.SocketConnectionStatus From 1c1c20e07b378b440f522752da6c0d50c9d51332 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 20 May 2022 12:37:21 +0200 Subject: [PATCH 17/22] Add Auth to the sample wallet --- Example/ExampleApp/SceneDelegate.swift | 11 +- .../SessionDetailsViewController.swift | 16 +-- .../Wallet/WalletViewController.swift | 124 +++++++----------- Sources/WalletConnectAuth/Auth/Auth.swift | 2 + 4 files changed, 70 insertions(+), 83 deletions(-) diff --git a/Example/ExampleApp/SceneDelegate.swift b/Example/ExampleApp/SceneDelegate.swift index de23ce81c..bbe9aeaa9 100644 --- a/Example/ExampleApp/SceneDelegate.swift +++ b/Example/ExampleApp/SceneDelegate.swift @@ -1,10 +1,19 @@ import UIKit +import WalletConnectAuth class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + + let metadata = AppMetadata( + name: "Example Wallet", + description: "wallet description", + url: "example.wallet", + icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) + Auth.configure(Auth.Config(metadata: metadata, projectId: "8ba9ee138960775e5231b70cc5ef1c3a")) + guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(windowScene: windowScene) window?.rootViewController = UITabBarController.createExampleApp() @@ -21,7 +30,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { vc.onClientConnected = { Task { do { - try await vc.client.pair(uri: wcUri) + try await Auth.instance.pair(uri: wcUri) } catch { print(error) } diff --git a/Example/ExampleApp/SessionDetails/SessionDetailsViewController.swift b/Example/ExampleApp/SessionDetails/SessionDetailsViewController.swift index d745268eb..44af78efb 100644 --- a/Example/ExampleApp/SessionDetails/SessionDetailsViewController.swift +++ b/Example/ExampleApp/SessionDetails/SessionDetailsViewController.swift @@ -7,10 +7,9 @@ final class SessionDetailsViewController: UIViewController, UITableViewDelegate, SessionDetailsView() }() private var sessionInfo: SessionInfo - private let client: AuthClient private let session: Session - init(_ session: Session, _ client: AuthClient) { - let pendingRequests = client.getPendingRequests(topic: session.topic).map{$0.method} + init(_ session: Session) { + let pendingRequests = Auth.instance.getPendingRequests(topic: session.topic).map{$0.method} let chains = Array(session.namespaces.values.flatMap { n in n.accounts.map{$0.blockchain.absoluteString}}) let methods = Array(session.namespaces.values.first?.methods ?? []) // TODO: Rethink how to show this info on example app self.sessionInfo = SessionInfo(name: session.peer.name, @@ -20,7 +19,6 @@ final class SessionDetailsViewController: UIViewController, UITableViewDelegate, chains: chains, methods: methods, pendingRequests: pendingRequests) - self.client = client self.session = session super.init(nibName: nil, bundle: nil) } @@ -51,7 +49,7 @@ final class SessionDetailsViewController: UIViewController, UITableViewDelegate, @objc private func ping() { - client.ping(topic: session.topic) { result in + Auth.instance.ping(topic: session.topic) { result in switch result { case .success(): print("received ping response") @@ -101,7 +99,7 @@ final class SessionDetailsViewController: UIViewController, UITableViewDelegate, func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.section == 2 { - let pendingRequests = client.getPendingRequests(topic: session.topic) + let pendingRequests = Auth.instance.getPendingRequests(topic: session.topic) showSessionRequest(pendingRequests[indexPath.row]) } } @@ -111,18 +109,18 @@ final class SessionDetailsViewController: UIViewController, UITableViewDelegate, requestVC.onSign = { [unowned self] in let result = Signer.signEth(request: sessionRequest) let response = JSONRPCResponse(id: sessionRequest.id, result: result) - client.respond(topic: sessionRequest.topic, response: .response(response)) + Auth.instance.respond(topic: sessionRequest.topic, response: .response(response)) reloadTable() } requestVC.onReject = { [unowned self] in - client.respond(topic: sessionRequest.topic, response: .error(JSONRPCErrorResponse(id: sessionRequest.id, error: JSONRPCErrorResponse.Error(code: 0, message: "")))) + Auth.instance.respond(topic: sessionRequest.topic, response: .error(JSONRPCErrorResponse(id: sessionRequest.id, error: JSONRPCErrorResponse.Error(code: 0, message: "")))) reloadTable() } present(requestVC, animated: true) } func reloadTable() { - let pendingRequests = client.getPendingRequests(topic: session.topic).map{$0.method} + let pendingRequests = Auth.instance.getPendingRequests(topic: session.topic).map{$0.method} let chains = Array(session.namespaces.values.flatMap { n in n.accounts.map{$0.blockchain.absoluteString}}) let methods = Array(session.namespaces.values.first?.methods ?? []) // TODO: Rethink how to show this info on example app self.sessionInfo = SessionInfo(name: session.peer.name, diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index 5ab0fb604..798dd425f 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -3,26 +3,15 @@ import WalletConnectAuth import WalletConnectUtils import Web3 import CryptoSwift +import Combine final class WalletViewController: UIViewController { - - let client: AuthClient = { - let metadata = AppMetadata( - name: "Example Wallet", - description: "wallet description", - url: "example.wallet", - icons: ["https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media"]) - return AuthClient( - metadata: metadata, - projectId: "8ba9ee138960775e5231b70cc5ef1c3a", - relayHost: "relay.walletconnect.com" - ) - }() lazy var account = Signer.privateKey.address.hex(eip55: true) var sessionItems: [ActiveSessionItem] = [] var currentProposal: Session.Proposal? var onClientConnected: (()->())? - + private var publishers = [AnyCancellable]() + private let walletView: WalletView = { WalletView() }() @@ -39,10 +28,10 @@ final class WalletViewController: UIViewController { walletView.tableView.dataSource = self walletView.tableView.delegate = self - let settledSessions = client.getSettledSessions() + let settledSessions = Auth.instance.getSettledSessions() sessionItems = getActiveSessionItem(for: settledSessions) - client.delegate = self - client.logger.setLogging(level: .debug) + Auth.instance.logger.setLogging(level: .debug) + setUpAuthSubscribing() } @objc @@ -67,7 +56,7 @@ final class WalletViewController: UIViewController { } private func showSessionDetailsViewController(_ session: Session) { - let vc = SessionDetailsViewController(session, client) + let vc = SessionDetailsViewController(session) navigationController?.pushViewController(vc, animated: true) } @@ -76,11 +65,11 @@ final class WalletViewController: UIViewController { requestVC.onSign = { [unowned self] in let result = Signer.signEth(request: sessionRequest) let response = JSONRPCResponse(id: sessionRequest.id, result: result) - client.respond(topic: sessionRequest.topic, response: .response(response)) + Auth.instance.respond(topic: sessionRequest.topic, response: .response(response)) reloadSessionDetailsIfNeeded() } requestVC.onReject = { [unowned self] in - client.respond(topic: sessionRequest.topic, response: .error(JSONRPCErrorResponse(id: sessionRequest.id, error: JSONRPCErrorResponse.Error(code: 0, message: "")))) + Auth.instance.respond(topic: sessionRequest.topic, response: .error(JSONRPCErrorResponse(id: sessionRequest.id, error: JSONRPCErrorResponse.Error(code: 0, message: "")))) reloadSessionDetailsIfNeeded() } reloadSessionDetailsIfNeeded() @@ -97,7 +86,7 @@ final class WalletViewController: UIViewController { print("[RESPONDER] Pairing to: \(uri)") Task { do { - try await client.pair(uri: uri) + try await Auth.instance.pair(uri: uri) } catch { print("[PROPOSER] Pairing connect error: \(error)") } @@ -122,7 +111,7 @@ extension WalletViewController: UITableViewDataSource, UITableViewDelegate { let item = sessionItems[indexPath.row] Task { do { - try await client.disconnect(topic: item.topic, reason: Reason(code: 0, message: "disconnect")) + try await Auth.instance.disconnect(topic: item.topic, reason: Reason(code: 0, message: "disconnect")) DispatchQueue.main.async { [weak self] in self?.sessionItems.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .automatic) @@ -141,7 +130,7 @@ extension WalletViewController: UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print("did select row \(indexPath)") let itemTopic = sessionItems[indexPath.row].topic - if let session = client.getSettledSessions().first{$0.topic == itemTopic} { + if let session = Auth.instance.getSettledSessions().first{$0.topic == itemTopic} { showSessionDetailsViewController(session) } } @@ -173,67 +162,56 @@ extension WalletViewController: ProposalViewControllerDelegate { let sessionNamespace = SessionNamespace(accounts: accounts, methods: proposalNamespace.methods, events: proposalNamespace.events, extension: extensions) sessionNamespaces[caip2Namespace] = sessionNamespace } - try! client.approve(proposalId: proposal.id, namespaces: sessionNamespaces) + try! Auth.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces) } func didRejectSession() { print("did reject session") let proposal = currentProposal! currentProposal = nil - client.reject(proposal: proposal, reason: .disapprovedChains) + Auth.instance.reject(proposal: proposal, reason: .disapprovedChains) } } -extension WalletViewController: AuthClientDelegate { - func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { - if status == .connected { - onClientConnected?() - print("Client connected") - } - } - - func didChangeSocketConnectionStatus() { +extension WalletViewController { + func setUpAuthSubscribing() { + Auth.instance.socketConnectionStatusPublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] status in + if status == .connected { + self?.onClientConnected?() + print("Client connected") + } + }.store(in: &publishers) - - } - - func didUpdate(sessionTopic: String, namespaces: [String : SessionNamespace]) { - - } - - // TODO: Adapt proposal data to be used on the view - func didReceive(sessionProposal: Session.Proposal) { - print("[RESPONDER] WC: Did receive session proposal") -// let appMetadata = sessionProposal.proposer -// let info = SessionInfo( -// name: appMetadata.name, -// descriptionText: appMetadata.description, -// dappURL: appMetadata.url, -// iconURL: appMetadata.icons.first ?? "", -// chains: Array(sessionProposal.namespaces.first?.chains.map { $0.absoluteString } ?? []), -// methods: Array(sessionProposal.namespaces.first?.methods ?? []), pendingRequests: []) - currentProposal = sessionProposal - DispatchQueue.main.async { // FIXME: Delegate being called from background thread - self.showSessionProposal(Proposal(proposal: sessionProposal)) // FIXME: Remove mock - } - } + // TODO: Adapt proposal data to be used on the view + Auth.instance.sessionProposalPublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] sessionProposal in + print("[RESPONDER] WC: Did receive session proposal") + self?.currentProposal = sessionProposal + self?.showSessionProposal(Proposal(proposal: sessionProposal)) // FIXME: Remove mock + }.store(in: &publishers) - func didSettle(session: Session) { - reloadActiveSessions() - } + Auth.instance.sessionSettlePublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] _ in + self?.reloadActiveSessions() + }.store(in: &publishers) - func didReceive(sessionRequest: Request) { - DispatchQueue.main.async { [weak self] in - self?.showSessionRequest(sessionRequest) - } - print("[RESPONDER] WC: Did receive session request") - } - - func didDelete(sessionTopic: String, reason: Reason) { - reloadActiveSessions() - DispatchQueue.main.async { [unowned self] in - navigationController?.popToRootViewController(animated: true) - } + Auth.instance.sessionRequestPublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] sessionRequest in + print("[RESPONDER] WC: Did receive session request") + self?.showSessionRequest(sessionRequest) + }.store(in: &publishers) + + Auth.instance.sessionDeletePublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] sessionRequest in + self?.reloadActiveSessions() + self?.navigationController?.popToRootViewController(animated: true) + }.store(in: &publishers) } private func getActiveSessionItem(for settledSessions: [Session]) -> [ActiveSessionItem] { @@ -248,7 +226,7 @@ extension WalletViewController: AuthClientDelegate { } private func reloadActiveSessions() { - let settledSessions = client.getSettledSessions() + let settledSessions = Auth.instance.getSettledSessions() let activeSessions = getActiveSessionItem(for: settledSessions) DispatchQueue.main.async { // FIXME: Delegate being called from background thread self.sessionItems = activeSessions diff --git a/Sources/WalletConnectAuth/Auth/Auth.swift b/Sources/WalletConnectAuth/Auth/Auth.swift index 325340b1b..04e27b379 100644 --- a/Sources/WalletConnectAuth/Auth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth/Auth.swift @@ -8,6 +8,7 @@ public class Auth { static public let instance = Auth() private let client: AuthClient private static var config: Config? + public let logger: ConsoleLogging private init() { guard let config = Auth.config else { @@ -15,6 +16,7 @@ public class Auth { } let relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) client = AuthClient(metadata: config.metadata, relayClient: relayClient) + self.logger = client.logger client.delegate = self } From 2dfa918d4a7980316c44f57fcc952dacc516dbac Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Mon, 23 May 2022 15:31:56 +0200 Subject: [PATCH 18/22] add connect and disconnect methods to Auth --- Sources/WalletConnectAuth/Auth/Auth.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/WalletConnectAuth/Auth/Auth.swift b/Sources/WalletConnectAuth/Auth/Auth.swift index 04e27b379..4ade2c9b7 100644 --- a/Sources/WalletConnectAuth/Auth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth/Auth.swift @@ -9,12 +9,13 @@ public class Auth { private let client: AuthClient private static var config: Config? public let logger: ConsoleLogging + private let relayClient: RelayClient private init() { guard let config = Auth.config else { fatalError("Error - you must configure before accessing Auth.instance") } - let relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) + relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) client = AuthClient(metadata: config.metadata, relayClient: relayClient) self.logger = client.logger client.delegate = self @@ -239,4 +240,12 @@ extension Auth { public func getSessionRequestRecord(id: Int64) -> WalletConnectUtils.JsonRpcRecord? { client.getSessionRequestRecord(id: id) } + + public func connect() throws { + try relayClient.connect() + } + + public func disconnect(closeCode: URLSessionWebSocketTask.CloseCode) throws { + try relayClient.disconnect(closeCode: closeCode) + } } From 9f42b85d8371c37c6bfe79a7217ea98928e1c872 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Mon, 23 May 2022 15:38:08 +0200 Subject: [PATCH 19/22] fix tests --- Tests/IntegrationTests/ClientDelegate.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/IntegrationTests/ClientDelegate.swift b/Tests/IntegrationTests/ClientDelegate.swift index 42e06b379..3ec563aea 100644 --- a/Tests/IntegrationTests/ClientDelegate.swift +++ b/Tests/IntegrationTests/ClientDelegate.swift @@ -3,6 +3,10 @@ import Foundation @testable import WalletConnectAuth class ClientDelegate: AuthClientDelegate { + func didChangeSocketConnectionStatus(_ status: SocketConnectionStatus) { + onConnected?() + } + var client: AuthClient var onSessionSettled: ((Session)->())? var onConnected: (()->())? @@ -49,8 +53,6 @@ class ClientDelegate: AuthClientDelegate { func didReceive(sessionResponse: Response) { onSessionResponse?(sessionResponse) } - func didChangeSocketConnectionStatus() { - onConnected?() - } + func didDisconnect() {} } From f38eba398aa918286bfa1f72fb7922dfb46912eb Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 24 May 2022 08:33:21 +0200 Subject: [PATCH 20/22] adjust style --- Sources/WalletConnectAuth/Auth/Auth.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/WalletConnectAuth/Auth/Auth.swift b/Sources/WalletConnectAuth/Auth/Auth.swift index 4ade2c9b7..225e678ce 100644 --- a/Sources/WalletConnectAuth/Auth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth/Auth.swift @@ -5,10 +5,11 @@ import WalletConnectRelay import Combine public class Auth { - static public let instance = Auth() - private let client: AuthClient - private static var config: Config? + public static let instance = Auth() public let logger: ConsoleLogging + + private static var config: Config? + private let client: AuthClient private let relayClient: RelayClient private init() { From 9dadc26952e5256c50645c0ea67142366e8a9967 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 24 May 2022 08:44:55 +0200 Subject: [PATCH 21/22] remove logger from Auth --- Sources/WalletConnectAuth/Auth/Auth.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/WalletConnectAuth/Auth/Auth.swift b/Sources/WalletConnectAuth/Auth/Auth.swift index 225e678ce..00faa0fc1 100644 --- a/Sources/WalletConnectAuth/Auth/Auth.swift +++ b/Sources/WalletConnectAuth/Auth/Auth.swift @@ -6,7 +6,6 @@ import Combine public class Auth { public static let instance = Auth() - public let logger: ConsoleLogging private static var config: Config? private let client: AuthClient @@ -18,7 +17,6 @@ public class Auth { } relayClient = RelayClient(relayHost: "relay.walletconnect.com", projectId: config.projectId, socketConnectionType: config.socketConnectionType) client = AuthClient(metadata: config.metadata, relayClient: relayClient) - self.logger = client.logger client.delegate = self } From 842e551df7a90f69c13b38af6a934246114b6681 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Tue, 24 May 2022 09:50:33 +0200 Subject: [PATCH 22/22] fix build --- Example/ExampleApp/Wallet/WalletViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index e3ce014b3..12ae3a833 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -30,7 +30,6 @@ final class WalletViewController: UIViewController { walletView.tableView.delegate = self let settledSessions = Auth.instance.getSettledSessions() sessionItems = getActiveSessionItem(for: settledSessions) - Auth.instance.logger.setLogging(level: .debug) setUpAuthSubscribing() }