1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/components/app/connected-accounts-permissions/connected-accounts-permissions.component.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

import classnames from 'classnames';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import CheckBox from '../../ui/check-box';
2020-05-15 20:53:52 +02:00
export default class ConnectedAccountsPermissions extends PureComponent {
2020-05-15 20:53:52 +02:00
static contextTypes = {
t: PropTypes.func.isRequired,
};
2020-05-15 20:53:52 +02:00
static defaultProps = {
permissions: [],
};
2020-05-15 20:53:52 +02:00
static propTypes = {
2020-11-03 00:41:28 +01:00
permissions: PropTypes.arrayOf(
PropTypes.shape({
key: PropTypes.string.isRequired,
}),
),
};
2020-05-15 20:53:52 +02:00
state = {
expanded: false,
};
2020-05-15 20:53:52 +02:00
toggleExpanded = () => {
this.setState((prevState) => ({
expanded: !prevState.expanded,
}));
};
2020-05-15 20:53:52 +02:00
2020-11-03 00:41:28 +01:00
render() {
const { permissions } = this.props;
const { t } = this.context;
const { expanded } = this.state;
2020-05-15 20:53:52 +02:00
if (permissions.length === 0) {
return null;
2020-05-15 20:53:52 +02:00
}
return (
<div className="connected-accounts-permissions">
2020-11-03 00:41:28 +01:00
<p
className="connected-accounts-permissions__header"
onClick={this.toggleExpanded}
>
2020-05-15 20:53:52 +02:00
<strong>{t('permissions')}</strong>
<button
className={classnames('fas', {
'fa-angle-down': !expanded,
'fa-angle-up': expanded,
})}
title={t('showPermissions')}
/>
</p>
2020-05-20 22:42:18 +02:00
<div
2020-11-03 00:41:28 +01:00
className={classnames(
'connected-accounts-permissions__list-container',
{
'connected-accounts-permissions__list-container--expanded': expanded,
},
)}
2020-05-20 22:42:18 +02:00
>
<p>{t('authorizedPermissions')}:</p>
<ul className="connected-accounts-permissions__list">
{permissions.map(({ key: permissionName }) => (
2020-11-03 00:41:28 +01:00
<li
key={permissionName}
className="connected-accounts-permissions__list-item"
>
<CheckBox
checked
disabled
id={permissionName}
className="connected-accounts-permissions__checkbox"
/>
<label htmlFor={permissionName}>{t(permissionName)}</label>
2020-05-20 22:42:18 +02:00
</li>
))}
</ul>
</div>
2020-05-15 20:53:52 +02:00
</div>
);
2020-05-15 20:53:52 +02:00
}
}