UNPKG

@metamask/snaps-simulation

Version:

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

35 lines 1.17 kB
import $reduxjstoolkit from "@reduxjs/toolkit"; const { createSelector, createSlice } = $reduxjstoolkit; /** * The initial notifications state. */ const INITIAL_STATE = { jsonRpc: {}, }; export const mocksSlice = createSlice({ name: 'mocks', initialState: INITIAL_STATE, reducers: { addJsonRpcMock: (state, action) => { // @ts-expect-error - TS2589: Type instantiation is excessively deep and // possibly infinite. state.jsonRpc[action.payload.method] = action.payload.result; }, removeJsonRpcMock: (state, action) => { delete state.jsonRpc[action.payload]; }, }, }); export const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions; /** * Get the JSON-RPC mocks from the state. * * @param state - The application state. * @returns The JSON-RPC mocks. */ export const getJsonRpcMocks = (state) => state.mocks.jsonRpc; /** * Get the JSON-RPC mock for a given method from the state. */ export const getJsonRpcMock = createSelector(getJsonRpcMocks, (_, method) => method, (jsonRpcMocks, method) => jsonRpcMocks[method]); //# sourceMappingURL=mocks.mjs.map