@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
1 lines • 2.94 kB
Source Map (JSON)
{"version":3,"file":"store.cjs","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAkD;AAClD,4DAA8C;AAE9C,uCAAqC;AACrC,uDAAqD;AACrD,uCAA+C;AAC/C,iDAA+C;AAC/C,iCAA+B;AAG/B;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAqB;IACxE,MAAM,cAAc,GAAG,IAAA,oBAAoB,GAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAA,wBAAc,EAAC;QAC3B,OAAO,EAAE;YACP,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,aAAa,EAAE,kCAAkB,CAAC,OAAO;YACzC,KAAK,EAAE,kBAAU,CAAC,OAAO;YACzB,UAAU,EAAE,4BAAe,CAAC,OAAO;YACnC,EAAE,EAAE,YAAO,CAAC,OAAO;SACpB;QACD,UAAU,EAAE,CAAC,oBAAoB,EAAE,EAAE,CACnC,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;KAChE,CAAC,CAAC;IAEH,kCAAkC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,QAAQ,CACZ,IAAA,gBAAQ,EAAC;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,IAAA,gBAAQ,EAAC;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;AArCD,kCAqCC","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 }).concat(sagaMiddleware),\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"]}