Stub restarting sessions

This commit is contained in:
Ivan Grachev 2021-07-10 22:54:55 +03:00
parent 4db073ecbf
commit ae3277ffff
3 changed files with 24 additions and 5 deletions

View File

@ -42,6 +42,7 @@ class Agent: NSObject {
if success {
self?.didEnterPasswordOnStart = true
self?.showInitialScreen(wcSession: wcSession)
WalletConnect.shared.restartSessions()
}
}
return

View File

@ -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
}
}

View File

@ -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
}
}