From d0e581d9f2c44fd44b14705c987c3df48b88f9c9 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Tue, 24 May 2022 20:11:08 +0500 Subject: [PATCH] Reload SessionDetails on request respond --- .../SessionDetailViewController.swift | 10 +++++++--- .../SessionDetailViewModel.swift | 4 ++-- .../Wallet/WalletViewController.swift | 19 +++---------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Example/ExampleApp/SessionDetails/SessionDetailViewController.swift b/Example/ExampleApp/SessionDetails/SessionDetailViewController.swift index 559afb6fb..b2e98447f 100644 --- a/Example/ExampleApp/SessionDetails/SessionDetailViewController.swift +++ b/Example/ExampleApp/SessionDetails/SessionDetailViewController.swift @@ -7,7 +7,7 @@ final class SessionDetailViewController: UIHostingController 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)) @@ -15,6 +15,10 @@ final class SessionDetailViewController: UIHostingController self?.showSessionRequest(request) } } + + func reload() { + viewModel.objectWillChange.send() + } private func showSessionRequest(_ request: Request) { let viewController = RequestViewController(request) @@ -22,7 +26,7 @@ final class SessionDetailViewController: UIHostingController let result = Signer.signEth(request: request) let response = JSONRPCResponse(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( @@ -32,7 +36,7 @@ final class SessionDetailViewController: UIHostingController error: JSONRPCErrorResponse.Error(code: 0, message: "")) ) ) - viewModel.objectWillChange.send() + reload() } present(viewController, animated: true) } diff --git a/Example/ExampleApp/SessionDetails/SessionDetailViewModel.swift b/Example/ExampleApp/SessionDetails/SessionDetailViewModel.swift index faefb3d87..8af18a759 100644 --- a/Example/ExampleApp/SessionDetails/SessionDetailViewModel.swift +++ b/Example/ExampleApp/SessionDetails/SessionDetailViewModel.swift @@ -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 @@ -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 diff --git a/Example/ExampleApp/Wallet/WalletViewController.swift b/Example/ExampleApp/Wallet/WalletViewController.swift index 812a2b68b..a01a7ae74 100644 --- a/Example/ExampleApp/Wallet/WalletViewController.swift +++ b/Example/ExampleApp/Wallet/WalletViewController.swift @@ -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? @@ -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) } @@ -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() } }