// @flow import * as PAGES from 'constants/pages'; import React, { useEffect } from 'react'; import { useParams } from 'react-router'; import Button from 'component/button'; import ClaimPreview from 'component/claimPreview'; import Card from 'component/common/card'; import { parseURI } from 'lbry-redux'; type Props = { user: any, fetchUser: () => void, claimReward: () => void, setReferrer: string => void, setReferrerPending: boolean, setReferrerError: string, channelSubscribe: (sub: Subscription) => void, history: { push: string => void }, }; function Invited(props: Props) { const { user, fetchUser, claimReward, setReferrer, setReferrerPending, setReferrerError, channelSubscribe, history, } = props; // useParams requires react-router-dom ^v5.1.0 const { referrer } = useParams(); const refUri = 'lbry://' + referrer.replace(':', '#'); const referrerIsChannel = parseURI(refUri).isChannel; const rewardsApproved = user && user.is_reward_approved; const hasVerifiedEmail = user && user.has_verified_email; useEffect(() => { fetchUser(); }, []); useEffect(() => { if (!setReferrerPending && hasVerifiedEmail) { claimReward(); } }, [setReferrerPending, hasVerifiedEmail]); useEffect(() => { if (referrer) { setReferrer(referrer.replace(':', '#')); } }, [referrer]); function handleDone() { if (hasVerifiedEmail && referrerIsChannel) { channelSubscribe({ channelName: parseURI(refUri).claimName, uri: refUri, }); } history.push(`/$/${PAGES.DISCOVER}`); } if (setReferrerError) { return (

{__('Not a valid referral')}

{setReferrerError}

} /> ); } if (!rewardsApproved) { return ( {referrerIsChannel && (
)}
} /> ); } return ( {referrerIsChannel && (
)}
} /> ); } export default Invited;