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

[Notify] Notifications history #1278

Merged
merged 21 commits into from
Jan 19, 2024
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
26 changes: 7 additions & 19 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
A50D53C32ABA055700A4FD8B /* NotifyPreferencesRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50D53BE2ABA055700A4FD8B /* NotifyPreferencesRouter.swift */; };
A50D53C42ABA055700A4FD8B /* NotifyPreferencesInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50D53BF2ABA055700A4FD8B /* NotifyPreferencesInteractor.swift */; };
A50D53C52ABA055700A4FD8B /* NotifyPreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50D53C02ABA055700A4FD8B /* NotifyPreferencesView.swift */; };
A50DF19D2A25084A0036EA6C /* WalletConnectHistory in Frameworks */ = {isa = PBXBuildFile; productRef = A50DF19C2A25084A0036EA6C /* WalletConnectHistory */; };
A50F3946288005B200064555 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50F3945288005B200064555 /* Types.swift */; };
A51606F82A2F47BD00CACB92 /* DefaultBIP44Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51606F72A2F47BD00CACB92 /* DefaultBIP44Provider.swift */; };
A51606F92A2F47BD00CACB92 /* DefaultBIP44Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51606F72A2F47BD00CACB92 /* DefaultBIP44Provider.swift */; };
Expand All @@ -79,7 +78,6 @@
A518B31428E33A6500A2CE93 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A518B31328E33A6500A2CE93 /* InputConfig.swift */; };
A51AC0D928E436A3001BACF9 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51AC0D828E436A3001BACF9 /* InputConfig.swift */; };
A51AC0DF28E4379F001BACF9 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51AC0DE28E4379F001BACF9 /* InputConfig.swift */; };
A5321C2B2A250367006CADC3 /* HistoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5321C2A2A250367006CADC3 /* HistoryTests.swift */; };
A5417BBE299BFC3E00B469F3 /* ImportAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5417BBD299BFC3E00B469F3 /* ImportAccount.swift */; };
A541959E2934BFEF0035AD19 /* CacaoSignerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A541959A2934BFEF0035AD19 /* CacaoSignerTests.swift */; };
A541959F2934BFEF0035AD19 /* SignerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A541959B2934BFEF0035AD19 /* SignerTests.swift */; };
Expand Down Expand Up @@ -177,6 +175,7 @@
A5B6C0F32A6EAB1700927332 /* WalletConnectNotify in Frameworks */ = {isa = PBXBuildFile; productRef = A5B6C0F22A6EAB1700927332 /* WalletConnectNotify */; };
A5B6C0F52A6EAB2800927332 /* WalletConnectNotify in Frameworks */ = {isa = PBXBuildFile; productRef = A5B6C0F42A6EAB2800927332 /* WalletConnectNotify */; };
A5B6C0F72A6EAB3200927332 /* WalletConnectNotify in Frameworks */ = {isa = PBXBuildFile; productRef = A5B6C0F62A6EAB3200927332 /* WalletConnectNotify */; };
A5B814FA2B5AAA2F00AECCFD /* WalletConnectIdentity in Frameworks */ = {isa = PBXBuildFile; productRef = A5B814F92B5AAA2F00AECCFD /* WalletConnectIdentity */; };
A5BB7FA328B6A50400707FC6 /* WalletConnectAuth in Frameworks */ = {isa = PBXBuildFile; productRef = A5BB7FA228B6A50400707FC6 /* WalletConnectAuth */; };
A5BB7FAD28B6AA7D00707FC6 /* QRCodeGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5BB7FAC28B6AA7D00707FC6 /* QRCodeGenerator.swift */; };
A5C2020B287D9DEE007E3188 /* WelcomeModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5C20206287D9DEE007E3188 /* WelcomeModule.swift */; };
Expand Down Expand Up @@ -475,7 +474,6 @@
A518B31328E33A6500A2CE93 /* InputConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A51AC0D828E436A3001BACF9 /* InputConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A51AC0DE28E4379F001BACF9 /* InputConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A5321C2A2A250367006CADC3 /* HistoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryTests.swift; sourceTree = "<group>"; };
A5417BBD299BFC3E00B469F3 /* ImportAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportAccount.swift; sourceTree = "<group>"; };
A541959A2934BFEF0035AD19 /* CacaoSignerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CacaoSignerTests.swift; sourceTree = "<group>"; };
A541959B2934BFEF0035AD19 /* SignerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -766,8 +764,8 @@
files = (
A5E03DFF2864662500888481 /* WalletConnect in Frameworks */,
A561C80529DFCD4500DF540D /* WalletConnectSync in Frameworks */,
A5B814FA2B5AAA2F00AECCFD /* WalletConnectIdentity in Frameworks */,
A5E03DF52864651200888481 /* Starscream in Frameworks */,
A50DF19D2A25084A0036EA6C /* WalletConnectHistory in Frameworks */,
A5C8BE85292FE20B006CC85C /* Web3 in Frameworks */,
84DDB4ED28ABB663003D66ED /* WalletConnectAuth in Frameworks */,
C5DD5BE1294E09E3008FD3A4 /* Web3Wallet in Frameworks */,
Expand Down Expand Up @@ -1047,14 +1045,6 @@
path = Settings;
sourceTree = "<group>";
};
A5321C292A25035A006CADC3 /* History */ = {
isa = PBXGroup;
children = (
A5321C2A2A250367006CADC3 /* HistoryTests.swift */,
);
path = History;
sourceTree = "<group>";
};
A54195992934BFDD0035AD19 /* Signer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1481,7 +1471,6 @@
isa = PBXGroup;
children = (
847F07FE2A25DBC700B2A5A4 /* XPlatform */,
A5321C292A25035A006CADC3 /* History */,
A561C80129DFCCD300DF540D /* Sync */,
849D7A91292E2115006A2BD4 /* Push */,
84CEC64728D8A98900D081A8 /* Pairing */,
Expand Down Expand Up @@ -2107,8 +2096,8 @@
C5DD5BE0294E09E3008FD3A4 /* Web3Wallet */,
A561C80429DFCD4500DF540D /* WalletConnectSync */,
A573C53A29EC365800E3CBFD /* HDWalletKit */,
A50DF19C2A25084A0036EA6C /* WalletConnectHistory */,
A5B6C0F22A6EAB1700927332 /* WalletConnectNotify */,
A5B814F92B5AAA2F00AECCFD /* WalletConnectIdentity */,
);
productName = IntegrationTests;
productReference = A5E03DED286464DB00888481 /* IntegrationTests.xctest */;
Expand Down Expand Up @@ -2488,7 +2477,6 @@
84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */,
7694A5262874296A0001257E /* RegistryTests.swift in Sources */,
A541959F2934BFEF0035AD19 /* SignerTests.swift in Sources */,
A5321C2B2A250367006CADC3 /* HistoryTests.swift in Sources */,
A58A1ECC29BF458600A82A20 /* ENSResolverTests.swift in Sources */,
A5E03DFA286465C700888481 /* SignClientTests.swift in Sources */,
84A6E3C32A386BBC008A0571 /* Publisher.swift in Sources */,
Expand Down Expand Up @@ -3444,10 +3432,6 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectAuth;
};
A50DF19C2A25084A0036EA6C /* WalletConnectHistory */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectHistory;
};
A54195A42934E83F0035AD19 /* Web3 */ = {
isa = XCSwiftPackageProductDependency;
package = A5AE354528A1A2AC0059AE8A /* XCRemoteSwiftPackageReference "Web3" */;
Expand Down Expand Up @@ -3530,6 +3514,10 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectNotify;
};
A5B814F92B5AAA2F00AECCFD /* WalletConnectIdentity */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectIdentity;
};
A5BB7FA228B6A50400707FC6 /* WalletConnectAuth */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectAuth;
Expand Down
11 changes: 1 addition & 10 deletions Example/IntegrationTests/Chat/ChatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import XCTest
import WalletConnectUtils
@testable import WalletConnectKMS
@testable import WalletConnectSync
@testable import WalletConnectHistory
import WalletConnectRelay
import Combine
import Web3
Expand Down Expand Up @@ -71,18 +70,10 @@ final class ChatTests: XCTestCase {
keychain: keychain
)

let historyClient = HistoryClientFactory.create(
historyUrl: "https://history.walletconnect.com",
relayUrl: "wss://relay.walletconnect.com",
keyValueStorage: keyValueStorage,
keychain: keychain,
logger: logger
)

let clientId = try! networkingInteractor.getClientId()
logger.debug("My client id is: \(clientId)")

return ChatClientFactory.create(keyserverURL: keyserverURL, relayClient: relayClient, networkingInteractor: networkingInteractor, keychain: keychain, logger: logger, storage: keyValueStorage, syncClient: syncClient, historyClient: historyClient)
return ChatClientFactory.create(keyserverURL: keyserverURL, relayClient: relayClient, networkingInteractor: networkingInteractor, keychain: keychain, logger: logger, storage: keyValueStorage, syncClient: syncClient)
}

func testInvite() async throws {
Expand Down
81 changes: 0 additions & 81 deletions Example/IntegrationTests/History/HistoryTests.swift

This file was deleted.

1 change: 0 additions & 1 deletion Example/IntegrationTests/Pairing/PairingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import WalletConnectPush
@testable import Auth
@testable import WalletConnectPairing
@testable import WalletConnectSync
@testable import WalletConnectHistory

final class PairingTests: XCTestCase {

Expand Down
24 changes: 22 additions & 2 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ final class NotifyTests: XCTestCase {
}
}

/*
func testWalletCreatesAndUpdatesSubscription() async throws {
let created = expectation(description: "Subscription created")

Expand Down Expand Up @@ -202,7 +201,6 @@ final class NotifyTests: XCTestCase {

try await walletNotifyClientA.deleteSubscription(topic: subscription.topic)
}
*/

func testNotifyServerSubscribeAndNotifies() async throws {
let subscribeExpectation = expectation(description: "creates notify subscription")
Expand Down Expand Up @@ -255,6 +253,28 @@ final class NotifyTests: XCTestCase {
}
}

func testFetchHistory() async throws {
let subscribeExpectation = expectation(description: "fetch notify subscription")
let account = Account("eip155:1:0x622b17376F76d72C43527a917f59273247A917b4")!

var subscription: NotifySubscription!
walletNotifyClientA.subscriptionsPublisher
.sink { subscriptions in
subscription = subscriptions.first
subscribeExpectation.fulfill()
}.store(in: &publishers)

try await walletNotifyClientA.register(account: account, domain: gmDappDomain) { message in
let privateKey = Data(hex: "c3ff8a0ae33ac5d58e515055c5870fa2f220d070997bd6fd77a5f2c148528ff0")
let signer = MessageSignerFactory(signerFactory: DefaultSignerFactory()).create(projectId: InputConfig.projectId)
return try! signer.sign(message: message, privateKey: privateKey, type: .eip191)
}

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

try await walletNotifyClientA.fetchHistory(subscription: subscription)
XCTAssertEqual(walletNotifyClientA.getMessageHistory(topic: subscription.topic).count, 41)
}
}


Expand Down
3 changes: 2 additions & 1 deletion Example/IntegrationTests/Stubs/PushMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension NotifyMessage {
body: "body",
icon: "https://images.unsplash.com/photo-1581224463294-908316338239?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=250&q=80",
url: "https://web3inbox.com",
type: type)
type: type,
sentAt: Date())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ final class SubscriptionInteractor {
try await Notify.instance.deleteSubscription(topic: subscription.topic)
}
}

func fetchHistory() {
Task(priority: .high) {
try await Notify.instance.fetchHistory(subscription: subscription)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ extension SubscriptionPresenter: SceneViewModel {
private extension SubscriptionPresenter {

func setupInitialState() {
interactor.fetchHistory()

pushMessages = interactor.getPushMessages()

interactor.messagesPublisher
Expand Down
14 changes: 5 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ let package = Package(
.library(
name: "WalletConnectVerify",
targets: ["WalletConnectVerify"]),
.library(
name: "WalletConnectHistory",
targets: ["WalletConnectHistory"]),
.library(
name: "WalletConnectModal",
targets: ["WalletConnectModal"]),

.library(
name: "WalletConnectIdentity",
targets: ["WalletConnectIdentity"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
Expand All @@ -62,7 +61,7 @@ let package = Package(
path: "Sources/WalletConnectSign"),
.target(
name: "WalletConnectChat",
dependencies: ["WalletConnectIdentity", "WalletConnectSync", "WalletConnectHistory"],
dependencies: ["WalletConnectIdentity", "WalletConnectSync"],
path: "Sources/Chat"),
.target(
name: "Auth",
Expand All @@ -74,7 +73,7 @@ let package = Package(
path: "Sources/Web3Wallet"),
.target(
name: "WalletConnectNotify",
dependencies: ["WalletConnectPairing", "WalletConnectPush", "WalletConnectIdentity", "WalletConnectSigner", "Database"],
dependencies: ["WalletConnectIdentity", "WalletConnectPairing", "WalletConnectPush", "WalletConnectSigner", "Database"],
path: "Sources/WalletConnectNotify"),
.target(
name: "WalletConnectPush",
Expand All @@ -92,9 +91,6 @@ let package = Package(
.target(
name: "WalletConnectPairing",
dependencies: ["WalletConnectNetworking"]),
.target(
name: "WalletConnectHistory",
dependencies: ["HTTPClient", "WalletConnectRelay"]),
.target(
name: "WalletConnectSigner",
dependencies: ["WalletConnectNetworking"]),
Expand Down
3 changes: 1 addition & 2 deletions Sources/Chat/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class Chat {
keyserverUrl: keyserverUrl,
relayClient: Relay.instance,
networkingInteractor: Networking.interactor,
syncClient: Sync.instance,
historyClient: History.instance
syncClient: Sync.instance
)
}()

Expand Down
11 changes: 4 additions & 7 deletions Sources/Chat/ChatClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct ChatClientFactory {

static func create(keyserverUrl: String, relayClient: RelayClient, networkingInteractor: NetworkingInteractor, syncClient: SyncClient, historyClient: HistoryClient) -> ChatClient {
static func create(keyserverUrl: String, relayClient: RelayClient, networkingInteractor: NetworkingInteractor, syncClient: SyncClient) -> ChatClient {
fatalError("fix access group")
let keychain = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk", accessGroup: "")
let keyserverURL = URL(string: keyserverUrl)!
Expand All @@ -13,8 +13,7 @@ public struct ChatClientFactory {
keychain: keychain,
logger: ConsoleLogger(loggingLevel: .debug),
storage: UserDefaults.standard,
syncClient: syncClient,
historyClient: historyClient
syncClient: syncClient
)
}

Expand All @@ -25,12 +24,10 @@ public struct ChatClientFactory {
keychain: KeychainStorageProtocol,
logger: ConsoleLogging,
storage: KeyValueStorage,
syncClient: SyncClient,
historyClient: HistoryClient
syncClient: SyncClient
) -> ChatClient {
let kms = KeyManagementService(keychain: keychain)
let serializer = Serializer(kms: kms, logger: logger)
let historyService = HistoryService(historyClient: historyClient, seiralizer: serializer)
let historyService = HistoryService()
let messageStore = KeyedDatabase<Message>(storage: storage, identifier: ChatStorageIdentifiers.messages.rawValue)
let receivedInviteStore = KeyedDatabase<ReceivedInvite>(storage: storage, identifier: ChatStorageIdentifiers.receivedInvites.rawValue)
let threadStore: SyncStore<Thread> = SyncStoreFactory.create(name: ChatStorageIdentifiers.thread.rawValue, syncClient: syncClient, storage: storage)
Expand Down
1 change: 0 additions & 1 deletion Sources/Chat/ChatImports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
@_exported import WalletConnectSigner
@_exported import WalletConnectIdentity
@_exported import WalletConnectSync
@_exported import WalletConnectHistory
#endif
Loading
Loading