@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
58 lines • 2.24 kB
JavaScript
;
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,
};
/**
* Get the user's locale setting. You can use this method to localize text in
* your Snap.
*
* Note that this method is deprecated. We recommend using
* [`snap_getPreferences`](https://docs.metamask.io/snaps/reference/snaps-api/snap_getpreferences)
* instead, which provides access to the user's locale as well as other
* preferences.
*
* @internal
*/
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