diff --git a/Example/DApp/ Accounts/AccountsViewController.swift b/Example/DApp/ Accounts/AccountsViewController.swift index 151d5d794..1856f867b 100644 --- a/Example/DApp/ Accounts/AccountsViewController.swift +++ b/Example/DApp/ Accounts/AccountsViewController.swift @@ -53,12 +53,12 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT private func disconnect() { Task { do { - try await Sign.instance.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect")) + try await Sign.instance.disconnect(topic: session.topic) DispatchQueue.main.async { [weak self] in self?.onDisconnect?() } } catch { - print(error) + print(error) // show failure alert } } diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index 48ddd8f9e..cc9b001e6 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -166,7 +166,7 @@ extension WalletViewController: UITableViewDataSource, UITableViewDelegate { let item = sessionItems[indexPath.row] Task { do { - try await Sign.instance.disconnect(topic: item.topic, reason: Reason(code: 0, message: "disconnect")) + try await Sign.instance.disconnect(topic: item.topic) DispatchQueue.main.async { [weak self] in self?.sessionItems.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .automatic) diff --git a/Example/IntegrationTests/Sign/SignClientTests.swift b/Example/IntegrationTests/Sign/SignClientTests.swift index 97a8d204b..e2cd14006 100644 --- a/Example/IntegrationTests/Sign/SignClientTests.swift +++ b/Example/IntegrationTests/Sign/SignClientTests.swift @@ -127,7 +127,7 @@ final class SignClientTests: XCTestCase { } dapp.onSessionSettled = { settledSession in Task(priority: .high) { - try await dapp.client.disconnect(topic: settledSession.topic, reason: Reason(code: 5900, message: "User disconnected session")) + try await dapp.client.disconnect(topic: settledSession.topic) } } wallet.onSessionDelete = { diff --git a/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift b/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift index a64ceadc3..6fc7c7a1d 100644 --- a/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift +++ b/Sources/WalletConnectSign/Engine/Common/SessionEngine.swift @@ -44,9 +44,11 @@ final class SessionEngine { sessionStore.getAll().map {$0.publicRepresentation()} } - func delete(topic: String, reason: Reason) async throws { + func delete(topic: String) async throws { + let reasonCode = ReasonCode.userDisconnected + let reason = SessionType.Reason(code: reasonCode.code, message: reasonCode.message) logger.debug("Will delete session for reason: message: \(reason.message) code: \(reason.code)") - try await networkingInteractor.request(.wcSessionDelete(reason.internalRepresentation()), onTopic: topic) + try await networkingInteractor.request(.wcSessionDelete(reason), onTopic: topic) sessionStore.delete(topic: topic) networkingInteractor.unsubscribe(topic: topic) } diff --git a/Sources/WalletConnectSign/Sign/Sign.swift b/Sources/WalletConnectSign/Sign/Sign.swift index f5eb6e5dc..b2c653610 100644 --- a/Sources/WalletConnectSign/Sign/Sign.swift +++ b/Sources/WalletConnectSign/Sign/Sign.swift @@ -230,9 +230,8 @@ extension Sign { /// - 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) + public func disconnect(topic: String) async throws { + try await client.disconnect(topic: topic) } /// - Returns: All sessions diff --git a/Sources/WalletConnectSign/Sign/SignClient.swift b/Sources/WalletConnectSign/Sign/SignClient.swift index 2d0e086aa..64f269a52 100644 --- a/Sources/WalletConnectSign/Sign/SignClient.swift +++ b/Sources/WalletConnectSign/Sign/SignClient.swift @@ -215,8 +215,8 @@ public final class SignClient { /// - 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 sessionEngine.delete(topic: topic, reason: reason) + public func disconnect(topic: String) async throws { + try await sessionEngine.delete(topic: topic) } /// - Returns: All sessions diff --git a/Sources/WalletConnectSign/Types/ReasonCode.swift b/Sources/WalletConnectSign/Types/ReasonCode.swift index 61061e9b6..496818936 100644 --- a/Sources/WalletConnectSign/Types/ReasonCode.swift +++ b/Sources/WalletConnectSign/Types/ReasonCode.swift @@ -34,6 +34,9 @@ enum ReasonCode { case unsupportedAccounts case unsupportedNamespaceKey + // 6000 + case userDisconnected + var code: Int { switch self { case .generic: return 0 @@ -61,6 +64,8 @@ enum ReasonCode { case .unsupportedEvents: return 5102 case .unsupportedAccounts: return 5103 case .unsupportedNamespaceKey: return 5104 + + case .userDisconnected: return 6000 } } @@ -108,6 +113,8 @@ enum ReasonCode { return "Unsupported or empty accounts for namespace" case .unsupportedNamespaceKey: return "Unsupported namespace key" + case .userDisconnected: + return "User discconnected" } } }