Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:WalletConnect/WalletConnectSwift…
Browse files Browse the repository at this point in the history
…V2 into push-client-encrypted-PNs

# Conflicts:
#	Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Loading branch information
llbartekll committed Dec 1, 2023
2 parents 78be65a + aee8c77 commit 3218408
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Example/WalletApp/ApplicationLayer/ProfilingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import Mixpanel
import WalletConnectNetworking
import Combine
import Web3Wallet
import WalletConnectNotify

final class ProfilingService {
Expand Down Expand Up @@ -34,6 +35,8 @@ final class ProfilingService {
handleLogs(from: Networking.instance.logsPublisher)
handleLogs(from: Notify.instance.logsPublisher)
handleLogs(from: Push.instance.logsPublisher)
handleLogs(from: Web3Wallet.instance.logsPublisher)

}

private func handleLogs(from publisher: AnyPublisher<Log, Never>) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/WalletConnectPairing/PairingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class PairingClient: PairingRegisterer, PairingInteracting, PairingClient

private let cleanupService: PairingCleanupService

public var logsPublisher: AnyPublisher<Log, Never> {
return logger.logsPublisher
}

init(
pairingStorage: WCPairingStorage,
appPairService: AppPairService,
Expand Down
3 changes: 3 additions & 0 deletions Sources/WalletConnectPairing/PairingClientProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Combine

public protocol PairingClientProtocol {
var logsPublisher: AnyPublisher<Log, Never> {get}
func pair(uri: WalletConnectURI) async throws
func disconnect(topic: String) async throws
func getPairings() -> [Pairing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ actor WalletPairService {
let kms: KeyManagementServiceProtocol
private let pairingStorage: WCPairingStorage
private let history: RPCHistory
private let logger: ConsoleLogging

init(
networkingInteractor: NetworkInteracting,
kms: KeyManagementServiceProtocol,
pairingStorage: WCPairingStorage,
history: RPCHistory
history: RPCHistory,
logger: ConsoleLogging
) {
self.networkingInteractor = networkingInteractor
self.kms = kms
self.pairingStorage = pairingStorage
self.history = history
self.logger = logger
}

func pair(_ uri: WalletConnectURI) async throws {
logger.debug("Pairing with uri: \(uri)")
guard try !pairingHasPendingRequest(for: uri.topic) else {
logger.debug("Pairing with topic (\(uri.topic)) has pending request")
return
}

Expand All @@ -35,6 +40,7 @@ actor WalletPairService {

let networkConnectionStatus = await resolveNetworkConnectionStatus()
guard networkConnectionStatus == .connected else {
logger.debug("Pairing failed - Network is not connected")
throw Errors.networkNotConnected
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ final class ApproveEngine {
}

func approveProposal(proposerPubKey: String, validating sessionNamespaces: [String: SessionNamespace], sessionProperties: [String: String]? = nil) async throws {
logger.debug("Approving session proposal")
guard let payload = try proposalPayloadsStore.get(key: proposerPubKey) else {
throw Errors.wrongRequestParams
}
Expand Down Expand Up @@ -112,6 +113,8 @@ final class ApproveEngine {

_ = try await [proposeResponse, settleRequest]

logger.debug("Session proposal response and settle request have been sent")

pairingRegisterer.activate(
pairingTopic: payload.topic,
peerMetadata: payload.request.proposer.metadata
Expand Down
4 changes: 4 additions & 0 deletions Sources/WalletConnectSign/Sign/SignClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public final class SignClient: SignClientProtocol {
sessionsPublisherSubject.eraseToAnyPublisher()
}

public var logsPublisher: AnyPublisher<Log, Never> {
return logger.logsPublisher
}

/// An object that loggs SDK's errors and info messages
public let logger: ConsoleLogging

Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectSign/Sign/SignClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct SignClientFactory {
networkingClient: NetworkingInteractor,
groupIdentifier: String
) -> SignClient {
let logger = ConsoleLogger(loggingLevel: .debug)
let logger = ConsoleLogger(prefix: "📝", loggingLevel: .debug)

guard let keyValueStorage = UserDefaults(suiteName: groupIdentifier) else {
fatalError("Could not instantiate UserDefaults for a group identifier \(groupIdentifier)")
Expand Down
3 changes: 2 additions & 1 deletion Sources/WalletConnectSign/Sign/SignClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public protocol SignClientProtocol {
var sessionResponsePublisher: AnyPublisher<Response, Never> { get }
var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> { get }
var sessionEventPublisher: AnyPublisher<(event: Session.Event, sessionTopic: String, chainId: Blockchain?), Never> { get }

var logsPublisher: AnyPublisher<Log, Never> {get}

func connect(requiredNamespaces: [String: ProposalNamespace], optionalNamespaces: [String: ProposalNamespace]?, sessionProperties: [String: String]?, topic: String) async throws
func request(params: Request) async throws
func approve(proposalId: String, namespaces: [String: SessionNamespace], sessionProperties: [String: String]?) async throws
Expand Down
6 changes: 6 additions & 0 deletions Sources/Web3Wallet/Web3WalletClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class Web3WalletClient {
signClient.sessionResponsePublisher.eraseToAnyPublisher()
}

public var logsPublisher: AnyPublisher<Log, Never> {
return signClient.logsPublisher
.merge(with: pairingClient.logsPublisher)
.eraseToAnyPublisher()
}

// MARK: - Private Properties
private let authClient: AuthClientProtocol
private let signClient: SignClientProtocol
Expand Down

0 comments on commit 3218408

Please sign in to comment.