hashgraph / hedera-wallet-connect

This package is a messaging relay between decentralized applications and wallets in Hedera network based on Wallet Connect relays.
Apache License 2.0
10 stars 18 forks source link

Calling getSigner sometimes has false positives #254

Open kantorcodes opened 1 month ago

kantorcodes commented 1 month ago

Describe the bug Sometimes calling getSigner does not return the Signer, even after a single refresh.

Error: Signer is not found for this accountId

To Reproduce Steps to reproduce the behavior:

Run:

    const signer = this.dAppConnector.getSigner(
      AccountId.fromString(accountId)
    );
    this.logger.info('Got signer:', signer);
    return signer?.getAccountId()?.toString();
    await new Promise((resolve) => setTimeout(resolve, 1000));
    const signer = this.dAppConnector.getSigner(
      AccountId.fromString(accountId)
    );
    this.logger.info('Got signer:', signer);
    return signer?.getAccountId()?.toString();

Expected behavior: If you have not called disconnect() and the user has not manually disconnected then, getSigner() should always return the signer.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

tmctl commented 2 days ago

@kantorcodes

we're struggling to reproduce.

The reproduction code does not cause the described behavior. Signer is returned throughout the lifecycle of the active session.

It should be taken into account that the signer can be deleted not only by calling disconnect or disconnectAll methods, but also by the user/wallet's initiative, as well as by session or pairing expiration.

It is possible to subscribe to session_delete, session_expire events for sessions and pairing_delete, pairing_expire event for pairings to handle these cases:

dAppConnector.walletConnectClient.on('session_delete', (pairing) => {
  console.log('Dapp: Session deleted by wallet!')
})

dAppConnector.walletConnectClient.on('session_expire', (pairing) => {
  console.log('Dapp: Session expire!')
})

dAppConnector.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
  console.log('Dapp: Pairing deleted by wallet!')
})

dAppConnector.walletConnectClient.core.pairing.events.on('pairing_expire', (pairing) => {
  console.log('Dapp: Pairing expire!')
})