Skip to content

Commit

Permalink
Invite screen UI
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Jul 8, 2022
1 parent 935d923 commit cd83c7f
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Example/Showcase/Classes/DomainLayer/ChatService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ final class ChatService {
func reject(invite: Invite) async throws {

}

func invite(account: String) async throws {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ final class ChatListRouter {
}

func presentInvite() {
InviteModule.create(app: app).push(from: viewController)
InviteModule.create(app: app)
.wrapToNavigationController()
.present(from: viewController)
}

func presentInviteList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
final class InviteInteractor {
private let chatService: ChatService

init(chatService: ChatService) {
self.chatService = chatService
}

func invite(account: String) async {
try! await chatService.invite(account: account)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class InviteModule {
@discardableResult
static func create(app: Application) -> UIViewController {
let router = InviteRouter(app: app)
let interactor = InviteInteractor()
let interactor = InviteInteractor(chatService: app.chatService)
let presenter = InvitePresenter(interactor: interactor, router: router)
let view = InviteView().environmentObject(presenter)
let viewController = SceneViewController(viewModel: presenter, content: view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,38 @@ final class InvitePresenter: ObservableObject {
private let router: InviteRouter
private var disposeBag = Set<AnyCancellable>()

@Published var input: String = .empty {
didSet { didInputChanged() }
}

lazy var rightBarButtonItem: UIBarButtonItem? = {
let item = UIBarButtonItem(
title: "Invite",
style: .plain,
target: self,
action: #selector(invite)
)
item.isEnabled = false
return item
}()

init(interactor: InviteInteractor, router: InviteRouter) {
self.interactor = interactor
self.router = router
}

var isClearVisible: Bool {
return input.count > 0
}

@MainActor
func setupInitialState() async {

}

func didPressClear() {
input = .empty
}
}

// MARK: SceneViewModel
Expand All @@ -35,4 +58,15 @@ extension InvitePresenter: SceneViewModel {

private extension InvitePresenter {

@MainActor
@objc func invite() {
Task(priority: .userInitiated) {
await interactor.invite(account: input)
router.dismiss()
}
}

func didInputChanged() {
rightBarButtonItem?.isEnabled = !input.isEmpty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ final class InviteRouter {
init(app: Application) {
self.app = app
}

func dismiss() {
viewController.dismiss()
}
}
38 changes: 35 additions & 3 deletions Example/Showcase/Classes/PresentationLayer/Invite/InviteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,42 @@ struct InviteView: View {
@EnvironmentObject var presenter: InvitePresenter

var body: some View {
Text("Invite module")
.task {
await presenter.setupInitialState()
VStack {
VStack(alignment: .leading) {
Text("ENS Name or Public Key")
.font(.subheadline)
.foregroundColor(.w_secondaryForeground)
.padding(.horizontal, 16.0)

HStack {
TextField("username.eth or 0x0…", text: $presenter.input)
.font(.body)
.foregroundColor(.w_foreground)

if presenter.isClearVisible {
Button(action: { presenter.didPressClear() }, label: {
Image(systemName: "xmark.circle.fill")
.frame(width: 17.0, height: 17.0)
})
}
}
.padding(.horizontal, 16.0)
}
.frame(height: 72.0)
.background(
RoundedRectangle(cornerRadius: 14.0)
.foregroundColor(.w_secondaryBackground)
)
.overlay(
RoundedRectangle(cornerRadius: 14.0)
.stroke(Color.w_tertiaryBackground, lineWidth: 0.5)
)
.padding(16.0)

Spacer()
}.task {
await presenter.setupInitialState()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ final class InviteListInteractor {
return chatService.getInvites()
}


func accept(invite: Invite) async {
try! await chatService.accept(invite: invite)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

// TODO: Delete after Chat SDK integration
struct Invite{
struct Invite {
let message: String
let pubKey: String
}
Expand Down
12 changes: 9 additions & 3 deletions Example/Showcase/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

enum NavigationBarStyle {
case color(UIColor)
case translucent(UIColor)
}

protocol SceneViewModel {
Expand All @@ -11,6 +11,8 @@ protocol SceneViewModel {
var rightBarButtonItem: UIBarButtonItem? { get }
var navigationBarStyle: NavigationBarStyle { get }
var preferredStatusBarStyle: UIStatusBarStyle { get }
var isNavigationBarTranslucent: Bool { get }

}

extension SceneViewModel {
Expand All @@ -27,11 +29,14 @@ extension SceneViewModel {
return .none
}
var navigationBarStyle: NavigationBarStyle {
return .color(.w_background)
return .translucent(.w_background)
}
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
var isNavigationBarTranslucent: Bool {
return true
}
}

class SceneViewController<ViewModel: SceneViewModel, Content: View>: UIHostingController<Content> {
Expand Down Expand Up @@ -77,8 +82,9 @@ private extension SceneViewController {

func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .color(let color):
case .translucent(let color):
navigationController?.navigationBar.barTintColor = color
navigationController?.navigationBar.isTranslucent = true
}
}
}
1 change: 0 additions & 1 deletion Sources/Chat/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ class Chat {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InvitationHandlingService {
}

private func getInviteResponseTopic(_ payload: RequestSubscriptionPayload, _ invite: Invite) throws -> String {
//todo - remove topicToInvitationPubKeyStore ?
// todo - remove topicToInvitationPubKeyStore ?

guard let selfPubKeyHex = try? topicToInvitationPubKeyStore.get(key: payload.topic) else {
logger.debug("PubKey for invitation topic not found")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Chat/Types/Message.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

struct Message: Codable, Equatable {
let message : String
let message: String
let authorAccount: String
let timestamp: Int64
}
2 changes: 1 addition & 1 deletion Sources/WalletConnectKMS/Serialiser/Serializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Serializer: Serializing {
guard let selfPubKey = kms.getPublicKey(for: topic),
case let .type1(peerPubKey) = envelope.type else { return nil }
do {
//self pub key is good
// self pub key is good
let agreementKeys = try kms.performKeyAgreement(selfPublicKey: selfPubKey, peerPublicKey: peerPubKey.toHexString())
let decodedType: T? = try decode(sealbox: envelope.sealbox, symmetricKey: agreementKeys.sharedKey.rawRepresentation)
let newTopic = agreementKeys.derivedTopic()
Expand Down

0 comments on commit cd83c7f

Please sign in to comment.