Skip to content

Commit

Permalink
Merge pull request #894 from WalletConnect/#888-w3i-date-encoding
Browse files Browse the repository at this point in the history
#888 w3i date encoding
  • Loading branch information
llbartekll authored Jun 5, 2023
2 parents a8b2678 + 85b72be commit 83e4b3f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
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)
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

0 comments on commit 83e4b3f

Please sign in to comment.