1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 14:15:06 +01:00
metamask-extension/ui/components/app/permissions-connect-permission-list/permissions-connect-permission-list.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { getWeightedPermissions } from '../../../helpers/utils/permission';
import { useI18nContext } from '../../../hooks/useI18nContext';
/**
* Get one or more permission descriptions for a permission name.
*
* @param permission - The permission to render.
* @param permission.label - The text label.
* @param permission.leftIcon - The left icon.
* @param permission.rightIcon - The right icon.
* @param permission.permissionName - The name of the permission.
* @param index - The index of the permission in the permissions array.
* @returns {JSX.Element[]} An array of permission description nodes.
*/
function getDescriptionNode(
{ label, leftIcon, rightIcon, permissionName },
index,
) {
return (
<div className="permission" key={`${permissionName}-${index}`}>
{typeof leftIcon === 'string' ? <i className={leftIcon} /> : leftIcon}
{label}
{rightIcon && <i className={rightIcon} />}
</div>
);
}
export default function PermissionsConnectPermissionList({ permissions }) {
const t = useI18nContext();
return (
<div className="permissions-connect-permission-list">
{getWeightedPermissions(t, permissions).map(getDescriptionNode)}
</div>
);
}
PermissionsConnectPermissionList.propTypes = {
permissions: PropTypes.object.isRequired,
};