airgap-it / beacon-sdk

The beacon sdk allows developers of dApps and wallets on Tezos to implement the wallet interaction standard tzip-10.
https://walletbeacon.io
MIT License
102 stars 64 forks source link

Disconnect throws no matching keys and ACTIVE_ACCOUNT_SET is emitted twice (wallet-connect transport) #757

Closed AlexandrosGounis closed 2 months ago

AlexandrosGounis commented 3 months ago

Describe the bug (current behavior) Upon a user-initiated disconnect on the DApp side there are no matching key errors in the console. This is evident on some DApp setups. After the first errors appear, the ACTIVE_ACCOUNT_SET event is emitted twice when account switching happens.

To Reproduce

  1. Go to staging.objkt.com, connect an account using a wallet-connect enabled wallet such as kukai.app (copy-paste the QR Code on kukai.app > settings (cog icon) > Scan QR Code)
  2. Sign the expression
  3. Sign out (on staging.objkt.com) — ⚠️ at this point there will be “no matching keys” in the console
  4. Connect an account again (same as step 1)
  5. Sign the expression
  6. Go to kukai.app > settings > Wallet Connect > sessions > click the pencil icon to switch account
  7. Sign the expression — this will trigger a second expression, more “no matching keys” in the console, this is likely because the ACTIVE_ACCOUNT_SET event is emitted twice

We occasionally get rate limit warnings due to the amount of requests sent to the wallet (likely ≥ 3)

Rate limit warnings

rate-limits
IsaccoSordo commented 3 months ago

Hi @AlexandrosGounis, The issue was caused by our cleanup logic, which inadvertently led the signClient internal state to refer to an old or deleted pairing. With #760, we now clear the signClient internal state before removing the reference.

As a footnote, I was able to reproduce this error in our example dApp using the following steps:

  1. Click "Request Permission", select "Kukai", and then choose "Use Browser" (this will utilize the P2P transport).
  2. In the wallet, reject the proposal.
  3. Return to the example dApp, click "Request Permission" again, select "Kukai Wallet", copy the sync code from the QR button, and then paste it into Kukai.
  4. Approve the sync proposal.
  5. The error “No matching key: pairing” will then appear in the console.
IsaccoSordo commented 3 months ago

Hi @AlexandrosGounis, We found multiple instances of failed subscriptions cleanup, which was the reason why you were receiving multiple times the same event. This should no longer be an issue in #764

IsaccoSordo commented 2 months ago

The fix has been included in v4.2.2