mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-14 06:26:41 +03:00
Remove disconnected interactors
This commit is contained in:
parent
4551f70b18
commit
3fc5dd7e1f
@ -18,12 +18,14 @@ class WalletConnect {
|
|||||||
let clientMeta = WCPeerMeta(name: "Encrypted Ink", url: "https://encrypted.ink")
|
let clientMeta = WCPeerMeta(name: "Encrypted Ink", url: "https://encrypted.ink")
|
||||||
|
|
||||||
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)
|
configure(interactor: interactor, address: address)
|
||||||
|
|
||||||
interactor.connect().done { connected in
|
interactor.connect().done { connected in
|
||||||
completion(connected)
|
completion(connected)
|
||||||
}.catch { _ in
|
}.catch { [weak self] _ in
|
||||||
completion(false)
|
completion(false)
|
||||||
|
self?.removeInteractor(id: id)
|
||||||
}
|
}
|
||||||
interactors.append(interactor)
|
interactors.append(interactor)
|
||||||
}
|
}
|
||||||
@ -34,9 +36,14 @@ class WalletConnect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func removeInteractor(id: String) {
|
||||||
|
interactors.removeAll(where: { $0.clientId == id })
|
||||||
|
}
|
||||||
|
|
||||||
private func configure(interactor: WCInteractor, address: String) {
|
private func configure(interactor: WCInteractor, address: String) {
|
||||||
let accounts = [address]
|
let accounts = [address]
|
||||||
let chainId = 1
|
let chainId = 1
|
||||||
|
let id = interactor.clientId
|
||||||
|
|
||||||
interactor.onError = { _ in }
|
interactor.onError = { _ in }
|
||||||
|
|
||||||
@ -45,7 +52,9 @@ class WalletConnect {
|
|||||||
interactor?.approveSession(accounts: accounts, chainId: chainId).cauterize()
|
interactor?.approveSession(accounts: accounts, chainId: chainId).cauterize()
|
||||||
}
|
}
|
||||||
|
|
||||||
interactor.onDisconnect = { _ in }
|
interactor.onDisconnect = { [weak self] _ in
|
||||||
|
self?.removeInteractor(id: id)
|
||||||
|
}
|
||||||
|
|
||||||
interactor.eth.onSign = { [weak self, weak interactor] (id, payload) in
|
interactor.eth.onSign = { [weak self, weak interactor] (id, payload) in
|
||||||
self?.approveSign(id: id, payload: payload, address: address, interactor: interactor)
|
self?.approveSign(id: id, payload: payload, address: address, interactor: interactor)
|
||||||
|
Loading…
Reference in New Issue
Block a user