From ae3277ffffa87519f7eaf5716476a82a259a176a Mon Sep 17 00:00:00 2001 From: Ivan Grachev Date: Sat, 10 Jul 2021 22:54:55 +0300 Subject: [PATCH] Stub restarting sessions --- Encrypted Ink/Agent.swift | 1 + Encrypted Ink/Services/SessionStorage.swift | 15 +++++++++++++++ Encrypted Ink/WalletConnect.swift | 13 ++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Encrypted Ink/Agent.swift b/Encrypted Ink/Agent.swift index 286907cc..bf74b69a 100644 --- a/Encrypted Ink/Agent.swift +++ b/Encrypted Ink/Agent.swift @@ -42,6 +42,7 @@ class Agent: NSObject { if success { self?.didEnterPasswordOnStart = true self?.showInitialScreen(wcSession: wcSession) + WalletConnect.shared.restartSessions() } } return diff --git a/Encrypted Ink/Services/SessionStorage.swift b/Encrypted Ink/Services/SessionStorage.swift index 7b12aae6..25146139 100644 --- a/Encrypted Ink/Services/SessionStorage.swift +++ b/Encrypted Ink/Services/SessionStorage.swift @@ -1,11 +1,26 @@ // Copyright © 2021 Encrypted Ink. All rights reserved. import Foundation +import WalletConnect class SessionStorage { + struct Item: Codable { + let session: WCSession + let address: String + let uuid: UUID + } + static let shared = SessionStorage() private init() {} + func loadAll() -> [Item] { + return [] + } + + func add(session: WCSession, address: String, uuid: UUID) { + // TODO: implement + } + } diff --git a/Encrypted Ink/WalletConnect.swift b/Encrypted Ink/WalletConnect.swift index b1c124b0..7ec8db1c 100644 --- a/Encrypted Ink/WalletConnect.swift +++ b/Encrypted Ink/WalletConnect.swift @@ -5,6 +5,7 @@ import WalletConnect class WalletConnect { + private let sessionStorage = SessionStorage.shared static let shared = WalletConnect() private init() {} @@ -15,9 +16,9 @@ class WalletConnect { return WCSession.from(string: link) } - func connect(session: WCSession, address: String, completion: @escaping ((Bool) -> Void)) { + func connect(session: WCSession, address: String, uuid: UUID = UUID(), completion: @escaping ((Bool) -> Void)) { let clientMeta = WCPeerMeta(name: "Encrypted Ink", url: "https://encrypted.ink", description: "Ethereum agent for macOS", icons: ["https://encrypted.ink/icon.png"]) - let interactor = WCInteractor(session: session, meta: clientMeta, uuid: UUID()) + let interactor = WCInteractor(session: session, meta: clientMeta, uuid: uuid) let id = interactor.clientId configure(interactor: interactor, address: address) @@ -30,9 +31,11 @@ class WalletConnect { interactors.append(interactor) } - func killAllSessions() { - interactors.forEach { - $0.killSession().cauterize() + func restartSessions() { + let items = sessionStorage.loadAll() + for item in items { + connect(session: item.session, address: item.address, uuid: item.uuid) { _ in } + // TODO: maybe should remove from storage on unsuccessful connection attempt } }