2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2018-04-18 06:03:01 +02:00
|
|
|
import { buildURI } from 'lbry-redux';
|
2019-06-28 09:27:55 +02:00
|
|
|
import Tooltip from 'component/common/tooltip';
|
|
|
|
import ClaimPreview from 'component/claimPreview';
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
isResolvingUri: boolean,
|
2019-04-24 16:02:08 +02:00
|
|
|
channelUri: ?string,
|
2018-05-07 06:50:55 +02:00
|
|
|
link: ?boolean,
|
2019-06-11 20:10:58 +02:00
|
|
|
claim: ?Claim,
|
2019-07-22 04:05:37 +02:00
|
|
|
addTooltip: boolean,
|
2018-05-07 06:50:55 +02:00
|
|
|
// Lint thinks we aren't using these, even though we are.
|
|
|
|
// Possibly because the resolve function is an arrow function that is passed in props?
|
2018-03-26 23:32:43 +02:00
|
|
|
resolveUri: string => void,
|
|
|
|
uri: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
class UriIndicator extends React.PureComponent<Props> {
|
2019-07-22 04:05:37 +02:00
|
|
|
static defaultProps = {
|
|
|
|
addTooltip: true,
|
|
|
|
};
|
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
componentDidMount() {
|
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
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.resolve(this.props);
|
2017-05-10 05:06:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
resolve = (props: 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
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2017-05-02 07:25:31 +02:00
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
render() {
|
2019-07-22 04:05:37 +02:00
|
|
|
const { link, isResolvingUri, claim, addTooltip } = this.props;
|
2019-04-24 16:02:08 +02:00
|
|
|
|
2017-05-21 16:42:34 +02:00
|
|
|
if (!claim) {
|
2019-03-25 07:18:22 +01:00
|
|
|
return <span className="empty">{isResolvingUri ? 'Validating...' : 'Unused'}</span>;
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
const isChannelClaim = claim.value_type === 'channel';
|
|
|
|
|
|
|
|
if (!claim.signing_channel && !isChannelClaim) {
|
2019-03-25 07:18:22 +01:00
|
|
|
return <span className="channel-name">Anonymous</span>;
|
2017-05-21 16:42:34 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
const channelClaim = isChannelClaim ? claim : claim.signing_channel;
|
2017-05-21 16:42:34 +02:00
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
if (channelClaim) {
|
|
|
|
const { name, claim_id: claimId } = channelClaim;
|
|
|
|
let channelLink;
|
2019-07-22 04:05:37 +02:00
|
|
|
|
|
|
|
// Disabling now because it mostly causes issues
|
|
|
|
// Add this back to ensure we only add links to signed channels
|
|
|
|
// if (claim.is_channel_signature_valid) {
|
|
|
|
channelLink = link ? buildURI({ channelName: name, claimId }) : false;
|
|
|
|
// }
|
2017-09-17 22:33:52 +02:00
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
const inner = <span className="channel-name">{name}</span>;
|
|
|
|
|
|
|
|
if (!channelLink) {
|
|
|
|
return inner;
|
|
|
|
}
|
2017-09-17 22:33:52 +02:00
|
|
|
|
2019-07-22 04:05:37 +02:00
|
|
|
const Wrapper = addTooltip
|
|
|
|
? ({ children }) => (
|
|
|
|
<Tooltip label={<ClaimPreview uri={channelLink} type="tooltip" placeholder={false} />}>{children}</Tooltip>
|
|
|
|
)
|
|
|
|
: 'span';
|
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
return (
|
|
|
|
<Button className="button--uri-indicator" navigate={channelLink}>
|
2019-07-22 04:05:37 +02:00
|
|
|
<Wrapper>{inner}</Wrapper>
|
2019-06-11 20:10:58 +02:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
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;
|