{"version":3,"file":"switch-ethereum-chain.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/switch-ethereum-chain.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EAIP,wBAAwB;AAMzB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAuB,EACvB,QAAgC,EAChC,KAAgC,EAChC,GAA6B,EAC7B,KAA+B;IAE/B,MAAM,WAAW,GAAG,OAA6C,CAAC;IAElE,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;IAChE,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAErD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n  JsonRpcEngineEndCallback,\n  JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport {\n  assert,\n  type Hex,\n  type JsonRpcRequest,\n  type PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type SwitchEthereumChainHooks = {\n  setCurrentChain: (chain: Hex) => null;\n};\n\n/**\n * A mock handler for the `wallet_switchEthereumChain` method that always\n * returns `null`.\n *\n * @param request - Incoming JSON-RPC request.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @param hooks - The method hooks.\n * @returns The response.\n */\nexport async function getSwitchEthereumChainHandler(\n  request: JsonRpcRequest,\n  response: PendingJsonRpcResponse,\n  _next: JsonRpcEngineNextCallback,\n  end: JsonRpcEngineEndCallback,\n  hooks: SwitchEthereumChainHooks,\n) {\n  const castRequest = request as JsonRpcRequest<[{ chainId: Hex }]>;\n\n  assert(castRequest.params?.[0]?.chainId, 'No chain ID passed.');\n  hooks.setCurrentChain(castRequest.params[0].chainId);\n\n  response.result = null;\n  return end();\n}\n"]}