Don't use getter for accessing walletconnector in close() method to prevent race condition inside getter when session is already killed #208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bug:
If you use walletconnect to connect your wallet and then close session from the mobile wallet while currently being inside the dapp, it will show you an invalid QRCode modal.
Steps to reproduce:
The reason for this bug
When user disconnects the session,
_handleDisconnectSession
method is called inside@walletconnect/core
and sets propertyconnected
on walletConnector tofalse
. Then whatever uses the core (let's sayweb3connect
), receives the disconnect event and wants to perform a cleanup and close walletconnect connection (not actually sure whether this is the best way to handle this, but this is how it's done in the web3connect example app: https://github.com/web3connect/web3connect/blob/master/example/src/App.tsx#L346). It calls.close()
and close tries to get the walletconnector viagetWalletConnector
, inside this method it checks ifwc.connected
is true and if not, it tries to initialize a new session and shows QRCode modal.Background info
I also thought about handling it inside
subscribeWalletConnector
:walletconnect-monorepo/packages/web3-provider/src/index.js
Line 341 in 0f756f1
.close
method felt wrong. If I am missing something, please let me know