@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
1 lines • 3.07 kB
Source Map (JSON)
{"version":3,"file":"store.mjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;AACA,OAAO,oBAAoB,mBAAmB;AAE9C,OAAO,EAAE,UAAU,EAAE,oBAAgB;AACrC,OAAO,EAAE,kBAAkB,EAAE,4BAAwB;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAgB;AAC/C,OAAO,EAAE,eAAe,EAAE,yBAAqB;AAC/C,OAAO,EAAE,OAAO,EAAE,iBAAa;AAG/B;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,cAAc,CAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kBAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,UAAU,CAAC,OAAO;YACzB,UAAU,EAAE,eAAe,CAAC,OAAO;YACnC,EAAE,EAAE,OAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CACrE,cAAc,CACf;KACJ,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,CAAC,QAAQ,CACZ,QAAQ,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;YACvC,SAAS,EAAE,KAAK;SACjB,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK;QACL,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { trackablesSlice } from './trackables';\nimport { uiSlice } from './ui';\nimport type { SimulationOptions } from '../options';\n\n/**\n * Create a Redux store.\n *\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore({ state, unencryptedState }: SimulationOptions) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n trackables: trackablesSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false, serializableCheck: false }).concat(\n sagaMiddleware,\n ),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify(state),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"]}