diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index fe1125fa9..5644fcd89 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -273,7 +273,7 @@ final class NotifyTests: XCTestCase { await fulfillment(of: [subscribeExpectation], timeout: InputConfig.defaultTimeout) try await walletNotifyClientA.fetchHistory(subscription: subscription) - XCTAssertEqual(walletNotifyClientA.getMessageHistory(topic: subscription.topic).count, 41) + XCTAssertTrue(walletNotifyClientA.getMessageHistory(topic: subscription.topic).count > 40) } } diff --git a/Sources/WalletConnectNotify/Types/DataStructures/NotifyMessage.swift b/Sources/WalletConnectNotify/Types/DataStructures/NotifyMessage.swift index 6c88dfa7a..f34549757 100644 --- a/Sources/WalletConnectNotify/Types/DataStructures/NotifyMessage.swift +++ b/Sources/WalletConnectNotify/Types/DataStructures/NotifyMessage.swift @@ -13,13 +13,24 @@ public struct NotifyMessage: Codable, Equatable { return Date(milliseconds: sent_at) } - public init(id: String, title: String, body: String, icon: String, url: String, type: String, sentAt: Date) { + public init(id: String, title: String, body: String, icon: String?, url: String?, type: String, sentAt: Date) { self.id = id self.title = title self.body = body - self.icon = icon - self.url = url + self.icon = icon ?? "" + self.url = url ?? "" self.type = type self.sent_at = UInt64(sentAt.millisecondsSince1970) } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decode(String.self, forKey: .id) + self.title = try container.decode(String.self, forKey: .title) + self.body = try container.decode(String.self, forKey: .body) + self.icon = try container.decodeIfPresent(String.self, forKey: .icon) ?? "" + self.url = try container.decodeIfPresent(String.self, forKey: .url) ?? "" + self.type = try container.decode(String.self, forKey: .type) + self.sent_at = try container.decode(UInt64.self, forKey: .sent_at) + } }