cowprotocol / cowswap

šŸ® CowSwap: First CoW Protocol UI
https://swap.cow.fi/
GNU General Public License v3.0
116 stars 85 forks source link

[widget] disconnect event broken #3892

Closed anxolin closed 5 months ago

anxolin commented 6 months ago

Description When we disconnect the widget in https://widget.cow.fi , it breaks:

image

We emit correctly the events: disconnect and close (this last one is deprecated EIP-1193 event)

However, something is not good in the handling: https://github.com/cowprotocol/cowswap/blob/release/2024.02.14/libs/wallet/src/web3-react/connectors/Injected/index.tsx#L156

Irrelevant info but I wanted to get it out of my chest

I thought I broke it in my big refactor of the communications, specially because I redid the part of the RPC and subscriptions to provider communications: https://github.com/cowprotocol/cowswap/pull/3871

I was sure it was my PR, and I would swear it was working before my change, but I saw later that is also broken even in production. I spent debugging what of my changes broke it for quite a lot! šŸ˜­

EDIT: I think i know what is happening!

I think i know what is happening and why I thought that I had broken it

I thought it was not "disconnecting' but it was! but after disconnecting, it was automatically connected to the injected wallet, and because i had given permission to the the original web (in this case localhost:3000), it was showing me an account inside the app even though I disconnected

So the issue is, we should make sure we don't use the injected wallet in the widget if the host dapp is handling the connection.

anxolin commented 6 months ago

Putting this one on hold, as I would hope we stop using web3-react soon, which contains a super strange autoconnect logic.

I believe once we do #3987 , this problem will be probably fixed