Automatically claim initial rewards (new_user & email_verified) when … #6807

Merged
Ruk33 merged 2 commits from 6788-automatically-claim-initial-rewards into master 2021-08-18 18:34:25 +02:00
5 changed files with 28 additions and 7 deletions
Showing only changes of commit de7c6788b4 - Show all commits

View file

@ -18,7 +18,7 @@ import {
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { doUpdateBlockListForPublishedChannel } from 'redux/actions/comments'; import { doUpdateBlockListForPublishedChannel } from 'redux/actions/comments';
import { doClaimInitialRewards } from 'redux/actions/rewards'; import { doClaimInitialRewards } from 'redux/actions/rewards';
import { selectIsClaimingInitialRewards } from 'redux/selectors/rewards'; import { selectIsClaimingInitialRewards, selectHasClaimedInitialRewards } from 'redux/selectors/rewards';
import ChannelForm from './view'; import ChannelForm from './view';
const select = (state, props) => ({ const select = (state, props) => ({
@ -39,6 +39,7 @@ const select = (state, props) => ({
creatingChannel: selectCreatingChannel(state), creatingChannel: selectCreatingChannel(state),
balance: selectBalance(state), balance: selectBalance(state),
isClaimingInitialRewards: selectIsClaimingInitialRewards(state), isClaimingInitialRewards: selectIsClaimingInitialRewards(state),
hasClaimedInitialRewards: selectHasClaimedInitialRewards(state),
}); });
const perform = (dispatch) => ({ const perform = (dispatch) => ({

View file

@ -57,6 +57,7 @@ type Props = {
uri: string, uri: string,
disabled: boolean, disabled: boolean,
isClaimingInitialRewards: boolean, isClaimingInitialRewards: boolean,
hasClaimedInitialRewards: boolean,
}; };
function ChannelForm(props: Props) { function ChannelForm(props: Props) {
@ -85,6 +86,7 @@ function ChannelForm(props: Props) {
openModal, openModal,
disabled, disabled,
isClaimingInitialRewards, isClaimingInitialRewards,
hasClaimedInitialRewards,
} = props; } = props;
const [nameError, setNameError] = React.useState(undefined); const [nameError, setNameError] = React.useState(undefined);
const [bidError, setBidError] = React.useState(''); const [bidError, setBidError] = React.useState('');
@ -240,8 +242,10 @@ function ChannelForm(props: Props) {
}, [clearChannelErrors]); }, [clearChannelErrors]);
React.useEffect(() => { React.useEffect(() => {
claimInitialRewards(); if (!hasClaimedInitialRewards) {
}, [claimInitialRewards]); claimInitialRewards();
}
}, [hasClaimedInitialRewards, claimInitialRewards]);
// TODO clear and bail after submit // TODO clear and bail after submit
return ( return (

View file

@ -19,7 +19,11 @@ import {
import * as RENDER_MODES from 'constants/file_render_modes'; import * as RENDER_MODES from 'constants/file_render_modes';
import { doPublishDesktop } from 'redux/actions/publish'; import { doPublishDesktop } from 'redux/actions/publish';
import { doClaimInitialRewards } from 'redux/actions/rewards'; import { doClaimInitialRewards } from 'redux/actions/rewards';
import { selectUnclaimedRewardValue, selectIsClaimingInitialRewards } from 'redux/selectors/rewards'; import {
selectUnclaimedRewardValue,
selectIsClaimingInitialRewards,
selectHasClaimedInitialRewards,
} from 'redux/selectors/rewards';
import { import {
selectModal, selectModal,
selectActiveChannelClaim, selectActiveChannelClaim,
@ -61,6 +65,7 @@ const select = (state) => {
incognito: selectIncognito(state), incognito: selectIncognito(state),
activeChannelStakedLevel: selectActiveChannelStakedLevel(state), activeChannelStakedLevel: selectActiveChannelStakedLevel(state),
isClaimingInitialRewards: selectIsClaimingInitialRewards(state), isClaimingInitialRewards: selectIsClaimingInitialRewards(state),
hasClaimedInitialRewards: selectHasClaimedInitialRewards(state),
}; };
}; };

View file

@ -92,6 +92,7 @@ type Props = {
remoteUrl: ?string, remoteUrl: ?string,
isClaimingInitialRewards: boolean, isClaimingInitialRewards: boolean,
claimInitialRewards: () => void, claimInitialRewards: () => void,
hasClaimedInitialRewards: boolean,
}; };
function PublishForm(props: Props) { function PublishForm(props: Props) {
@ -132,6 +133,7 @@ function PublishForm(props: Props) {
remoteUrl, remoteUrl,
isClaimingInitialRewards, isClaimingInitialRewards,
claimInitialRewards, claimInitialRewards,
hasClaimedInitialRewards,
} = props; } = props;
const { replace, location } = useHistory(); const { replace, location } = useHistory();
@ -268,8 +270,10 @@ function PublishForm(props: Props) {
}, [activeChannelClaimStr, setSignedMessage]); }, [activeChannelClaimStr, setSignedMessage]);
useEffect(() => { useEffect(() => {
claimInitialRewards(); if (!hasClaimedInitialRewards) {
}, [claimInitialRewards]); claimInitialRewards();
}
}, [hasClaimedInitialRewards, claimInitialRewards]);
useEffect(() => { useEffect(() => {
if (!modal) { if (!modal) {

View file

@ -63,5 +63,12 @@ export const selectHasUnclaimedRefereeReward = createSelector(selectUnclaimedRew
); );
export const selectIsClaimingInitialRewards = createSelector(selectClaimsPendingByType, (claimsPendingByType) => { export const selectIsClaimingInitialRewards = createSelector(selectClaimsPendingByType, (claimsPendingByType) => {
return claimsPendingByType[REWARDS.TYPE_NEW_USER] || claimsPendingByType[REWARDS.TYPE_CONFIRM_EMAIL]; return !!(claimsPendingByType[REWARDS.TYPE_NEW_USER] || claimsPendingByType[REWARDS.TYPE_CONFIRM_EMAIL]);
});
export const selectHasClaimedInitialRewards = createSelector(selectClaimedRewardsById, (claimedRewardsById) => {
const claims = Object.values(claimedRewardsById);
const newUserClaimed = !!claims.find((claim) => claim && claim.reward_type === REWARDS.TYPE_NEW_USER);
const confirmEmailClaimed = !!claims.find((claim) => claim && claim.reward_type === REWARDS.TYPE_CONFIRM_EMAIL);
return newUserClaimed && confirmEmailClaimed;
}); });