Skip to content

Commit

Permalink
add query session request record by jsonrpc id
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jan 28, 2022
1 parent aecc9db commit f694e29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Example/DApp/ResponseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ class ResponseViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let record = ClientDelegate.shared.client.getSessionRequestRecord(id: response.result.id)!
switch response.result {
case .response(let response):
responseView.nameLabel.text = "Received Response"
responseView.nameLabel.text = "Received Response\n\(record.request.method)"
responseView.descriptionLabel.text = try! response.result.get(String.self).description
case .error(let error):
responseView.nameLabel.text = "Received Error"
responseView.nameLabel.text = "Received Error\n\(record.request.method)"
responseView.descriptionLabel.text = error.error.message
}
responseView.dismissButton.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)
Expand All @@ -45,6 +46,7 @@ final class ResponseView: UIView {

let nameLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.font = UIFont.systemFont(ofSize: 17.0, weight: .heavy)
return label
}()
Expand Down
14 changes: 8 additions & 6 deletions Sources/WalletConnect/WalletConnectClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ public final class WalletConnectClient {
}
}

// /// <#Description#>
// /// - Parameter id: <#id description#>
// /// - Returns: <#description#>
// public func getSessionRequestRecord(id: Int64) -> [WalletConnectUtils.JsonRpcRecord] {
//
// }
/// - Parameter id: id of a wc_sessionPayload 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? {
guard let record = history.get(id: id),
case .sessionPayload(let payload) = record.request.params else {return nil}
let request = WalletConnectUtils.JsonRpcRecord.Request(method: payload.request.method, params: payload.request.params)
return WalletConnectUtils.JsonRpcRecord(id: record.id, topic: record.topic, request: request, response: record.response, chainId: record.chainId)
}

// MARK: - Private

Expand Down
13 changes: 13 additions & 0 deletions Sources/WalletConnectUtils/JsonRpcRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ public struct JsonRpcRecord: Codable {
public var response: JsonRpcResult?
public let chainId: String?

public init(id: Int64, topic: String, request: JsonRpcRecord.Request, response: JsonRpcResult? = nil, chainId: String?) {
self.id = id
self.topic = topic
self.request = request
self.response = response
self.chainId = chainId
}

public struct Request: Codable {
public let method: String
public let params: AnyCodable

public init(method: String, params: AnyCodable) {
self.method = method
self.params = params
}
}
}

0 comments on commit f694e29

Please sign in to comment.