UNPKG

@metamask/snaps-simulation

Version:

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

34 lines 1.45 kB
import { put, take } from "redux-saga/effects"; import { resolveInterface, setInterface, closeInterface } from "../../store/index.mjs"; /** * 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 put(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 take(resolveInterface.type); yield put(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. */ export function getRequestUserApprovalImplementation(runSaga) { return async (...args) => { return await runSaga(requestUserApprovalImplementation, ...args).toPromise(); }; } //# sourceMappingURL=request-user-approval.mjs.map