UNPKG

@metamask/snaps-rpc-methods

Version:
47 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getImplementation = exports.getLocaleBuilder = exports.specificationBuilder = void 0; const permission_controller_1 = require("@metamask/permission-controller"); const methodName = 'snap_getLocale'; /** * The specification builder for the `snap_getLocale` permission. * `snap_getLocale` allows snaps to get the user selected locale. * * @param options - The specification builder options. * @param options.allowedCaveats - The optional allowed caveats for the permission. * @param options.methodHooks - The RPC method hooks needed by the method implementation. * @returns The specification for the `snap_getLocale` permission. * @deprecated - To be removed in favor of `snap_getPreferences`. */ const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => { return { permissionType: permission_controller_1.PermissionType.RestrictedMethod, targetName: methodName, allowedCaveats, methodImplementation: getImplementation(methodHooks), subjectTypes: [permission_controller_1.SubjectType.Snap], }; }; exports.specificationBuilder = specificationBuilder; const methodHooks = { getPreferences: true, }; exports.getLocaleBuilder = Object.freeze({ targetName: methodName, specificationBuilder: exports.specificationBuilder, methodHooks, }); /** * Builds the method implementation for `snap_getLocale`. * * @param hooks - The RPC method hooks. * @param hooks.getPreferences - A function that returns the user selected preferences. * @returns The user selected locale. */ function getImplementation({ getPreferences }) { return async function implementation(_args) { return getPreferences().locale; }; } exports.getImplementation = getImplementation; //# sourceMappingURL=getLocale.cjs.map