extension icon indicating copy to clipboard operation
extension copied to clipboard

Unsub for `accounts.subscribe` and `web3AccountsSubscribe` do not unsubscribe.

Open F-OBrien opened this issue 2 years ago • 3 comments

  • I'm submitting a ...
  • [x] Bug report
  • [ ] Feature request
  • [ ] Support request
  • [ ] Other
  • What is the current behavior and expected behavior?

The unsub callbacks for accounts.subscribe and web3AccountsSubscribe do not unsubscribe. This was reported previously in issue #1017 and #1088. It was reported to have been fixed in #1067 however I've just tested with release 0.44.6 and the issue is still present.

  • What is the motivation for changing the behavior?

Bug fix.

  • Please tell us about your environment:

Ubuntu-20.04 (on WSL2). See below steps to reproduce with create react app.

Steps to reproduce.

  • npx create-react-app my-app --template typescript
  • cd my-app
  • npm i @polkadot/extension-dapp
  • Replace the contents of src/App.tsx with the below.
  • npm run start
  • Check console log and add remove accounts. Neither unsubscribes.
import { web3AccountsSubscribe, web3Enable } from '@polkadot/extension-dapp';
import { Unsubcall } from '@polkadot/extension-inject/types';
import { useEffect} from 'react';

function App() {

  useEffect(() => {
    let unsubAccounts: Unsubcall
    let unsubWeb3Accounts: Unsubcall
    
    const subAccounts = async () => {
  
      const extensions = await web3Enable('Test web3AccountsSubscribe');

      unsubAccounts = extensions[0].accounts.subscribe(()=>{
        console.log("I'm still subscribed");
        setTimeout(() => {
          console.log('called unsub Accounts');
          unsubAccounts();
        }, 1000 * 5);

      })

      unsubWeb3Accounts = await web3AccountsSubscribe((accounts) => {
        console.log("I'm also still subscribed");
        setTimeout(() => {
          console.log('called unsub Web3Accounts');
          unsubWeb3Accounts();
        }, 1000 * 5);

      });
    };
  
    subAccounts();
    return ()=>{
      unsubAccounts && unsubAccounts()
      unsubWeb3Accounts && unsubWeb3Accounts()
    }
  }, []);

  return (
    <h1 >
        Add or remove accounts from your wallet extension and check the console log.
    </h1>
  );
}
  • Version: 0.44.6

  • Environment:

    • [ ] Node.js
    • [x] Browser
    • [ ] Other (limited support for other environments)
  • Language:

    • [ ] JavaScript
    • [x] TypeScript (include tsc --version)
    • [ ] Other

F-OBrien avatar Sep 19 '22 18:09 F-OBrien

0.44.1 is the last publish to the stores.

jacogr avatar Sep 19 '22 18:09 jacogr

Ok, so I think you are saying the Polkadot browser extension and the extension-dapp package need to be running a version with the fix for unsubs to work? (I believe greater than 0.44.2). I'm actually using a different wallet extension but it likely hadn't been update to the latest extension-dapp yet either. Can you clarify if my understanding is corect?

F-OBrien avatar Sep 19 '22 18:09 F-OBrien

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

polkadot-js-bot avatar Oct 10 '22 20:10 polkadot-js-bot

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

polkadot-js-bot avatar Oct 24 '22 23:10 polkadot-js-bot