tokenary/Encrypted Ink/Services/SessionStorage.swift

29 lines
715 B
Swift
Raw Normal View History

2021-07-10 22:41:53 +03:00
// Copyright © 2021 Encrypted Ink. All rights reserved.
import Foundation
2021-07-10 22:54:55 +03:00
import WalletConnect
2021-07-10 22:41:53 +03:00
class SessionStorage {
2021-07-10 22:54:55 +03:00
struct Item: Codable {
let session: WCSession
let address: String
let uuid: UUID
2021-07-11 14:41:04 +03:00
let sessionDetails: WCSessionRequestParam
2021-07-10 22:54:55 +03:00
}
2021-07-10 22:41:53 +03:00
static let shared = SessionStorage()
private init() {}
2021-07-10 22:54:55 +03:00
func loadAll() -> [Item] {
2021-07-10 23:26:21 +03:00
return Defaults.storedSessions
2021-07-10 22:54:55 +03:00
}
2021-07-11 14:41:04 +03:00
func add(session: WCSession, address: String, uuid: UUID, sessionDetails: WCSessionRequestParam) {
let item = Item(session: session, address: address, uuid: uuid, sessionDetails: sessionDetails)
2021-07-10 23:26:21 +03:00
Defaults.storedSessions.append(item)
2021-07-10 22:54:55 +03:00
}
2021-07-10 22:41:53 +03:00
}