@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
54 lines • 1.58 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getState = exports.clearState = exports.setState = exports.stateSlice = void 0;
const toolkit_1 = require("@reduxjs/toolkit");
/**
* The initial state.
*/
const INITIAL_STATE = {
encrypted: null,
unencrypted: null,
};
/**
* The state slice, which stores the state of the Snap.
*/
exports.stateSlice = (0, toolkit_1.createSlice)({
name: 'state',
initialState: INITIAL_STATE,
reducers: {
setState: (state, action) => {
if (action.payload.encrypted) {
state.encrypted = action.payload.state;
return state;
}
state.unencrypted = action.payload.state;
return state;
},
clearState: (state, action) => {
if (action.payload.encrypted) {
state.encrypted = null;
return state;
}
state.unencrypted = null;
return state;
},
},
});
_a = exports.stateSlice.actions, exports.setState = _a.setState, exports.clearState = _a.clearState;
/**
* Get the state from the store.
*
* @param encrypted - Whether to get the encrypted or unencrypted state.
* @returns A selector that returns the state.
*/
function getState(encrypted) {
return (0, toolkit_1.createSelector)((state) => state, ({ state }) => {
if (encrypted) {
return state.encrypted;
}
return state.unencrypted;
});
}
exports.getState = getState;
//# sourceMappingURL=state.cjs.map