vue-dapp icon indicating copy to clipboard operation
vue-dapp copied to clipboard

disconnect() doesn't fire in sample code

Open str11ngfello opened this issue 2 years ago • 2 comments

disconnect from useWallet doesn't fire in my app. I reproduced this in the sample code just now.

To repro:

  1. Download latest
  2. yarn && yarn dev
  3. connect to metamask
  4. press blue disconnect button observe no console.log that says 'disconnect'

However, changing network does fire the change event.

Metamask is still connected after pressing disconnect. (which I figured it would be since the callback didn't fire)

https://user-images.githubusercontent.com/877000/176020803-1bb9f9e2-3875-4157-9b56-1ded2ed76c60.mov

str11ngfello avatar Jun 27 '22 19:06 str11ngfello

This may is not suppose to happen, You simply disconnecting your page from the Metamask, but not Metamask from your domain. Don't get confused here.

re2005 avatar Jun 28 '22 13:06 re2005

MetaMask's disconnect event would be triggered when some chain changed, like Polygon or Arbitrum. So I excluded the disconnect function when using MetaMask.

https://github.com/chnejohnson/vue-dapp/blob/650b021d3834fece88309b63781a2fe6369fda23/src/composables/useWallet.ts#L89-L99

Besides, MetaMask doesn't support programmatic disconnect, see https://github.com/MetaMask/metamask-extension/issues/10353

https://github.com/chnejohnson/vue-dapp/blob/4df55dbef7623db411992c8d2c31846242c9233e/src/wallets/metaMask.ts#L114-L132

johnson86tw avatar Jul 07 '22 15:07 johnson86tw

I also run into the problem that when i call disconnet, isActivated seem to be false.But when i refresh the page,i still got my wallet address. Also I just checkout websites like opensea and uniswap, when i hit disconnect button, I DO disconnect my wallet from the website. I wonder what you mean by "MetaMask doesn't support programmatic disconnect"?

frankye23 avatar Dec 14 '22 09:12 frankye23

@frankye23 did you setup the autoConnect to true ?

Metamask either can remove a connected website, or lock itself. both can't be done from an external app, like VueDapp.

@chnejohnson I think other libs are storing a flag on localStorage something like autoConnect false.

re2005 avatar Dec 14 '22 10:12 re2005

I wonder what you mean by "MetaMask doesn't support programmatic disconnect"?

@frankye23 I mean the Connected status on MetaMask. If you have been connected, it would keep connected even if the web app seems disconnected.

截圖 2022-12-14 下午7 25 11

@re2005 So if the user has clicked the disconnect button, it should not trigger auto connect when he refreshed the window, right?

johnson86tw avatar Dec 14 '22 11:12 johnson86tw

Yes, @chnejohnson I'm wondering if this is accepted/expected behaviour? What do you think ?

On Uniswap, even when you have disconnected, after refresh the page it still connects automatically. So maybe we should not worry about it for now. But is something to think about. If an user deliberately, click to disconnect we could save that and even if the app has the autoConnect set to true, we would ignore it.

Cheers

re2005 avatar Dec 14 '22 13:12 re2005

Cool, maybe we can add an option for users to control this feature?

Hmm, but I tested on Uniswap, when I have disconnected, it doesn't connect automatically after I refreshed the page 🤔

https://user-images.githubusercontent.com/31992185/207753304-05e2a38a-172f-48e2-9194-31e9d3bd6ef8.mov

johnson86tw avatar Dec 15 '22 01:12 johnson86tw

did you setup the autoConnect to true ?

Yes, i did. The reason is that i want to stay connected when i refresh my pages .But i also would like it stay disconnected after i click disconnect and refresh my page.

frankye23 avatar Dec 15 '22 06:12 frankye23

@chnejohnson Maybe we can introduce this new flag, persistDisconnect and if that is true, we store on localStorage to not autoConnect after refresh.

Looking to Uniswap, look at this:

https://user-images.githubusercontent.com/2920357/207850265-685681b3-151a-43b9-b610-61a1ce06f74a.mov

Connected and after refresh, connected again :\

re2005 avatar Dec 15 '22 11:12 re2005

Maybe we can introduce this new flag, persistDisconnect and if that is true, we store on localStorage to not autoConnect after refresh.

Nice!

Connected and after refresh, connected again :\

I found the problem, you can't reload the page too quickly, wait a second then refresh 😆

i want to stay connected when i refresh my pages .But i also would like it stay disconnected after i click disconnect and refresh my page.

I think this is more reasonable than the existing implementation, maybe we should setup persistDisconnect default to true if the user setup the autoConnect to true?

johnson86tw avatar Dec 15 '22 15:12 johnson86tw

I think this is more reasonable than the existing implementation, maybe we should setup persistDisconnect default to true if the user setup the autoConnect to true?

Agreed! I believe to be a concise behaviour.

We should also document it.

Thanks @chnejohnson

re2005 avatar Dec 16 '22 17:12 re2005

Fixed in v0.6.3

johnson86tw avatar Dec 22 '22 10:12 johnson86tw