keplr-wallet
keplr-wallet copied to clipboard
emit event on chain change
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);
});
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