1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/components/app/permissions-connect-permission-list/permissions-connect-permission-list.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

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 permissions = getPermissionDescription(
t,
permissionName,
permissionValue,
);
return permissions.map(({ label, leftIcon, rightIcon }, index) => (
<div className="permission" key={`${permissionName}-${index}`}>
<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,
};