@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
53 lines • 1.91 kB
JavaScript
import { PermissionType, SubjectType } from "@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`.
*/
export const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
return {
permissionType: PermissionType.RestrictedMethod,
targetName: methodName,
allowedCaveats,
methodImplementation: getImplementation(methodHooks),
subjectTypes: [SubjectType.Snap],
};
};
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
*/
export const getLocaleBuilder = Object.freeze({
targetName: methodName,
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.
*/
export function getImplementation({ getPreferences }) {
return async function implementation(_args) {
return getPreferences().locale;
};
}
//# sourceMappingURL=getLocale.mjs.map