1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/components/app/permissions-connect-permission-list/permissions-connect-permission-list.js
Maarten Zuidhoorn a52c6a4908
[FLASK] snaps-skunkworks@0.19.0 (#15619)
* Bump snaps-skunkworks to 0.19.0

* Improve snap_getBip32Entropy UI

* Remove console.log

* Update LavaMoat policy

* Dedupe Yarn lock

* Update LavaMoat policy again

* Fix tests

* Update policies and e2e tests

* Update policy again

* Update iframe-execution-environment

* Dedupe yarn.lock

* Update snapshots

* Fix PR comments

* Add TODO

* Trigger CI
2022-08-18 17:07:34 +02:00

59 lines
1.7 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { getPermissionDescription } from '../../../helpers/utils/permission';
import { useI18nContext } from '../../../hooks/useI18nContext';
/**
* Get one or more permission descriptions for a permission name.
*
* @param t - The translation function.
* @param permissionName - The name of the permission to request.
* @param permissionValue - The value of the permission to request.
* @returns {JSX.Element[]} An array of permission description nodes.
*/
function getDescriptionNodes(t, permissionName, permissionValue) {
const { label, leftIcon, rightIcon } = getPermissionDescription(
t,
permissionName,
permissionValue,
);
if (Array.isArray(label)) {
return label.map((labelValue, index) => (
<div className="permission" key={`${permissionName}-${index}`}>
<i className={leftIcon} />
{labelValue}
{rightIcon && <i className={rightIcon} />}
</div>
));
}
return [
<div className="permission" key={permissionName}>
<i className={leftIcon} />
{label}
{rightIcon && <i className={rightIcon} />}
</div>,
];
}
export default function PermissionsConnectPermissionList({ permissions }) {
const t = useI18nContext();
return (
<div className="permissions-connect-permission-list">
{Object.entries(permissions).reduce(
(target, [permissionName, permissionValue]) =>
target.concat(
getDescriptionNodes(t, permissionName, permissionValue),
),
[],
)}
</div>
);
}
PermissionsConnectPermissionList.propTypes = {
permissions: PropTypes.object.isRequired,
};