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

Fast workaround fix for pairing responses #29

Merged
merged 2 commits into from
Jan 17, 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
2 changes: 1 addition & 1 deletion Sources/WalletConnect/Engine/PairingEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class PairingEngine {
removeRespondedPendingPairings()
restoreSubscriptions()

relayer.onResponse = { [weak self] in
relayer.onPairingResponse = { [weak self] in
self?.handleReponse($0)
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/WalletConnect/Relay/WalletConnectRelay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct WCResponse {
}

protocol WalletConnectRelaying: AnyObject {
var onPairingResponse: ((WCResponse) -> Void)? {get set} // Temporary workaround
var onResponse: ((WCResponse) -> Void)? {get set}
var transportConnectionPublisher: AnyPublisher<Void, Never> {get}
var wcRequestPublisher: AnyPublisher<WCRequestSubscriptionPayload, Never> {get}
Expand All @@ -22,6 +23,7 @@ protocol WalletConnectRelaying: AnyObject {

class WalletConnectRelay: WalletConnectRelaying {

var onPairingResponse: ((WCResponse) -> Void)?
var onResponse: ((WCResponse) -> Void)?

private var networkRelayer: NetworkRelaying
Expand Down Expand Up @@ -164,6 +166,7 @@ class WalletConnectRelay: WalletConnectRelaying {
requestParams: record.request.params,
result: .success(response))
wcResponsePublisherSubject.send(.response(response))
onPairingResponse?(wcResponse)
onResponse?(wcResponse)
} catch {
logger.info("Info: \(error.localizedDescription)")
Expand All @@ -179,6 +182,7 @@ class WalletConnectRelay: WalletConnectRelaying {
requestParams: record.request.params,
result: .failure(response))
wcResponsePublisherSubject.send(.error(response))
onPairingResponse?(wcResponse)
onResponse?(wcResponse)
} catch {
logger.info("Info: \(error.localizedDescription)")
Expand Down
1 change: 1 addition & 0 deletions Tests/WalletConnectTests/Mocks/MockedRelay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import WalletConnectUtils

class MockedWCRelay: WalletConnectRelaying {

var onPairingResponse: ((WCResponse) -> Void)?
var onResponse: ((WCResponse) -> Void)?

var onPairingApproveResponse: ((String) -> Void)?
Expand Down
2 changes: 1 addition & 1 deletion Tests/WalletConnectTests/PairingEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class PairingEngineTests: XCTestCase {
try engine.approve(uri)
let success = JSONRPCResponse<AnyCodable>(id: 0, result: AnyCodable(true))
let response = WCResponse(topic: topicA, requestMethod: .pairingApprove, requestParams: .pairingApprove(PairingType.ApprovalParams(relay: RelayProtocolOptions(protocol: "", params: nil), responder: PairingParticipant(publicKey: ""), expiry: 0, state: nil)), result: .success(success))
relayMock.onResponse?(response)
relayMock.onPairingResponse?(response)

XCTAssert(storageMock.hasAcknowledgedPairing(on: topicB), "Settled pairing must advance to acknowledged state.")
XCTAssertFalse(storageMock.hasSequence(forTopic: topicA), "Pending pairing must be deleted.")
Expand Down