cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
183 stars 128 forks source link

fix useChain #361

Open Sen-Com opened 10 months ago

Sen-Com commented 10 months ago

useChain is not correctly picking up all events.

Consider

.... const {address} = useChain("cosmosHub") return

{address}
....

If I connect and change accounts, it works. If I then re-connect and change accounts it does not pick up any account changes, i.e. I change account and the address does not change.

The bug is also in production, i.e. Osmosis frontend. even forcefully refreshing the component a la

useEffect(() => () => setRefreshKey(refreshKey + 1), [chain, chainName])

is not working

Sen-Com commented 10 months ago

local storage items are also not correct updated (i.e. no change) on account change

Sen-Com commented 10 months ago

interestingly, useChainWallet does not suffer from the same issue and always picks up account changes correctly. That's a clear indication that the useChain hook is broken

liujun93 commented 10 months ago

@Sen-Com What did you do to cause re-connect? Usually Reconnect button shows up when you failed to connect, i.e. connection rejected by wallet. I tries this and reconnect, switch account still works. Is this not the re-connect you mentioned? can you list the exact steps so that we can reproduce the issue?

Sen-Com commented 10 months ago

I tried countless things to make this work and all lead to the same issue: the useChain hook is not registering account changes correctly.

  1. connect wallet
  2. switch account -> registered
  3. disconnect wallet
  4. connect wallet
  5. switch account -> not registered
liujun93 commented 9 months ago

I still cannot reproduce it. Are you using the latest version of CosmosKit?

Maybe you can also try these steps in our doc site. https://docs.cosmoskit.com/#try-it-out

I'm using Keplr extension to test and everything works fine.

Or, can you make a simple example repo to reproduce it?