Skip to content

Commit

Permalink
Reload SessionDetails on request respond
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed May 24, 2022
1 parent 38a87d7 commit 10f73cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ final class SessionDetailViewController: UIHostingController<SessionDetailView>

private let viewModel: SessionDetailViewModel

init(session: Session, client: AuthClient) {
init(session: Session, client: Auth) {
self.viewModel = SessionDetailViewModel(session: session, client: client)
super.init(rootView: SessionDetailView(viewModel: viewModel))

rootView.didPressSessionRequest = { [weak self] request in
self?.showSessionRequest(request)
}
}

func reload() {
viewModel.objectWillChange.send()
}

private func showSessionRequest(_ request: Request) {
let viewController = RequestViewController(request)
viewController.onSign = { [unowned self] in
let result = Signer.signEth(request: request)
let response = JSONRPCResponse<AnyCodable>(id: request.id, result: result)
Auth.instance.respond(topic: request.topic, response: .response(response))
viewModel.objectWillChange.send()
reload()
}
viewController.onReject = { [unowned self] in
Auth.instance.respond(
Expand All @@ -32,7 +36,7 @@ final class SessionDetailViewController: UIHostingController<SessionDetailView>
error: JSONRPCErrorResponse.Error(code: 0, message: ""))
)
)
viewModel.objectWillChange.send()
reload()
}
present(viewController, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WalletConnectAuth
@MainActor
final class SessionDetailViewModel: ObservableObject {
private let session: Session
private let client: AuthClient
private let client: Auth

enum Fields {
case accounts
Expand All @@ -16,7 +16,7 @@ final class SessionDetailViewModel: ObservableObject {

@Published var namespaces: [String: SessionNamespace]

init(session: Session, client: AuthClient) {
init(session: Session, client: Auth) {
self.session = session
self.client = client
self.namespaces = session.namespaces
Expand Down
19 changes: 3 additions & 16 deletions Example/ExampleApp/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ import Combine
import SwiftUI

final class WalletViewController: UIViewController {

let client: AuthClient = {
let metadata = AppMetadata(
name: "Example Wallet",
description: "wallet description",
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"])
return AuthClient(
metadata: metadata,
projectId: "8ba9ee138960775e5231b70cc5ef1c3a",
relayHost: "relay.walletconnect.com"
)
}()
lazy var account = Signer.privateKey.address.hex(eip55: true)
var sessionItems: [ActiveSessionItem] = []
var currentProposal: Session.Proposal?
Expand Down Expand Up @@ -69,7 +56,7 @@ final class WalletViewController: UIViewController {
}

private func showSessionDetails(with session: Session) {
let viewController = SessionDetailViewController(session: session, client: client)
let viewController = SessionDetailViewController(session: session, client: Auth.instance)
navigationController?.present(viewController, animated: true)
}

Expand All @@ -90,8 +77,8 @@ final class WalletViewController: UIViewController {
}

func reloadSessionDetailsIfNeeded() {
if let sessionDetailsViewController = navigationController?.viewControllers.first(where: {$0 is SessionDetailsViewController}) as? SessionDetailsViewController {
sessionDetailsViewController.reloadTable()
if let viewController = navigationController?.presentedViewController as? SessionDetailViewController {
viewController.reload()
}
}

Expand Down

0 comments on commit 10f73cc

Please sign in to comment.