unisat-wallet / extension

The first open-source browser extension wallet for Bitcoin NFTs
Other
874 stars 336 forks source link

"networkChanged" event not working? #211

Closed gndelia closed 3 months ago

gndelia commented 4 months ago

In my app, I listen for both accountsChanged and networkChanged events.

I do so by running

window.unisat.on('accountsChanged', handler)
window.unisat.on('networkChanged', handler)

While both used to work, today I noticed that networkChanged event isn't fired. Has something changed? My code detects when accounts have changed, but networkChanged does not fire the handler (ever)

slient-coder commented 3 months ago

Please use chainChanged event. window.unisat.on('chainChanged', handler)

Due to our support for more networks, such as fractal(mainnet), testnet4(testnet), and signet(testnet), a new method is required to properly identify the current chain.

We will fix the networkChanged event shortly, but it is not recommended to use.

gndelia commented 3 months ago

Thanks for your response, I will check it - however I don't see that event listed in the docs

gndelia commented 3 months ago

I tried with window.unisat.on('chainChanged', handler) and it worked. Thanks @huanniangstudio !