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

#888 w3i date encoding #894

Merged
merged 3 commits into from
Jun 5, 2023
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
1 change: 1 addition & 0 deletions Example/IntegrationTests/Push/PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ final class PushTests: XCTestCase {
return
}
subscriptionTopic = pushSubscription.topic
sleep(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you leave context here of why this is required and what is being fixed?

Copy link
Contributor Author

@llbartekll llbartekll Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when dapp receives proposal response and subscribes to push subscription topic, wallet immediately calls delete() method(not waiting for dapp's subscribe response). And usually dapp can subscribe before wallet publishes pushDelete but rarely delete reaches relay before dapp is able to subscribe and pushDelete payload is never delivered to a dapp.
This won't happen in real world and is just an effect of test design and immediate function calls. Push is not natively supported for dapps at the moment. Dapp client is implemented mostly for tests.
1 second delay of pushDelete method call should eliminate futur test fails.

Task(priority: .userInitiated) { try! await walletPushClient.deleteSubscription(topic: pushSubscription.topic)}
}.store(in: &publishers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class PushMessagesDatabase {
}

func getPushMessages(topic: String) -> [PushMessageRecord] {
return store.getAll().filter{$0.topic == topic}
return store.getAll()
.filter{$0.topic == topic}
.sorted{$0.publishedAt > $1.publishedAt}
}

func deletePushMessages(topic: String) {
Expand Down
5 changes: 4 additions & 1 deletion Sources/WalletConnectUtils/Encodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ public enum DataConversionError: Error {
public extension Encodable {

// TODO: Migrate
func json() throws -> String {
func json(dateEncodingStrategy: JSONEncoder.DateEncodingStrategy? = nil) throws -> String {
let encoder = JSONEncoder()
if let dateEncodingStrategy = dateEncodingStrategy {
encoder.dateEncodingStrategy = dateEncodingStrategy
}
encoder.outputFormatting = .withoutEscapingSlashes
let data = try encoder.encode(self)
guard let string = String(data: data, encoding: .utf8) else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Web3Inbox/WebView/WebViewProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ actor WebViewProxy {

@MainActor
func respond(_ response: RPCResponse) async throws {
let body = try response.json()
let body = try response.json(dateEncodingStrategy: .millisecondsSince1970)
logger.debug("resonding to w3i with \(body)")
let script = scriptFormatter.formatScript(body: body)
webView.evaluateJavaScript(script, completionHandler: nil)
}

@MainActor
func request(_ request: RPCRequest) async throws {
let body = try request.json()
let body = try request.json(dateEncodingStrategy: .millisecondsSince1970)
logger.debug("requesting w3i with \(body)")
let script = scriptFormatter.formatScript(body: body)
webView.evaluateJavaScript(script, completionHandler: nil)
Expand Down