mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-02 09:33:49 +03:00
Stub restarting sessions
This commit is contained in:
parent
4db073ecbf
commit
ae3277ffff
@ -42,6 +42,7 @@ class Agent: NSObject {
|
||||
if success {
|
||||
self?.didEnterPasswordOnStart = true
|
||||
self?.showInitialScreen(wcSession: wcSession)
|
||||
WalletConnect.shared.restartSessions()
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user