Fix showing dapp details after restart

This commit is contained in:
Ivan Grachyov 2021-07-11 15:07:40 +03:00
parent 3e3afde86c
commit b6213a375f
2 changed files with 13 additions and 7 deletions

View File

@ -8,7 +8,7 @@ class SessionStorage {
struct Item: Codable {
let session: WCSession
let address: String
let uuid: UUID
let clientId: String
let sessionDetails: WCSessionRequestParam
}
@ -20,8 +20,12 @@ class SessionStorage {
return Defaults.storedSessions
}
func add(session: WCSession, address: String, uuid: UUID, sessionDetails: WCSessionRequestParam) {
let item = Item(session: session, address: address, uuid: uuid, sessionDetails: sessionDetails)
func removeAll() {
Defaults.storedSessions = []
}
func add(session: WCSession, address: String, clientId: String, sessionDetails: WCSessionRequestParam) {
let item = Item(session: session, address: address, clientId: clientId, sessionDetails: sessionDetails)
Defaults.storedSessions.append(item)
}

View File

@ -33,9 +33,11 @@ class WalletConnect {
func restartSessions() {
let items = sessionStorage.loadAll()
for item in items {
connect(session: item.session, address: item.address, uuid: item.uuid) { _ in }
peers[item.sessionDetails.peerId] = item.sessionDetails.peerMeta
guard let uuid = UUID(uuidString: item.clientId) else { continue }
connect(session: item.session, address: item.address, uuid: uuid) { _ in }
peers[item.clientId] = item.sessionDetails.peerMeta
// TODO: maybe should remove from storage on unsuccessful connection attempt
}
}
@ -61,10 +63,10 @@ class WalletConnect {
if let id = interactor?.clientId {
self?.peers[id] = peer
}
if let session = interactor?.session, let uuid = UUID(uuidString: interactor?.clientId ?? "") {
if let session = interactor?.session, let clientId = interactor?.clientId {
WCSessionStore.store(session, peerId: peerParam.peerId, peerMeta: peer)
// TODO: store session if it is not already stored
self?.sessionStorage.add(session: session, address: address, uuid: uuid, sessionDetails: peerParam)
self?.sessionStorage.add(session: session, address: address, clientId: clientId, sessionDetails: peerParam)
}
interactor?.approveSession(accounts: accounts, chainId: chainId).cauterize()
}