Skip to content

Commit

Permalink
History message mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Jun 13, 2023
1 parent e0f9618 commit 554661a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Example/IntegrationTests/History/HistoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ final class HistoryTests: XCTestCase {

await fulfillment(of: [exp], timeout: InputConfig.defaultTimeout)

sleep(5) // History server has a queue

let messages = try await historyClient.getMessages(
payload: GetMessagesPayload(
topic: topic,
Expand Down
12 changes: 6 additions & 6 deletions Example/Showcase/Classes/DomainLayer/Chat/ImportAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ enum ImportAccount: Codable {
var account: Account {
switch self {
case .swift:
return Account("eip155:1:0x1AAe9864337E821f2F86b5D27468C59AA333C877")!
return Account("eip155:1:0x5F847B18b4a2Dd0F428796E89CaEe71480a2a98e")!
case .kotlin:
return Account("eip155:1:0x4c0fb06CD854ab7D5909E830a5f49D184EB41BF5")!
return Account("eip155:1:0xC313B6F74FcB89147e751220184F0C56D37a210e")!
case .js:
return Account("eip155:1:0x7ABa5B1F436e42f6d4A579FB3Ad6D204F6A91863")!
return Account("eip155:1:0x265F4Eb49ab95ED142C4995EF8B5FC9e57538836")!
case .custom(let privateKey):
let address = try! EthereumPrivateKey(hexPrivateKey: "0x" + privateKey, ctx: nil).address.hex(eip55: true)
return Account("eip155:1:\(address)")!
Expand All @@ -79,11 +79,11 @@ enum ImportAccount: Codable {
var privateKey: String {
switch self {
case .swift:
return "4dc0055d1831f7df8d855fc8cd9118f4a85ddc05395104c4cb0831a6752621a8"
return "85f52ec43821c1e2e24a248ee464e8d3f883e460acb0506e1eb6b520eb67ae15"
case .kotlin:
return "ebe738a76b9a3b7457c3d5eca8d3d9ea6909bc563e05b6e0c5c35448f93100a0"
return "646a0ebac6bd34ba5f498b809148b2aca3793374cafe9dc417cf63bea80450bf"
case .js:
return "de15cb11963e9bde0a5cce06a5ee2bda1cf3a67be6fbcd7a4fc8c0e4c4db0298"
return "8df6b8206eebcd3da89b750f1cf9bba887630c3c5eade83f44c06fa4f7cc5f65"
case .custom(let privateKey):
return privateKey
case .web3Modal:
Expand Down
22 changes: 21 additions & 1 deletion Sources/WalletConnectHistory/Types/GetMessagesResponse.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import Foundation

public struct GetMessagesResponse: Codable {
public struct GetMessagesResponse: Decodable {
public struct Message: Codable {
public let message: String
}
public let topic: String
public let direction: GetMessagesPayload.Direction
public let nextId: Int64?
public let messages: [String]

enum CodingKeys: String, CodingKey {
case topic
case direction
case nextId
case messages
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.topic = try container.decode(String.self, forKey: .topic)
self.direction = try container.decode(GetMessagesPayload.Direction.self, forKey: .direction)
self.nextId = try container.decodeIfPresent(Int64.self, forKey: .nextId)

let messages = try container.decode([Message].self, forKey: .messages)
self.messages = messages.map { $0.message }
}
}

0 comments on commit 554661a

Please sign in to comment.