walletconnect-dart-sdk
walletconnect-dart-sdk copied to clipboard
[fix] killSession not working, #84
fix #84
The problem is caused by the use of unawaited
, I think it is because the killSession
request will not have any response and the author wants to run killSession
and then use _handleSessionDisconnect
to reset the local state immediately.
Unfortunately, the actual situation is that the local state is reset before the killSession
request is sent out, so a valid killSession
request cannot be sent successfully.
Future killSession({String? sessionError}) async {
...
unawaited(_sendRequest(request));
await _handleSessionDisconnect(errorMessage: message, forceClose: true);
..
}
To reduce the impact on other places, I just add a delay to ensure that the killSession
request can be sent out before the _handleSessionDisconnect
reset local state.
unawaited(_sendRequest(request));
// Avoid starting `_handleSessionDisconnect` before completing `_sendRequest`, which will cause the dapp to not be disconnected from the wallet, https://github.com/RootSoft/walletconnect-dart-sdk/issues/84
await Future.delayed(const Duration(milliseconds: 100));
await _handleSessionDisconnect(errorMessage: message, forceClose: true);
Hope to approve this PR, please let me know if there are any problems 🙏🏻 Thanks so much
await Future.delayed(const Duration(milliseconds: 100));
is always guaranteed to work?
hard coding a 100 ms
doesn't seem to be very attractive
I have tested on my android and ios device, btw I know it's just a workaround solution.
Author should come up with a better solution
https://github.com/RootSoft/walletconnect-dart-sdk/issues/84#issuecomment-1305987493