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

[Sign] add 6000 code on disconnect #328

Merged
merged 4 commits into from
Jul 12, 2022
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
4 changes: 2 additions & 2 deletions Example/DApp/ Accounts/AccountsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/ExampleApp/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Sign/SignClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 4 additions & 2 deletions Sources/WalletConnectSign/Engine/Common/SessionEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/WalletConnectSign/Sign/Sign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/WalletConnectSign/Sign/SignClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Sources/WalletConnectSign/Types/ReasonCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ enum ReasonCode {
case unsupportedAccounts
case unsupportedNamespaceKey

// 6000
case userDisconnected

var code: Int {
switch self {
case .generic: return 0
Expand Down Expand Up @@ -61,6 +64,8 @@ enum ReasonCode {
case .unsupportedEvents: return 5102
case .unsupportedAccounts: return 5103
case .unsupportedNamespaceKey: return 5104

case .userDisconnected: return 6000
}
}

Expand Down Expand Up @@ -108,6 +113,8 @@ enum ReasonCode {
return "Unsupported or empty accounts for namespace"
case .unsupportedNamespaceKey:
return "Unsupported namespace key"
case .userDisconnected:
return "User discconnected"
}
}
}