Refactor reconnecting

This commit is contained in:
Ivan Grachyov 2021-07-11 14:43:17 +03:00
parent 81aa9c815b
commit 3e3afde86c

View File

@ -69,9 +69,10 @@ class WalletConnect {
interactor?.approveSession(accounts: accounts, chainId: chainId).cauterize()
}
interactor.onDisconnect = { [weak interactor] _ in
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(10)) {
interactor?.resume() // TODO: reconnect when appropriate. should not reconnect when session is killed.
interactor.onDisconnect = { [weak interactor, weak self] _ in
// TODO: should not reconnect when session is killed.
if let interactor = interactor {
self?.reconnectWhenPossible(interactor: interactor)
}
}
@ -84,6 +85,12 @@ class WalletConnect {
}
}
private func reconnectWhenPossible(interactor: WCInteractor) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(10)) { [weak interactor] in
interactor?.resume() // TODO: reconnect when appropriate.
}
}
private func approveTransaction(id: Int64, wct: WCEthereumTransaction, address: String, interactor: WCInteractor?) {
guard let to = wct.to else {
rejectRequest(id: id, interactor: interactor, message: "Something went wrong.")