mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
512fdcae56
* Replaced with new checkbox in ConnectedAccountsPermissions * removed a typo * fixed linting issue * Small updates to styles --------- Co-authored-by: George Marshall <george.marshall@consensys.net>
91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
import classnames from 'classnames';
|
|
import PropTypes from 'prop-types';
|
|
import React, { useState } from 'react';
|
|
import { flatten } from 'lodash';
|
|
import { Checkbox } from '../../component-library';
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import { getPermissionDescription } from '../../../helpers/utils/permission';
|
|
|
|
const ConnectedAccountsPermissions = ({ permissions }) => {
|
|
const t = useI18nContext();
|
|
const [expanded, setExpanded] = useState(false);
|
|
|
|
const toggleExpanded = () => {
|
|
setExpanded((_expanded) => !_expanded);
|
|
};
|
|
|
|
if (!permissions.length) {
|
|
return null;
|
|
}
|
|
|
|
const permissionLabels = flatten(
|
|
permissions.map(({ key, value }) =>
|
|
getPermissionDescription({
|
|
t,
|
|
permissionName: key,
|
|
permissionValue: value,
|
|
}),
|
|
),
|
|
);
|
|
|
|
return (
|
|
<div className="connected-accounts-permissions">
|
|
<p
|
|
className="connected-accounts-permissions__header"
|
|
onClick={toggleExpanded}
|
|
>
|
|
<strong>{t('permissions')}</strong>
|
|
<button
|
|
className={classnames('fas', {
|
|
'fa-angle-down': !expanded,
|
|
'fa-angle-up': expanded,
|
|
})}
|
|
title={t('showPermissions')}
|
|
/>
|
|
</p>
|
|
<div
|
|
className={classnames(
|
|
'connected-accounts-permissions__list-container',
|
|
{
|
|
'connected-accounts-permissions__list-container--expanded':
|
|
expanded,
|
|
},
|
|
)}
|
|
>
|
|
<p>{t('authorizedPermissions')}:</p>
|
|
<ul className="connected-accounts-permissions__list">
|
|
{permissionLabels.map(({ label }, idx) => (
|
|
<li
|
|
key={`connected-permission-${idx}`}
|
|
className="connected-accounts-permissions__list-item"
|
|
>
|
|
<Checkbox
|
|
isChecked
|
|
isDisabled
|
|
id={`connected-permission-${idx}`}
|
|
label={label}
|
|
/>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
ConnectedAccountsPermissions.propTypes = {
|
|
permissions: PropTypes.arrayOf(
|
|
PropTypes.shape({
|
|
key: PropTypes.string.isRequired,
|
|
}),
|
|
),
|
|
};
|
|
|
|
ConnectedAccountsPermissions.defaultProps = {
|
|
permissions: [],
|
|
};
|
|
|
|
ConnectedAccountsPermissions.displayName = 'ConnectedAccountsPermissions';
|
|
|
|
export default React.memo(ConnectedAccountsPermissions);
|