// @flow 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 'lbry-redux'; import { rewards as REWARDS, ERRORS } from 'lbryinc'; import { formatLbryUrlForWeb } from 'util/url'; 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) { channelSubscribe({ channelName: parseURI(fullUri).claimName, uri: fullUri, }); } }, [fullUri, isSubscribed]); useEffect(() => { if (!referrerSetPending && hasVerifiedEmail) { claimReward(); } }, [referrerSetPending, hasVerifiedEmail]); useEffect(() => { if (referrer) { setReferrer(referrer.replace(':', '#')); } }, [referrer]); function handleDone() { history.push(redirect); } if (referrerSetError === ERRORS.ALREADY_CLAIMED) { return ( ) } actions={
} /> ); } if (referrerSetError && referredRewardAvailable) { return (

{__('Not a valid invite')}

} /> ); } if (!rewardsApproved) { return ( ) } actions={
} /> ); } return ( ) } actions={
} /> ); } export default Invited;