Skip to content

Commit

Permalink
Merge pull request #558 from WalletConnect/develop
Browse files Browse the repository at this point in the history
[Chat] Chat alpha
  • Loading branch information
llbartekll authored Oct 28, 2022
2 parents 528410e + f733a44 commit 3013d46
Show file tree
Hide file tree
Showing 32 changed files with 105 additions and 95 deletions.
7 changes: 6 additions & 1 deletion .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ runs:
-scheme WalletConnect \
-clonedSourcePackagesDirPath SourcePackagesCache \
-destination 'platform=iOS Simulator,name=iPhone 13' \
-derivedDataPath DerivedDataCache \
test"

# Integration tests
Expand All @@ -37,7 +38,8 @@ runs:
-project Example/ExampleApp.xcodeproj \
-scheme IntegrationTests \
-clonedSourcePackagesDirPath SourcePackagesCache \
-destination 'platform=iOS Simulator,name=iPhone 13' \
-destination 'platform=iOS Simulator,name=iPhone 13' \
-derivedDataPath DerivedDataCache \
RELAY_HOST='$RELAY_ENDPOINT' \
PROJECT_ID='$PROJECT_ID' \
test"
Expand All @@ -50,6 +52,7 @@ runs:
-project Example/ExampleApp.xcodeproj \
-scheme Wallet \
-clonedSourcePackagesDirPath SourcePackagesCache \
-derivedDataPath DerivedDataCache \
-sdk iphonesimulator"

# DApp build
Expand All @@ -60,6 +63,7 @@ runs:
-project Example/ExampleApp.xcodeproj \
-scheme DApp \
-clonedSourcePackagesDirPath SourcePackagesCache \
-derivedDataPath DerivedDataCache \
-sdk iphonesimulator"

# UI tests
Expand All @@ -69,6 +73,7 @@ runs:
run: "xcodebuild \
-project Example/ExampleApp.xcodeproj \
-scheme UITests \
-derivedDataPath DerivedDataCache \
-clonedSourcePackagesDirPath SourcePackagesCache \
-destination 'platform=iOS Simulator,name=iPhone 13' test"
continue-on-error: true
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
path: |
.build
SourcePackagesCache
DerivedDataCache
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
Expand Down
4 changes: 0 additions & 4 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
A5629AE42876E6D200094373 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE32876E6D200094373 /* ThreadViewModel.swift */; };
A5629AE828772A0100094373 /* InviteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE728772A0100094373 /* InviteViewModel.swift */; };
A5629AEA2877F2D600094373 /* WalletConnectChat in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AE92877F2D600094373 /* WalletConnectChat */; };
A5629AED2877F6A600094373 /* ChatFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AEC2877F6A600094373 /* ChatFactory.swift */; };
A5629AF02877F73000094373 /* SocketFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AEF2877F73000094373 /* SocketFactory.swift */; };
A5629AF22877F75100094373 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AF12877F75100094373 /* Starscream */; };
A578FA322873036400AA7720 /* InputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A578FA312873036400AA7720 /* InputView.swift */; };
Expand Down Expand Up @@ -277,7 +276,6 @@
A5629ADD2876CC6E00094373 /* InviteListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteListView.swift; sourceTree = "<group>"; };
A5629AE32876E6D200094373 /* ThreadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadViewModel.swift; sourceTree = "<group>"; };
A5629AE728772A0100094373 /* InviteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteViewModel.swift; sourceTree = "<group>"; };
A5629AEC2877F6A600094373 /* ChatFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatFactory.swift; sourceTree = "<group>"; };
A5629AEF2877F73000094373 /* SocketFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketFactory.swift; sourceTree = "<group>"; };
A578FA312873036400AA7720 /* InputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputView.swift; sourceTree = "<group>"; };
A578FA34287304A300AA7720 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -717,7 +715,6 @@
isa = PBXGroup;
children = (
A5629AA82876A23100094373 /* ChatService.swift */,
A5629AEC2877F6A600094373 /* ChatFactory.swift */,
A5C20225287EB099007E3188 /* AccountNameResolver.swift */,
A5C2022C287EC3F0007E3188 /* RegisterService.swift */,
);
Expand Down Expand Up @@ -1452,7 +1449,6 @@
A59EBEFA28B54A2A003EDAAF /* AuthRequestRouter.swift in Sources */,
A5629AF02877F73000094373 /* SocketFactory.swift in Sources */,
A55CAAB228B92AFF00844382 /* ScanRouter.swift in Sources */,
A5629AED2877F6A600094373 /* ChatFactory.swift in Sources */,
A5C20221287EA5B8007E3188 /* TextFieldView.swift in Sources */,
A5C2022B287EB89A007E3188 /* WelcomeInteractor.swift in Sources */,
A5C2020C287D9DEE007E3188 /* WelcomePresenter.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"repositoryURL": "https://github.com/Boilertalk/secp256k1.swift.git",
"state": {
"branch": null,
"revision": "45e458ec3be46cf0a6eb68bc947f797852dc65d8",
"version": "0.1.6"
"revision": "cd187c632fb812fd93711a9f7e644adb7e5f97f0",
"version": "0.1.7"
}
},
{
Expand Down
15 changes: 7 additions & 8 deletions Example/IntegrationTests/Chat/ChatTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import XCTest
@testable import Chat
@testable import WalletConnectChat
import WalletConnectUtils
@testable import WalletConnectKMS
import WalletConnectRelay
Expand Down Expand Up @@ -29,8 +29,8 @@ final class ChatTests: XCTestCase {
let inviteExpectation = expectation(description: "invitation expectation")
let inviteeAccount = Account(chainIdentifier: "eip155:1", address: "0x3627523167367216556273151")!
let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")!
let pubKey = try! await invitee.register(account: inviteeAccount)
try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "", account: inviterAccount)
try! await invitee.register(account: inviteeAccount)
try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "", account: inviterAccount)
invitee.invitePublisher.sink { _ in
inviteExpectation.fulfill()
}.store(in: &publishers)
Expand All @@ -44,9 +44,8 @@ final class ChatTests: XCTestCase {
let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")!

Task(priority: .high) {
let pubKey = try! await invitee.register(account: inviteeAccount)

try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount)
try! await invitee.register(account: inviteeAccount)
try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount)
}

invitee.invitePublisher.sink { [unowned self] invite in
Expand All @@ -72,8 +71,8 @@ final class ChatTests: XCTestCase {
let inviterAccount = Account(chainIdentifier: "eip155:1", address: "0x36275231673672234423f")!

Task(priority: .high) {
let pubKey = try! await invitee.register(account: inviteeAccount)
try! await inviter.invite(publicKey: pubKey, peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount)
try! await invitee.register(account: inviteeAccount)
try! await inviter.invite(peerAccount: inviteeAccount, openingMessage: "opening message", account: inviterAccount)
}

invitee.invitePublisher.sink { [unowned self] invite in
Expand Down
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Chat/RegistryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest
import WalletConnectNetworking
import WalletConnectKMS
import WalletConnectUtils
@testable import Chat
@testable import WalletConnectChat

final class RegistryTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Stubs/InputConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct InputConfig {
}

static var defaultTimeout: TimeInterval {
return 30
return 45
}

private static func config(for key: String) -> String? {
Expand Down
4 changes: 2 additions & 2 deletions Example/Showcase/Classes/ApplicationLayer/Application.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation
import Chat
import WalletConnectChat

final class Application {

lazy var chatService: ChatService = {
return ChatService(client: ChatFactory.create())
return ChatService(client: Chat.instance)
}()

lazy var accountStorage: AccountStorage = {
Expand Down
22 changes: 0 additions & 22 deletions Example/Showcase/Classes/DomainLayer/Chat/ChatFactory.swift

This file was deleted.

14 changes: 7 additions & 7 deletions Example/Showcase/Classes/DomainLayer/Chat/ChatService.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import Combine
import Chat
import WalletConnectChat
import WalletConnectRelay

typealias Stream<T> = AsyncPublisher<AnyPublisher<T, Never>>
Expand All @@ -21,23 +21,23 @@ final class ChatService {
return client.messagePublisher.values
}

var threadPublisher: Stream<Chat.Thread> {
var threadPublisher: Stream<WalletConnectChat.Thread> {
return client.newThreadPublisher.values
}

var invitePublisher: Stream<Invite> {
return client.invitePublisher.values
}

func getMessages(thread: Chat.Thread) async -> [Chat.Message] {
func getMessages(thread: WalletConnectChat.Thread) async -> [WalletConnectChat.Message] {
await client.getMessages(topic: thread.topic)
}

func getThreads() async -> [Chat.Thread] {
func getThreads() async -> [WalletConnectChat.Thread] {
await client.getThreads()
}

func getInvites(account: Account) async -> [Chat.Invite] {
func getInvites(account: Account) async -> [WalletConnectChat.Invite] {
client.getInvites(account: account)
}

Expand All @@ -53,8 +53,8 @@ final class ChatService {
try await client.reject(inviteId: invite.id)
}

func invite(peerPubkey publicKey: String, peerAccount: Account, message: String, selfAccount: Account) async throws {
try await client.invite(publicKey: publicKey, peerAccount: peerAccount, openingMessage: message, account: selfAccount)
func invite(peerAccount: Account, message: String, selfAccount: Account) async throws {
try await client.invite(peerAccount: peerAccount, openingMessage: message, account: selfAccount)
}

func register(account: Account) async throws {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Chat
import WalletConnectChat

final class ChatInteractor {

Expand All @@ -9,7 +9,7 @@ final class ChatInteractor {
self.chatService = chatService
}

func getMessages(thread: Chat.Thread) async -> [Message] {
func getMessages(thread: WalletConnectChat.Thread) async -> [Message] {
return await chatService.getMessages(thread: thread)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import SwiftUI
import Chat
import WalletConnectChat

final class ChatModule {

@discardableResult
static func create(thread: Chat.Thread, app: Application) -> UIViewController {
static func create(thread: WalletConnectChat.Thread, app: Application) -> UIViewController {
let router = ChatRouter(app: app)
let interactor = ChatInteractor(chatService: app.chatService)
let presenter = ChatPresenter(thread: thread, interactor: interactor, router: router)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import UIKit
import Combine
import Chat
import WalletConnectChat

final class ChatPresenter: ObservableObject {

private let thread: Chat.Thread
private let thread: WalletConnectChat.Thread
private let interactor: ChatInteractor
private let router: ChatRouter
private var disposeBag = Set<AnyCancellable>()

@Published var messages: [MessageViewModel] = []
@Published var input: String = .empty

init(thread: Chat.Thread, interactor: ChatInteractor, router: ChatRouter) {
init(thread: WalletConnectChat.Thread, interactor: ChatInteractor, router: ChatRouter) {
self.thread = thread
self.interactor = interactor
self.router = router
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation
import Chat
import WalletConnectChat

struct MessageViewModel {
private let message: Message
private let thread: Chat.Thread
private let thread: WalletConnectChat.Thread

init(message: Message, thread: Chat.Thread) {
init(message: Message, thread: WalletConnectChat.Thread) {
self.message = message
self.thread = thread
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Chat
import WalletConnectChat

final class ChatListInteractor {

Expand All @@ -10,11 +10,11 @@ final class ChatListInteractor {
self.accountStorage = accountStorage
}

func getThreads() async -> [Chat.Thread] {
func getThreads() async -> [WalletConnectChat.Thread] {
return await chatService.getThreads()
}

func threadsSubscription() -> Stream<Chat.Thread> {
func threadsSubscription() -> Stream<WalletConnectChat.Thread> {
return chatService.threadPublisher
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import Chat
import WalletConnectChat

final class ChatListRouter {

Expand All @@ -21,7 +21,7 @@ final class ChatListRouter {
InviteListModule.create(app: app, account: account).push(from: viewController)
}

func presentChat(thread: Chat.Thread) {
func presentChat(thread: WalletConnectChat.Thread) {
ChatModule.create(thread: thread, app: app).push(from: viewController)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import Chat
import WalletConnectChat

struct ThreadViewModel: Identifiable {
let thread: Chat.Thread
let thread: WalletConnectChat.Thread

var topic: String {
return thread.topic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ final class InviteInteractor {
}

func invite(peerAccount: Account, message: String, selfAccount: Account) async {
let publicKey = try! await chatService.resolve(account: peerAccount)
try! await chatService.invite(peerPubkey: publicKey, peerAccount: peerAccount, message: message, selfAccount: selfAccount)
try! await chatService.invite(peerAccount: peerAccount, message: message, selfAccount: selfAccount)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Chat
import WalletConnectChat

final class InviteListInteractor {
private let chatService: ChatService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit
import Combine
import Chat
import WalletConnectChat

final class InviteListPresenter: ObservableObject {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Chat
import WalletConnectChat

struct InviteViewModel {
let invite: Invite
Expand Down
Loading

1 comment on commit 3013d46

@lyn4935

This comment was marked as outdated.

Please sign in to comment.