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

View file

@ -50,7 +50,7 @@ import NotificationsPage from 'page/notifications';
import SignInWalletPasswordPage from 'page/signInWalletPassword';
import YoutubeSyncPage from 'page/youtubeSync';
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';
const dynamicRoutes = Object.values(SIDEBAR_ROUTES).filter(
@ -105,6 +105,8 @@ type Props = {
welcomeVersion: number,
hasNavigated: boolean,
setHasNavigated: () => void,
setReferrer: string => void,
hasUnclaimedRefereeReward: boolean,
};
function AppRouter(props: Props) {
@ -118,6 +120,8 @@ function AppRouter(props: Props) {
welcomeVersion,
hasNavigated,
setHasNavigated,
hasUnclaimedRefereeReward,
setReferrer,
} = props;
const { entries } = history;
const entryIndex = history.index;
@ -135,6 +139,16 @@ function AppRouter(props: Props) {
return unlisten;
}, [hasNavigated, setHasNavigated]);
useEffect(() => {
if (!hasNavigated && hasUnclaimedRefereeReward) {
const valid = isURIValid(uri);
if (valid) {
const { path } = parseURI(uri);
setReferrer(path);
}
}
}, [hasNavigated, uri, hasUnclaimedRefereeReward, setReferrer]);
useEffect(() => {
if (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 { doClaimRewardType, doRewardList } from 'redux/actions/rewards';
import { selectEmailToVerify, selectPhoneToVerify, selectUserCountryCode, selectUser } from 'redux/selectors/user';
@ -640,10 +640,8 @@ export function doUserSetReferrer(referrer, shouldClaim) {
});
let claim;
let referrerCode;
const { isChannel } = parseURI(referrer);
if (isChannel) {
const isValid = isURIValid(referrer);
if (isValid) {
const uri = `lbry://${referrer}`;
claim = makeSelectClaimForUri(uri)(getState());
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) {

View file

@ -57,3 +57,7 @@ export const selectReferralReward = createSelector(
selectUnclaimedRewards,
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)
);