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 requests-life-cycle
  • Loading branch information
llbartekll committed Aug 27, 2024
2 parents 086116a + 0bc1bae commit 0cc1ec8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/WalletConnectRelay/PackageConfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "1.19.6"}
{"version": "1.20.0"}
12 changes: 12 additions & 0 deletions Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ final class ApproveEngine {

do {
let session: WCSession = try await settleRequestTask
eventsClient.saveTraceEvent(SessionApproveExecutionTraceEvents.sessionSettleSuccess)
logger.debug("Session settle request has been successfully processed")

do {
_ = try await proposeResponseTask
eventsClient.saveTraceEvent(SessionApproveExecutionTraceEvents.responseApproveSent)
} catch {
eventsClient.saveTraceEvent(ApproveSessionTraceErrorEvents.sessionSettleFailure)
throw error
}

sessionStore.setSession(session)

Task {
removePairing(pairingTopic: pairingTopic)
}
Expand Down
16 changes: 14 additions & 2 deletions Sources/WalletConnectVerify/VerifyContextFactory.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@

import Foundation

class VerifyContextFactory {

private func ensureUrlHasScheme(_ urlString: String) -> String {
if urlString.hasPrefix("http://") || urlString.hasPrefix("https://") {
return urlString
} else {
return "https://" + urlString
}
}

public func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool?) -> VerifyContext {

guard isScam != true else {
Expand All @@ -19,7 +27,11 @@ class VerifyContextFactory {
)
}

if let origin, let originUrl = URL(string: origin), let domainUrl = URL(string: domain) {
// Ensure both origin and domain have a scheme
let originWithScheme = origin.map { ensureUrlHasScheme($0) }
let domainWithScheme = ensureUrlHasScheme(domain)

if let originWithScheme, let originUrl = URL(string: originWithScheme), let domainUrl = URL(string: domainWithScheme) {
return VerifyContext(
origin: origin,
validation: (originUrl.host == domainUrl.host) ? .valid : .invalid
Expand Down
10 changes: 10 additions & 0 deletions Tests/VerifyTests/VerifyContextFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class VerifyContextFactoryTests: XCTestCase {
XCTAssertEqual(contextWithFalseVerification.validation, .scam)
}

func testValidOriginAndDomainWithoutScheme() {
let context = factory.createVerifyContext(origin: "https://dev.lab.web3modal.com", domain: "dev.lab.web3modal.com", isScam: false, isVerified: nil)
XCTAssertEqual(context.validation, .valid)
}

func testInvalidOriginAndDomainWithoutScheme() {
let context = factory.createVerifyContext(origin: "https://dev.lab.web3modal.com", domain: "different.com", isScam: false, isVerified: nil)
XCTAssertEqual(context.validation, .invalid)
}

// tests for createVerifyContextForLinkMode

func testValidUniversalLink() {
Expand Down

0 comments on commit 0cc1ec8

Please sign in to comment.