diff --git a/src/renderer/component/externalLink/view.jsx b/src/renderer/component/externalLink/view.jsx index b3362de66..27f98e040 100644 --- a/src/renderer/component/externalLink/view.jsx +++ b/src/renderer/component/externalLink/view.jsx @@ -4,10 +4,10 @@ import { MODALS } from 'lbry-redux'; import Button from 'component/button'; type Props = { - href?: string, + href: string, title?: string, children: React.Node, - openModal: ({ id: string }, { url: string }) => void, + openModal: ({ id: string }, { uri: string }) => void, }; class ExternalLink extends React.PureComponent { @@ -15,20 +15,37 @@ class ExternalLink extends React.PureComponent { href: null, title: null, }; - render() { + + createLink() { const { href, title, children, openModal } = this.props; - return href ? ( - - ) : ( - children - ); + + // Regex for url protocol + const protocolRegex = new RegExp('^(https?|lbry)+:', 'i'); + const protocol = href ? protocolRegex.exec(href) : null; + + // Return plain text if no valid url + let element = {children}; + + // Return external link if protocol is http or https + if (protocol && (protocol[0] === 'http:' || protocol[0] === 'https:')) { + element = ( + + ); + } + + return element; + } + + render() { + const RenderLink = () => this.createLink(); + return ; } } diff --git a/src/renderer/modal/modalOpenExternalLink/view.jsx b/src/renderer/modal/modalOpenExternalLink/view.jsx index 7a92b75c1..76e8c4651 100644 --- a/src/renderer/modal/modalOpenExternalLink/view.jsx +++ b/src/renderer/modal/modalOpenExternalLink/view.jsx @@ -4,22 +4,22 @@ import { Modal } from 'modal/modal'; import { shell } from 'electron'; type Props = { - url: string, + uri: string, closeModal: () => void, }; class ModalOpenExternalLink extends React.PureComponent { openExternalLink() { - const { url, closeModal } = this.props; + const { uri, closeModal } = this.props; const { openExternal } = shell; - if (url) { - openExternal(url); + if (uri) { + openExternal(uri); } closeModal(); } render() { - const { url, closeModal } = this.props; + const { uri, closeModal } = this.props; return ( { >

Warning!

{__('This link leads to an external website.')}

-
{url}
+
{uri}

{__( 'LBRY Inc is not responsible for its content, click continue to proceed at your own risk.'