// @flow import { SITE_NAME } from 'config'; import * as PAGES from 'constants/pages'; import React, { useEffect } from 'react'; import Button from 'component/button'; import ClaimPreview from 'component/claimPreview'; import Card from 'component/common/card'; import { buildURI, parseURI } from 'util/lbryURI'; import { ERRORS } from 'lbryinc'; import REWARDS from 'rewards'; import { formatLbryUrlForWeb } from 'util/url'; import ChannelContent from 'component/channelContent'; import I18nMessage from 'component/i18nMessage'; type Props = { user: any, claimReward: () => void, setReferrer: (string) => void, referrerSetPending: boolean, referrerSetError: string, channelSubscribe: (sub: Subscription) => void, history: { push: (string) => void }, rewards: Array, referrer: string, fullUri: string, isSubscribed: boolean, }; function Invited(props: Props) { const { user, claimReward, setReferrer, referrerSetPending, referrerSetError, channelSubscribe, history, rewards, fullUri, referrer, isSubscribed, } = props; const refUri = referrer && 'lbry://' + referrer.replace(':', '#'); const { isChannel: referrerIsChannel, claimName: referrerChannelName, channelClaimId: referrerChannelClaimId, } = parseURI(refUri); const channelUri = referrerIsChannel && formatLbryUrlForWeb(buildURI({ channelName: referrerChannelName, channelClaimId: referrerChannelClaimId })); const rewardsApproved = user && user.is_reward_approved; const hasVerifiedEmail = user && user.has_verified_email; const referredRewardAvailable = rewards && rewards.some((reward) => reward.reward_type === REWARDS.TYPE_REFEREE); const redirect = channelUri || `/`; // always follow if it's a channel useEffect(() => { if (fullUri && !isSubscribed && fullUri) { let channelName; try { const { claimName } = parseURI(fullUri); channelName = claimName; } catch (e) {} if (channelName) { channelSubscribe({ channelName: channelName, uri: fullUri, }); } } }, [fullUri, isSubscribed, channelSubscribe]); useEffect(() => { if (!referrerSetPending && hasVerifiedEmail) { claimReward(); } }, [referrerSetPending, hasVerifiedEmail, claimReward]); useEffect(() => { if (referrer) { setReferrer(referrer.replace(':', '#')); } }, [referrer, setReferrer]); function handleDone() { history.push(redirect); } if (referrerSetError === ERRORS.ALREADY_CLAIMED) { return ( ) } actions={
} /> ); } if (referrerSetError && referredRewardAvailable) { return (

{__('Not a valid invite')}

} /> ); } if (!rewardsApproved) { const signUpButton = (