lbry-desktop/ui/js/component/uriIndicator/view.jsx

65 lines
1.3 KiB
React
Raw Normal View History

2017-06-06 17:19:12 -04:00
import React from "react";
import { Icon } from "component/common";
2017-05-02 12:25:31 +07:00
2017-06-07 21:42:19 -07:00
class UriIndicator extends React.PureComponent {
2017-05-21 10:42:34 -04:00
componentWillMount() {
2017-06-06 17:19:12 -04:00
this.resolve(this.props);
2017-05-21 10:42:34 -04:00
}
2017-05-02 12:25:31 +07:00
2017-05-21 10:42:34 -04:00
componentWillReceiveProps(nextProps) {
2017-06-06 17:19:12 -04:00
this.resolve(nextProps);
2017-05-09 23:06:48 -04:00
}
2017-05-21 10:42:34 -04:00
resolve(props) {
2017-06-06 17:19:12 -04:00
const { isResolvingUri, resolveUri, claim, uri } = props;
2017-05-09 23:06:48 -04:00
2017-06-06 17:19:12 -04:00
if (!isResolvingUri && claim === undefined && uri) {
resolveUri(uri);
2017-05-21 10:42:34 -04:00
}
2017-05-02 12:25:31 +07:00
}
2017-05-21 10:42:34 -04:00
render() {
2017-06-06 17:19:12 -04:00
const { claim, uri, isResolvingUri } = this.props;
2017-05-21 10:42:34 -04:00
if (isResolvingUri && !claim) {
2017-06-06 17:19:12 -04:00
return <span className="empty">Validating...</span>;
2017-05-21 10:42:34 -04:00
}
if (!claim) {
2017-06-06 17:19:12 -04:00
return <span className="empty">Unused</span>;
2017-05-21 10:42:34 -04:00
}
2017-05-02 12:25:31 +07:00
2017-05-21 10:42:34 -04:00
const {
channel_name: channelName,
has_signature: hasSignature,
signature_is_valid: signatureIsValid,
2017-06-06 17:19:12 -04:00
} = claim;
2017-05-21 10:42:34 -04:00
if (!hasSignature || !channelName) {
return <span className="empty">Anonymous</span>;
}
let icon, modifier;
if (signatureIsValid) {
2017-06-06 17:19:12 -04:00
modifier = "valid";
2017-05-21 10:42:34 -04:00
} else {
2017-06-06 17:19:12 -04:00
icon = "icon-times-circle";
modifier = "invalid";
2017-05-21 10:42:34 -04:00
}
return (
<span>
2017-06-06 17:19:12 -04:00
{channelName} {" "}
{!signatureIsValid
? <Icon
icon={icon}
className={`channel-indicator__icon channel-indicator__icon--${modifier}`}
/>
: ""}
2017-05-21 10:42:34 -04:00
</span>
2017-06-06 17:19:12 -04:00
);
2017-05-21 10:42:34 -04:00
}
2017-05-02 12:25:31 +07:00
}
2017-06-05 21:21:55 -07:00
export default UriIndicator;