walletconnect-dart-sdk icon indicating copy to clipboard operation
walletconnect-dart-sdk copied to clipboard

[fix] killSession not working, #84

Open WingCH opened this issue 1 year ago • 2 comments

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

WingCH avatar Nov 05 '22 16:11 WingCH

await Future.delayed(const Duration(milliseconds: 100)); is always guaranteed to work? hard coding a 100 ms doesn't seem to be very attractive

Neo-vortex avatar Nov 11 '22 05:11 Neo-vortex

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

WingCH avatar Nov 11 '22 14:11 WingCH