keplr-wallet icon indicating copy to clipboard operation
keplr-wallet copied to clipboard

emit event on chain change

Open pastaghost opened this issue 2 years ago • 1 comments

When the user switches the network from the extension menu, the webpage might need to be made aware of the currently selected chain. With the changes introduced in this PR, Keplr emits a keplr_chainchange event to the webpage's window each time the user selects a new chain from the extension. You can request the currently selected chain based on this event listener.

window.addEventListener("keplr_chainchange", (e) => {
    console.log("Keplr chain updated. Currently selected chainId:", (e as CustomEvent).detail);
});

pastaghost avatar May 25 '22 06:05 pastaghost

Even though we do have this function, with the website turned off, there’s no way of receiving events so it needs to be done in the way of using a method like enable() and returning the currently selected chain id regardless of the chain id event that is happening in the website.

However, regardless of the actual methodology of implementation, I am negative about the direction of this feature itself. This direction is more similar to the direction of Metamask. Keplr is a multi-chain wallet and its APIs are made to serve multiple chains at once. I’m also hoping that the websites are built in this direction and concept as well

Thunnini avatar May 25 '22 10:05 Thunnini