From 6d53da22c6adefac987e5f552a03ba0c43dd339a Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Tue, 14 Feb 2023 20:29:48 +0100 Subject: [PATCH] Web3Wallet expose disconnect pairing --- Sources/WalletConnectPairing/PairingClientProtocol.swift | 1 + Sources/Web3Wallet/Web3WalletClient.swift | 4 ++++ Tests/Web3WalletTests/Mocks/PairingClientMock.swift | 5 +++++ Tests/Web3WalletTests/Web3WalletTests.swift | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/Sources/WalletConnectPairing/PairingClientProtocol.swift b/Sources/WalletConnectPairing/PairingClientProtocol.swift index 680cb3090..3c4435cc6 100644 --- a/Sources/WalletConnectPairing/PairingClientProtocol.swift +++ b/Sources/WalletConnectPairing/PairingClientProtocol.swift @@ -1,3 +1,4 @@ public protocol PairingClientProtocol { func pair(uri: WalletConnectURI) async throws + func disconnect(topic: String) async throws } diff --git a/Sources/Web3Wallet/Web3WalletClient.swift b/Sources/Web3Wallet/Web3WalletClient.swift index d9397de4e..cde24b697 100644 --- a/Sources/Web3Wallet/Web3WalletClient.swift +++ b/Sources/Web3Wallet/Web3WalletClient.swift @@ -125,6 +125,10 @@ public class Web3WalletClient { public func pair(uri: WalletConnectURI) async throws { try await pairingClient.pair(uri: uri) } + + public func disconnectPairing(topic: String) async throws { + try await pairingClient.disconnect(topic: topic) + } /// For a wallet and a dApp to terminate a session /// diff --git a/Tests/Web3WalletTests/Mocks/PairingClientMock.swift b/Tests/Web3WalletTests/Mocks/PairingClientMock.swift index 6c03d2226..55aed003e 100644 --- a/Tests/Web3WalletTests/Mocks/PairingClientMock.swift +++ b/Tests/Web3WalletTests/Mocks/PairingClientMock.swift @@ -5,8 +5,13 @@ import Combine final class PairingClientMock: PairingClientProtocol { var pairCalled = false + var disconnectPairingCalled = false func pair(uri: WalletConnectUtils.WalletConnectURI) async throws { pairCalled = true } + + func disconnect(topic: String) async throws { + disconnectPairingCalled = true + } } diff --git a/Tests/Web3WalletTests/Web3WalletTests.swift b/Tests/Web3WalletTests/Web3WalletTests.swift index 8962e88a1..76a088e63 100644 --- a/Tests/Web3WalletTests/Web3WalletTests.swift +++ b/Tests/Web3WalletTests/Web3WalletTests.swift @@ -127,6 +127,11 @@ final class Web3WalletTests: XCTestCase { XCTAssertTrue(pairingClient.pairCalled) } + func testDisconnectPairingCalled() async { + try! await web3WalletClient.disconnectPairing(topic: "topic") + XCTAssertTrue(pairingClient.disconnectPairingCalled) + } + func testDisconnectCalled() async { try! await web3WalletClient.disconnect(topic: "") XCTAssertTrue(signClient.disconnectCalled)