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

ACTIVE_ACCOUNT_SET is emitted twice #743

Closed AlexandrosGounis closed 3 months ago

AlexandrosGounis commented 4 months ago

Describe the bug (current behavior) When using requestPermissions for the first time on a DApp, no ACTIVE_ACCOUNT_SET is emitted. If the user disconnects and uses a subsequent requestPermissions then two, identical ACTIVE_ACCOUNT_SET events are emitted. Duplicate messages are also emitted when users initiate an account switch event on their wallet.

To Reproduce Steps to reproduce the behavior:

  1. Use requestPermissions (no event will be emitted the first time)
  2. Use disconnect or removeAllAccounts (an ACTIVE_ACCOUNT_SET event will be emitted with an empty payload)
  3. Use requestPermissions again (two, identical ACTIVE_ACCOUNT_SET events will be emitted)

Expected (correct) behavior ACTIVE_ACCOUNT_SET should only be emitted once when the active account changes.

Example

client.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (payload) => {
    // receives two identical messages on subsequent pairings
});

Environment Tested on ghostnet

IsaccoSordo commented 4 months ago

Hi @AlexandrosGounis The issue was caused by the following line https://github.com/airgap-it/beacon-sdk/blob/3026e3f03644ff75c31bd56eb939d87e0513aa11/packages/beacon-dapp/src/dapp-client/DAppClient.ts#L1344 as we already call setActiveAccount inside onNewAccount

IsaccoSordo commented 3 months ago

This issue has been addressed in v4.2.1