1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/components/app/connected-sites-list/connected-sites-list.component.js
2021-04-28 14:53:59 -05:00

65 lines
1.8 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SiteIcon from '../../ui/site-icon';
import { stripHttpSchemes } from '../../../helpers/utils/util';
export default class ConnectedSitesList extends Component {
static contextTypes = {
t: PropTypes.func,
};
static propTypes = {
connectedDomains: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
icon: PropTypes.string,
origin: PropTypes.string,
host: PropTypes.string,
}),
).isRequired,
onDisconnect: PropTypes.func.isRequired,
domainHostCount: PropTypes.objectOf(PropTypes.number).isRequired,
};
render() {
const { connectedDomains, onDisconnect } = this.props;
const { t } = this.context;
return (
<main className="connected-sites-list__content-rows">
{connectedDomains.map((domain) => (
<div
key={domain.origin}
className="connected-sites-list__content-row"
>
<div className="connected-sites-list__domain-info">
<SiteIcon icon={domain.icon} name={domain.name} size={32} />
<span
className="connected-sites-list__domain-name"
title={domain.extensionId || domain.origin}
>
{this.getDomainDisplayName(domain)}
</span>
</div>
<i
className="fas fa-trash-alt connected-sites-list__trash"
title={t('disconnect')}
onClick={() => onDisconnect(domain.origin)}
/>
</div>
))}
</main>
);
}
getDomainDisplayName(domain) {
if (domain.extensionId) {
return this.context.t('externalExtension');
}
return this.props.domainHostCount[domain.host] > 1
? domain.origin
: stripHttpSchemes(domain.origin);
}
}