import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import PermissionsConnectHeader from '../../permissions-connect-header';
import Tooltip from '../../../ui/tooltip';
import PermissionsConnectPermissionList from '../../permissions-connect-permission-list';
export default class PermissionPageContainerContent extends PureComponent {
static propTypes = {
domainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
selectedPermissions: PropTypes.object.isRequired,
selectedIdentities: PropTypes.array,
allIdentitiesSelected: PropTypes.bool,
};
static defaultProps = {
selectedIdentities: [],
allIdentitiesSelected: false,
};
static contextTypes = {
t: PropTypes.func,
};
renderRequestedPermissions() {
const { selectedPermissions } = this.props;
return (
);
}
renderAccountTooltip(textContent) {
const { selectedIdentities } = this.props;
const { t } = this.context;
return (
{selectedIdentities.slice(0, 6).map((identity, index) => {
return (
{identity.addressLabel}
);
})}
{selectedIdentities.length > 6
? t('plusXMore', [selectedIdentities.length - 6])
: null}
}
>
{textContent}
);
}
getTitle() {
const {
domainMetadata,
selectedIdentities,
allIdentitiesSelected,
} = this.props;
const { t } = this.context;
if (domainMetadata.extensionId) {
return t('externalExtension', [domainMetadata.extensionId]);
} else if (allIdentitiesSelected) {
return t('connectToAll', [
this.renderAccountTooltip(t('connectToAllAccounts')),
]);
} else if (selectedIdentities.length > 1) {
return t('connectToMultiple', [
this.renderAccountTooltip(
t('connectToMultipleNumberOfAccounts', [selectedIdentities.length]),
),
]);
}
return t('connectTo', [selectedIdentities[0]?.addressLabel]);
}
render() {
const { domainMetadata } = this.props;
const { t } = this.context;
const title = this.getTitle();
return (
{this.renderRequestedPermissions()}
);
}
}