1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/pages/permissions-connect/flask/util.js
Hassan Malik c2b2f2685e
[FLASK] Redesign key management modal (#18263)
* added the rest of the sev1 warnings to getSnapInstallWarnings

* added and updated translations

* Updated getSnapInstallWarnings to include warnings for all weight-1 permissions

* Updated snap install warning and css according to designs

* fix snaps tests

* fixed alignment/spacing

* updated e2e tests to click through the newly displayed public key access warning

* lint fix

* fixed update snap test

* refactored getSnapInstallWarnings, moved logic to PERMISSION_DESCRIPTIONS

* fix logic to account for objects & arrays

* update function description

* add missing properties to ethereum provider description

* moved id and message to baseDescription to fix error

* add optional chaining to fix undefined error

* more optional chaining

* more optional chaining
2023-03-29 15:17:57 -04:00

33 lines
1.0 KiB
JavaScript

import { isObject } from '@metamask/utils';
import { PERMISSION_DESCRIPTIONS } from '../../../helpers/utils/permission';
export function getSnapInstallWarnings(permissions, targetSubjectMetadata, t) {
const weightOneWarnings = Object.entries(permissions).reduce(
(filteredWarnings, [permissionName, permissionValue]) => {
const permissionDescription = PERMISSION_DESCRIPTIONS[permissionName]({
t,
permissionValue,
targetSubjectMetadata,
});
if (Array.isArray(permissionDescription)) {
permissionDescription.forEach((description) => {
if (description.weight === 1) {
const { id, message } = description;
filteredWarnings.push({ id, message });
}
});
} else if (
isObject(permissionDescription) &&
permissionDescription.weight === 1
) {
const { id, message } = permissionDescription;
filteredWarnings.push({ id, message });
}
return filteredWarnings;
},
[],
);
return weightOneWarnings;
}