import { logger as c } from "../../logger.js";
class n extends Error {
  constructor(t) {
    super(t), this.name = "SwitchChainError";
  }
}
const i = async (e, t) => {
  try {
    const r = await t.request({
      method: "eth_chainId"
    }), o = parseInt(r, 16);
    if (o === e)
      return;
    await t.request({
      method: "wallet_switchEthereumChain",
      params: [{ chainId: `0x${e.toString(16)}` }]
    }), c.debug(
      `Successfully switched chain from ${o} to ${e}`
    );
  } catch (r) {
    throw r && typeof r == "object" && "code" in r && r.code === 4902 ? new n(`Chain ${e} is not available.`) : (c.error(r), new n(
      `Please switch to the correct network (Chain ID: ${e}) in your wallet`
    ));
  }
};
export {
  i as switchEthereumChain
};
//# sourceMappingURL=switchEthereumChain.js.map
