@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
50 lines • 1.38 kB
JavaScript
import $reduxjstoolkit from "@reduxjs/toolkit";
const { createSelector, createSlice } = $reduxjstoolkit;
/**
* The initial state.
*/
const INITIAL_STATE = {
encrypted: null,
unencrypted: null,
};
/**
* The state slice, which stores the state of the Snap.
*/
export const stateSlice = 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;
},
},
});
export const { setState, clearState } = stateSlice.actions;
/**
* Get the state from the store.
*
* @param encrypted - Whether to get the encrypted or unencrypted state.
* @returns A selector that returns the state.
*/
export function getState(encrypted) {
return createSelector((state) => state, ({ state }) => {
if (encrypted) {
return state.encrypted;
}
return state.unencrypted;
});
}
//# sourceMappingURL=state.mjs.map