mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-12 04:37:13 +01:00
025ee2cb48
* Expose transaction origin to transaction insight snaps * Support multiple icons for each label for a permission * Add transaction insight origin permission * Fix fencing * Fix import and permission crash * Use function properly for connected accounts
49 lines
1.4 KiB
JavaScript
49 lines
1.4 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 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,
|
|
};
|