@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
38 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRequestUserApprovalImplementation = void 0;
const effects_1 = require("redux-saga/effects");
const store_1 = require("../../store/index.cjs");
/**
* Show a dialog to the user. This will wait for `resolveUserInterface` to be
* dispatched before returning.
*
* @param opts - The options for the request.
* @param opts.type - The type of dialog to show.
* @param opts.requestData - The data to display in the dialog.
* @param opts.requestData.id - The ID of the interface.
* @yields Sets the dialog in the store, waits for the user to resolve the
* dialog, and closes the dialog.
* @returns The result of the dialog.
*/
function* requestUserApprovalImplementation({ type, requestData: { id }, }) {
yield (0, effects_1.put)((0, store_1.setInterface)({ type, id }));
// We use `take` to wait for `resolveUserInterface` to be dispatched, which
// indicates that the user has resolved the dialog.
const { payload } = yield (0, effects_1.take)(store_1.resolveInterface.type);
yield (0, effects_1.put)((0, store_1.closeInterface)());
return payload;
}
/**
* Get the implementation of the `requestUserApproval` hook.
*
* @param runSaga - The function to run a saga outside the usual Redux flow.
* @returns The implementation of the `requestUserApproval` hook.
*/
function getRequestUserApprovalImplementation(runSaga) {
return async (...args) => {
return await runSaga(requestUserApprovalImplementation, ...args).toPromise();
};
}
exports.getRequestUserApprovalImplementation = getRequestUserApprovalImplementation;
//# sourceMappingURL=request-user-approval.cjs.map