vue-dapp
vue-dapp copied to clipboard
disconnect() doesn't fire in sample code
disconnect from useWallet doesn't fire in my app. I reproduced this in the sample code just now.
To repro:
- Download latest
- yarn && yarn dev
- connect to metamask
- 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
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.
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
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 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.
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.
@re2005 So if the user has clicked the disconnect button, it should not trigger auto connect when he refreshed the window, right?
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
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
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.
@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 :\
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?
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
Fixed in v0.6.3