2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-01-04 23:05:29 +01:00
|
|
|
import Icon from 'component/icon';
|
2017-12-21 22:08:54 +01:00
|
|
|
import Link from 'component/link';
|
|
|
|
import lbryuri from 'lbryuri';
|
|
|
|
import classnames from 'classnames';
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class UriIndicator extends React.PureComponent {
|
2017-05-21 16:42:34 +02:00
|
|
|
componentWillMount() {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.resolve(this.props);
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-06-06 23:19:12 +02:00
|
|
|
this.resolve(nextProps);
|
2017-05-10 05:06:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
resolve(props) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { isResolvingUri, resolveUri, claim, uri } = props;
|
2017-05-10 05:06:48 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
if (!isResolvingUri && claim === undefined && uri) {
|
|
|
|
resolveUri(uri);
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
2017-05-02 07:25:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
render() {
|
2017-12-14 22:12:04 +01:00
|
|
|
const { claim, link, uri, isResolvingUri, smallCard, span } = this.props;
|
2017-05-21 16:42:34 +02:00
|
|
|
|
2017-06-16 04:48:55 +02:00
|
|
|
if (isResolvingUri && !claim) {
|
2017-06-06 23:19:12 +02:00
|
|
|
return <span className="empty">Validating...</span>;
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!claim) {
|
2017-06-06 23:19:12 +02:00
|
|
|
return <span className="empty">Unused</span>;
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
const {
|
|
|
|
channel_name: channelName,
|
|
|
|
has_signature: hasSignature,
|
|
|
|
signature_is_valid: signatureIsValid,
|
2017-09-17 22:33:52 +02:00
|
|
|
value,
|
2017-06-06 23:19:12 +02:00
|
|
|
} = claim;
|
2017-09-17 22:33:52 +02:00
|
|
|
const channelClaimId =
|
2017-12-21 22:08:54 +01:00
|
|
|
value && value.publisherSignature && value.publisherSignature.certificateId;
|
2017-05-21 16:42:34 +02:00
|
|
|
|
|
|
|
if (!hasSignature || !channelName) {
|
|
|
|
return <span className="empty">Anonymous</span>;
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:33:52 +02:00
|
|
|
let icon, channelLink, modifier;
|
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
if (signatureIsValid) {
|
2017-12-21 22:08:54 +01:00
|
|
|
modifier = 'valid';
|
|
|
|
channelLink = link ? lbryuri.build({ channelName, claimId: channelClaimId }, false) : false;
|
2017-05-21 16:42:34 +02:00
|
|
|
} else {
|
2017-12-21 22:08:54 +01:00
|
|
|
icon = 'icon-times-circle';
|
|
|
|
modifier = 'invalid';
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
|
|
|
|
2017-09-17 22:33:52 +02:00
|
|
|
const inner = (
|
2017-05-21 16:42:34 +02:00
|
|
|
<span>
|
2017-12-05 20:34:32 +01:00
|
|
|
<span
|
2017-12-21 22:08:54 +01:00
|
|
|
className={classnames('channel-name', {
|
|
|
|
'channel-name--small': smallCard,
|
|
|
|
'button-text no-underline': link,
|
2017-12-05 20:34:32 +01:00
|
|
|
})}
|
|
|
|
>
|
2017-11-22 21:28:56 +01:00
|
|
|
{channelName}
|
2017-12-21 22:08:54 +01:00
|
|
|
</span>{' '}
|
2017-11-21 20:51:12 +01:00
|
|
|
{!signatureIsValid ? (
|
|
|
|
<Icon
|
|
|
|
icon={icon}
|
2017-12-21 22:08:54 +01:00
|
|
|
className={`channel-indicator__icon channel-indicator__icon--${modifier}`}
|
2017-11-21 20:51:12 +01:00
|
|
|
/>
|
|
|
|
) : (
|
2017-12-21 22:08:54 +01:00
|
|
|
''
|
2017-11-21 20:51:12 +01:00
|
|
|
)}
|
2017-05-21 16:42:34 +02:00
|
|
|
</span>
|
2017-06-06 23:19:12 +02:00
|
|
|
);
|
2017-09-17 22:33:52 +02:00
|
|
|
|
|
|
|
if (!channelLink) {
|
|
|
|
return inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-10-08 23:56:59 +02:00
|
|
|
<Link
|
|
|
|
navigate="/show"
|
|
|
|
navigateParams={{ uri: channelLink }}
|
|
|
|
className="no-underline"
|
2017-12-14 22:12:04 +01:00
|
|
|
span={span}
|
2017-10-08 23:56:59 +02:00
|
|
|
>
|
2017-09-17 22:33:52 +02:00
|
|
|
{inner}
|
|
|
|
</Link>
|
|
|
|
);
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
2017-05-02 07:25:31 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default UriIndicator;
|