UNPKG

@metamask/snaps-simulation

Version:

A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment

47 lines 1.63 kB
import $reduxjstoolkit from "@reduxjs/toolkit"; const { configureStore } = $reduxjstoolkit; import createSagaMiddleware from "redux-saga"; import { mocksSlice } from "./mocks.mjs"; import { notificationsSlice } from "./notifications.mjs"; import { setState, stateSlice } from "./state.mjs"; import { trackablesSlice } from "./trackables.mjs"; import { uiSlice } from "./ui.mjs"; /** * Create a Redux store. * * @param options - The simulation options. * @param options.state - The initial state for the Snap. * @param options.unencryptedState - The initial unencrypted state for the Snap. * @returns A Redux store with the default state. */ export function createStore({ state, unencryptedState }) { const sagaMiddleware = createSagaMiddleware(); const store = configureStore({ reducer: { mocks: mocksSlice.reducer, notifications: notificationsSlice.reducer, state: stateSlice.reducer, trackables: trackablesSlice.reducer, ui: uiSlice.reducer, }, middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware), }); // Set initial state for the Snap. if (state) { store.dispatch(setState({ state: JSON.stringify(state), encrypted: true, })); } if (unencryptedState) { store.dispatch(setState({ state: JSON.stringify(unencryptedState), encrypted: false, })); } return { store, runSaga: sagaMiddleware.run.bind(sagaMiddleware), }; } //# sourceMappingURL=store.mjs.map