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

[Chat] Message callback on send #327

Merged
merged 2 commits into from
Jul 12, 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 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