Skip to content

Commit

Permalink
Merge pull request #730 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.4.1
  • Loading branch information
llbartekll authored Feb 21, 2023
2 parents dd68f76 + 2146f0a commit 623f734
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Sources/JSONRPC/RPCID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public protocol IdentifierGenerator {
struct IntIdentifierGenerator: IdentifierGenerator {

func next() -> RPCID {
let timestamp = Int64(Date().timeIntervalSince1970 * 1000 * pow(10, 6))
let random = Int64.random(in: 0..<1000000)
let timestamp = Int64(Date().timeIntervalSince1970 * 1000) * 1000
let random = Int64.random(in: 0..<1000)
return RPCID(timestamp + random)
}
}
Expand All @@ -37,7 +37,7 @@ extension RPCID {

public var timestamp: Date {
guard let id = self.right else { return .distantPast }
let interval = TimeInterval(id / 1000 / 1000000)
let interval = TimeInterval(id / 1000 / 1000)
return Date(timeIntervalSince1970: interval)
}
}
4 changes: 2 additions & 2 deletions Sources/WalletConnectRelay/RPC/WalletConnectRPCID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Foundation
struct WalletConnectRPCID: IdentifierGenerator {

func next() -> RPCID {
let timestamp = Int64(Date().timeIntervalSince1970 * 1000 * pow(10, 6))
let random = Int64.random(in: 0..<1000000)
let timestamp = Int64(Date().timeIntervalSince1970 * 1000) * 1000
let random = Int64.random(in: 0..<1000)
return .right(Int64(timestamp + random))
}
}
6 changes: 3 additions & 3 deletions Sources/WalletConnectUtils/JsonRecID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Foundation
public struct JsonRpcID {

public static func generate() -> Int64 {
let timestamp = Int64(Date().timeIntervalSince1970 * 1000 * pow(10, 6))
let random = Int64.random(in: 0..<1000000)
let timestamp = Int64(Date().timeIntervalSince1970 * 1000) * 1000
let random = Int64.random(in: 0..<1000)
return timestamp + random
}

public static func timestamp(from id: Int64) -> Date {
let interval = TimeInterval(id / 1000 / 1000000)
let interval = TimeInterval(id / 1000 / 1000)
return Date(timeIntervalSince1970: interval)
}
}
2 changes: 1 addition & 1 deletion Tests/WalletConnectSignTests/WCResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class RPCIDTests: XCTestCase {
func testTimestamp() {
let request = RPCRequest(method: "method")
let response = RPCResponse(matchingRequest: request, error: JSONRPCError(code: 0, message: "message"))
let timestamp = Date(timeIntervalSince1970: TimeInterval(request.id!.right! / 1000 / 1000000))
let timestamp = Date(timeIntervalSince1970: TimeInterval(request.id!.right! / 1000 / 1000))

XCTAssertEqual(response.id!.timestamp, timestamp)
XCTAssertTrue(Calendar.current.isDateInToday(response.id!.timestamp))
Expand Down

0 comments on commit 623f734

Please sign in to comment.