Skip to content

Commit

Permalink
Merge pull request #327 from WalletConnect/bugfix/message-callback-on…
Browse files Browse the repository at this point in the history
…-send

[Chat] Message callback on send
  • Loading branch information
llbartekll authored Jul 12, 2022
2 parents 10e964f + 6dee074 commit df4711a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Chat/RegistryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import WalletConnectUtils
final class RegistryTests: XCTestCase {

func testRegistry() async throws {
let client = HTTPClient(host: "159.65.123.131")
let client = HTTPClient(host: "keys.walletconnect.com")
let registry = KeyserverRegistryProvider(client: client)
let account = Account("eip155:1:" + Data.randomBytes(count: 16).toHexString())!
let pubKey = SigningPrivateKey().publicKey.hexRepresentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ChatFactory {
let relayHost = "relay.walletconnect.com"
let projectId = "8ba9ee138960775e5231b70cc5ef1c3a"
let keychain = KeychainStorage(serviceIdentifier: "com.walletconnect.showcase")
let client = HTTPClient(host: "159.65.123.131")
let client = HTTPClient(host: "keys.walletconnect.com")
let registry = KeyserverRegistryProvider(client: client)
let relayClient = RelayClient(relayHost: relayHost, projectId: projectId, keychainStorage: keychain, socketFactory: SocketFactory())
return ChatClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MessagingService {
try await networkingInteractor.request(request, topic: topic, envelopeType: .type0)
Task(priority: .background) {
await messagesStore.add(message)
onMessage?(message)
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/Chat/Services/RegisterService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ struct RegisterService: HTTPService {
.post
}

var scheme: String {
return "https"
}

var body: Data? {
try? JSONEncoder().encode(userAccount)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Chat/Services/ResolveService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct ResolveService: HTTPService {
.get
}

var scheme: String {
return "https"
}

var body: Data? {
nil
}
Expand Down
16 changes: 5 additions & 11 deletions Sources/WalletConnectRelay/HTTP/HTTPService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public protocol HTTPService {
var method: HTTPMethod { get }
var body: Data? { get }
var queryParameters: [String: String]? { get }
var port: Int? { get }
func resolve(for host: String) -> URLRequest?
}

Expand All @@ -21,25 +20,20 @@ public extension HTTPService {
"http"
}

var port: Int? {
8080
}

func resolve(for host: String) -> URLRequest? {
var components = URLComponents()
components.scheme = self.scheme
components.scheme = scheme
components.host = host
components.port = self.port
components.path = self.path
if let query = self.queryParameters {
components.path = path
if let query = queryParameters {
components.queryItems = query.map { URLQueryItem(name: $0.key, value: $0.value) }
}
guard let url = components.url else {
return nil
}
var request = URLRequest(url: url)
request.httpMethod = self.method.rawValue
request.httpBody = self.body
request.httpMethod = method.rawValue
request.httpBody = body
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
return request
}
Expand Down

0 comments on commit df4711a

Please sign in to comment.