initial page view sets referring channel

This commit is contained in:
jessop 2020-10-06 20:59:38 -04:00 committed by Sean Yesmunt
parent 72f5684b6f
commit 10ce772bcb
4 changed files with 34 additions and 7 deletions

View file

@ -4,6 +4,9 @@ import { selectHasNavigated, selectScrollStartingPosition, selectWelcomeVersion
import Router from './view'; import Router from './view';
import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux'; import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux';
import { doSetHasNavigated } from 'redux/actions/app'; import { doSetHasNavigated } from 'redux/actions/app';
import { doUserSetReferrer } from 'redux/actions/user';
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
const select = state => { const select = state => {
const { pathname, hash } = state.router.location; const { pathname, hash } = state.router.location;
const urlPath = pathname + hash; const urlPath = pathname + hash;
@ -28,11 +31,13 @@ const select = state => {
isAuthenticated: selectUserVerifiedEmail(state), isAuthenticated: selectUserVerifiedEmail(state),
welcomeVersion: selectWelcomeVersion(state), welcomeVersion: selectWelcomeVersion(state),
hasNavigated: selectHasNavigated(state), hasNavigated: selectHasNavigated(state),
hasUnclaimedRefereeReward: selectHasUnclaimedRefereeReward(state),
}; };
}; };
const perform = dispatch => ({ const perform = dispatch => ({
setHasNavigated: () => dispatch(doSetHasNavigated()), setHasNavigated: () => dispatch(doSetHasNavigated()),
setReferrer: referrer => dispatch(doUserSetReferrer(referrer)),
}); });
export default connect(select, perform)(Router); export default connect(select, perform)(Router);

View file

@ -50,7 +50,7 @@ import NotificationsPage from 'page/notifications';
import SignInWalletPasswordPage from 'page/signInWalletPassword'; import SignInWalletPasswordPage from 'page/signInWalletPassword';
import YoutubeSyncPage from 'page/youtubeSync'; import YoutubeSyncPage from 'page/youtubeSync';
import { LINKED_COMMENT_QUERY_PARAM } from 'constants/comment'; import { LINKED_COMMENT_QUERY_PARAM } from 'constants/comment';
import { parseURI } from 'lbry-redux'; import { parseURI, isURIValid } from 'lbry-redux';
import { SITE_TITLE, WELCOME_VERSION } from 'config'; import { SITE_TITLE, WELCOME_VERSION } from 'config';
const dynamicRoutes = Object.values(SIDEBAR_ROUTES).filter( const dynamicRoutes = Object.values(SIDEBAR_ROUTES).filter(
@ -105,6 +105,8 @@ type Props = {
welcomeVersion: number, welcomeVersion: number,
hasNavigated: boolean, hasNavigated: boolean,
setHasNavigated: () => void, setHasNavigated: () => void,
setReferrer: string => void,
hasUnclaimedRefereeReward: boolean,
}; };
function AppRouter(props: Props) { function AppRouter(props: Props) {
@ -118,6 +120,8 @@ function AppRouter(props: Props) {
welcomeVersion, welcomeVersion,
hasNavigated, hasNavigated,
setHasNavigated, setHasNavigated,
hasUnclaimedRefereeReward,
setReferrer,
} = props; } = props;
const { entries } = history; const { entries } = history;
const entryIndex = history.index; const entryIndex = history.index;
@ -135,6 +139,16 @@ function AppRouter(props: Props) {
return unlisten; return unlisten;
}, [hasNavigated, setHasNavigated]); }, [hasNavigated, setHasNavigated]);
useEffect(() => {
if (!hasNavigated && hasUnclaimedRefereeReward) {
const valid = isURIValid(uri);
if (valid) {
const { path } = parseURI(uri);
setReferrer(path);
}
}
}, [hasNavigated, uri, hasUnclaimedRefereeReward, setReferrer]);
useEffect(() => { useEffect(() => {
if (uri) { if (uri) {
const { channelName, streamName } = parseURI(uri); const { channelName, streamName } = parseURI(uri);

View file

@ -1,4 +1,4 @@
import { Lbry, doFetchChannelListMine, batchActions, makeSelectClaimForUri, parseURI } from 'lbry-redux'; import { Lbry, doFetchChannelListMine, batchActions, makeSelectClaimForUri, isURIValid } from 'lbry-redux';
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import { doClaimRewardType, doRewardList } from 'redux/actions/rewards'; import { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
import { selectEmailToVerify, selectPhoneToVerify, selectUserCountryCode, selectUser } from 'redux/selectors/user'; import { selectEmailToVerify, selectPhoneToVerify, selectUserCountryCode, selectUser } from 'redux/selectors/user';
@ -640,10 +640,8 @@ export function doUserSetReferrer(referrer, shouldClaim) {
}); });
let claim; let claim;
let referrerCode; let referrerCode;
const isValid = isURIValid(referrer);
const { isChannel } = parseURI(referrer); if (isValid) {
if (isChannel) {
const uri = `lbry://${referrer}`; const uri = `lbry://${referrer}`;
claim = makeSelectClaimForUri(uri)(getState()); claim = makeSelectClaimForUri(uri)(getState());
if (!claim) { if (!claim) {
@ -657,7 +655,13 @@ export function doUserSetReferrer(referrer, shouldClaim) {
}); });
} }
} }
referrerCode = claim && claim.permanent_url && claim.permanent_url.replace('lbry://', ''); if (claim) {
if (claim.signing_channel) {
referrerCode = claim.signing_channel.permanent_url.replace('lbry://', '');
} else {
referrerCode = claim.permanent_url.replace('lbry://', '');
}
}
} }
if (!referrerCode) { if (!referrerCode) {

View file

@ -57,3 +57,7 @@ export const selectReferralReward = createSelector(
selectUnclaimedRewards, selectUnclaimedRewards,
unclaimedRewards => unclaimedRewards.filter(reward => reward.reward_type === REWARDS.TYPE_REFERRAL)[0] unclaimedRewards => unclaimedRewards.filter(reward => reward.reward_type === REWARDS.TYPE_REFERRAL)[0]
); );
export const selectHasUnclaimedRefereeReward = createSelector(selectUnclaimedRewards, unclaimedRewards =>
unclaimedRewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE)
);