Skip to content

Commit

Permalink
Merge pull request #70 from WalletConnect/rejection-reasons
Browse files Browse the repository at this point in the history
Rejection reasons
  • Loading branch information
André Vants authored Feb 9, 2022
2 parents 54d57a6 + 6569ff4 commit 07cac7b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Example/ExampleApp/Responder/ResponderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ extension ResponderViewController: SessionViewControllerDelegate {
print("did reject session")
let proposal = currentProposal!
currentProposal = nil
client.reject(proposal: proposal, reason: Reason(code: 0, message: "reject"))
client.reject(proposal: proposal, reason: .disapprovedChains)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Relayer/WebSocketSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final class WebSocketSession: NSObject, WebSocketSessionProtocol, WebSocketConne
case .string(let text):
onMessageReceived?(text)
case .data(let data):
print("Transport: Unexpected type of message received: \(data)")
print("Transport: Unexpected type of message received: \(data.toHexString())")
@unknown default:
print("Transport: Unexpected type of message received")
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/WalletConnect/Engine/SessionEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ final class SessionEngine {
}
}

func reject(proposal: SessionProposal, reason: Reason) {
let rejectParams = SessionType.RejectParams(reason: reason.toInternal())
func reject(proposal: SessionProposal, reason: SessionType.Reason ) {
let rejectParams = SessionType.RejectParams(reason: reason)
relayer.request(.wcSessionReject(rejectParams), onTopic: proposal.topic) { [weak self] result in
self?.logger.debug("Reject result: \(result)")
}
Expand Down
22 changes: 22 additions & 0 deletions Sources/WalletConnect/RejectionReason.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import Foundation

/// https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-25.md
public enum RejectionReason {
case disapprovedChains
case disapprovedMethods
case disapprovedNotificationTypes
}

internal extension RejectionReason {
func internalRepresentation() -> SessionType.Reason {
switch self {
case .disapprovedChains:
return SessionType.Reason(code: 5000, message: "User disapproved requested chains")
case .disapprovedMethods:
return SessionType.Reason(code: 5001, message: "User disapproved requested json-rpc methods")
case .disapprovedNotificationTypes:
return SessionType.Reason(code: 5002, message: "User disapproved requested notification types")
}
}
}
6 changes: 3 additions & 3 deletions Sources/WalletConnect/WalletConnectClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public final class WalletConnectClient {
/// 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.
public func reject(proposal: Session.Proposal, reason: Reason) {
sessionEngine.reject(proposal: proposal.proposal, reason: reason)
/// - reason: Reason why the session proposal was rejected. Conforms to CAIP25.
public func reject(proposal: Session.Proposal, reason: RejectionReason) {
sessionEngine.reject(proposal: proposal.proposal, reason: reason.internalRepresentation())
}

/// For the responder to update the accounts
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Tests/IntegrationTests/ClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ final class ClientTests: XCTestCase {
let uri = try! proposer.client.connect(sessionPermissions: permissions)!
_ = try! responder.client.pair(uri: uri)
responder.onSessionProposal = {[unowned self] proposal in
self.responder.client.reject(proposal: proposal, reason: Reason(code: WalletConnectError.internal(.notApproved).code, message: WalletConnectError.internal(.notApproved).description))
self.responder.client.reject(proposal: proposal, reason: .disapprovedChains)
}
proposer.onSessionRejected = { _, reason in
XCTAssertEqual(reason.code, WalletConnectError.internal(.notApproved).code)
XCTAssertEqual(reason.code, 5000)
sessionRejectExpectation.fulfill()
}
waitForExpectations(timeout: defaultTimeout, handler: nil)
Expand Down

0 comments on commit 07cac7b

Please sign in to comment.