Skip to content

Commit

Permalink
Add snap_getLocale support
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Aug 23, 2023
1 parent d43c1de commit 12a7abf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,17 @@ export default class MetamaskController extends EventEmitter {
return this.controllerMessenger.call('SnapController:handleRequest', args);
}

/**
* Gets the currently selected locale from the PreferencesController.
*
* @returns The currently selected locale.
*/
getLocale() {
const { currentLocale } = this.preferencesController.store.getState();

return currentLocale;
}

/**
* Constructor helper for getting Snap permission specifications.
*/
Expand All @@ -1883,6 +1894,7 @@ export default class MetamaskController extends EventEmitter {
...buildSnapRestrictedMethodSpecifications({
encrypt,
decrypt,
getLocale: this.getLocale.bind(this),
clearSnapState: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapController:clearSnapState',
Expand Down
1 change: 1 addition & 0 deletions shared/constants/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const RestrictedMethods = Object.freeze({
snap_getBip32Entropy: 'snap_getBip32Entropy',
snap_getBip44Entropy: 'snap_getBip44Entropy',
snap_getEntropy: 'snap_getEntropy',
snap_getLocale: 'snap_getLocale',
wallet_snap: 'wallet_snap',
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps)
Expand Down
1 change: 1 addition & 0 deletions shared/constants/snaps/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const EndowmentPermissions = Object.freeze({
export const ExcludedSnapPermissions = Object.freeze({
// TODO: Enable in Flask
///: BEGIN:ONLY_INCLUDE_IN(build-main)
snap_getLocale: 'This permission is still in development and therefore not available.',
snap_manageAccounts:
'This permission is still in development and therefore not available.',
///: END:ONLY_INCLUDE_IN
Expand Down
7 changes: 7 additions & 0 deletions ui/helpers/utils/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ export const PERMISSION_DESCRIPTIONS = deepFreeze({
leftIcon: IconName.AddSquare,
weight: 3,
}),
[RestrictedMethods.snap_getLocale]: ({ t }) => ({
// TODO
label: 'Get Locale',
description: 'foo',
leftIcon: IconName.Messages,
weight: 3,
}),
[RestrictedMethods.wallet_snap]: ({
t,
permissionValue,
Expand Down

0 comments on commit 12a7abf

Please sign in to comment.