@@ -30,7 +30,7 @@ import type {
3030} from '@metamask/snaps-sdk' ;
3131import type { FetchedSnapFiles , Snap } from '@metamask/snaps-utils' ;
3232import { logError } from '@metamask/snaps-utils' ;
33- import type { CaipAssetType , Json } from '@metamask/utils' ;
33+ import type { CaipAssetType , Hex , Json } from '@metamask/utils' ;
3434import type { Duplex } from 'readable-stream' ;
3535import { pipeline } from 'readable-stream' ;
3636import type { SagaIterator } from 'redux-saga' ;
@@ -54,6 +54,7 @@ import {
5454 getTrackErrorImplementation ,
5555 getEndTraceImplementation ,
5656 getStartTraceImplementation ,
57+ getSetCurrentChainImplementation ,
5758} from './methods/hooks' ;
5859import { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed' ;
5960import { createJsonRpcEngine } from './middleware' ;
@@ -155,6 +156,13 @@ export type RestrictedMiddlewareHooks = {
155156 * @returns The metadata for the given Snap.
156157 */
157158 getSnap : ( snapId : string ) => Snap ;
159+
160+ /**
161+ * A hook that sets the current chain ID.
162+ *
163+ * @param chainId - The chain ID.
164+ */
165+ setCurrentChain : ( chainId : Hex ) => Promise < void > ;
158166} ;
159167
160168export type PermittedMiddlewareHooks = {
@@ -373,7 +381,7 @@ export async function installSnap<
373381 registerActions ( controllerMessenger , runSaga , options , snapId ) ;
374382
375383 // Set up controllers and JSON-RPC stack.
376- const restrictedHooks = getRestrictedHooks ( options ) ;
384+ const restrictedHooks = getRestrictedHooks ( options , runSaga ) ;
377385 const permittedHooks = getPermittedHooks (
378386 snapId ,
379387 snapFiles ,
@@ -457,10 +465,12 @@ export async function installSnap<
457465 * Get the hooks for the simulation.
458466 *
459467 * @param options - The simulation options.
468+ * @param runSaga - The run saga function.
460469 * @returns The hooks for the simulation.
461470 */
462471export function getRestrictedHooks (
463472 options : SimulationOptions ,
473+ runSaga : RunSagaFunction ,
464474) : RestrictedMiddlewareHooks {
465475 return {
466476 getMnemonic : getGetMnemonicImplementation ( options . secretRecoveryPhrase ) ,
@@ -470,6 +480,7 @@ export function getRestrictedHooks(
470480 getIsLocked : ( ) => false ,
471481 getClientCryptography : ( ) => ( { } ) ,
472482 getSnap : getGetSnapImplementation ( true ) ,
483+ setCurrentChain : getSetCurrentChainImplementation ( runSaga ) ,
473484 } ;
474485}
475486
0 commit comments