1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/ui/components/app/permissions-connect-permission-list/permissions-connect-permission-list.js
Frederik Bolding 025ee2cb48
[FLASK] Expose transaction origin to transaction insight snaps (#16671)
* 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
2022-12-01 14:38:56 +01:00

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,
};