diff --git a/src/ui/component/socialShare/view.jsx b/src/ui/component/socialShare/view.jsx index 0cf996c3e..63edcf65d 100644 --- a/src/ui/component/socialShare/view.jsx +++ b/src/ui/component/socialShare/view.jsx @@ -33,35 +33,40 @@ class SocialShare extends React.PureComponent { const { speechShareable, onDone } = this.props; const channelClaimId = value && value.publisherSignature && value.publisherSignature.certificateId; - const speechPrefix = 'https://spee.ch/'; - const lbryPrefix = 'https://open.lbry.com/'; - let speechURL; - let lbryURL; - if (isChannel) { - // For channel claims, the channel name (@something) is in `claim.name` - speechURL = `${claimName}:${claimId}`; - lbryURL = `${claimName}#${claimId}`; - } else { - // If it's for a regular claim, check if it has an associated channel - speechURL = - channelName && channelClaimId + const getSpeechUri = (): string => { + if (isChannel) { + // For channel claims, the channel name (@something) is in `claim.name` + return `${claimName}:${claimId}`; + } else { + // If it's for a regular claim, check if it has an associated channel + return channelName && channelClaimId ? `${channelName}:${channelClaimId}/${claimName}` : `${claimId}/${claimName}`; + } + }; - lbryURL = - channelName && channelClaimId + const getLbryUri = (): string => { + if (isChannel) { + // For channel claims, the channel name (@something) is in `claim.name` + return `${claimName}#${claimId}`; + } else { + // If it's for a regular claim, check if it has an associated channel + return channelName && channelClaimId ? `${channelName}#${channelClaimId}/${claimName}` : `${claimName}#${claimId}`; - } + } + }; - if (lbryURL) { - lbryURL = `${lbryPrefix}${encodeURIComponent(lbryURL)}`; - } + const speechPrefix = 'https://spee.ch/'; + const lbryPrefix = 'https://open.lbry.com/'; + const lbryUri = getLbryUri(); + const speechUri = getSpeechUri(); + const encodedLbryURL: string = `${lbryPrefix}${encodeURIComponent(lbryUri)}`; + const lbryURL: string = `${lbryPrefix}${getLbryUri()}`; - if (speechURL) { - speechURL = `${speechPrefix}${encodeURIComponent(speechURL)}`; - } + const encodedSpeechURL = `${speechPrefix}${encodeURIComponent(speechUri)}`; + const speechURL = `${speechPrefix}${speechUri}`; return ( @@ -76,7 +81,7 @@ class SocialShare extends React.PureComponent { icon={ICONS.FACEBOOK} button="alt" label={__('')} - href={`https://facebook.com/sharer/sharer.php?u=${speechURL}`} + href={`https://facebook.com/sharer/sharer.php?u=${encodedSpeechURL}`} /> @@ -85,7 +90,7 @@ class SocialShare extends React.PureComponent { icon={ICONS.TWITTER} button="alt" label={__('')} - href={`https://twitter.com/home?status=${speechURL}`} + href={`https://twitter.com/home?status=${encodedSpeechURL}`} /> @@ -110,7 +115,7 @@ class SocialShare extends React.PureComponent { icon={ICONS.FACEBOOK} button="alt" label={__('')} - href={`https://facebook.com/sharer/sharer.php?u=${lbryURL}`} + href={`https://facebook.com/sharer/sharer.php?u=${encodedLbryURL}`} /> @@ -119,7 +124,7 @@ class SocialShare extends React.PureComponent { icon={ICONS.TWITTER} button="alt" label={__('')} - href={`https://twitter.com/home?status=${lbryURL}`} + href={`https://twitter.com/home?status=${encodedLbryURL}`} />