diff --git a/ui/component/channelEdit/index.js b/ui/component/channelEdit/index.js index 8bb161afc..9a195039b 100644 --- a/ui/component/channelEdit/index.js +++ b/ui/component/channelEdit/index.js @@ -18,7 +18,7 @@ import { import { doOpenModal } from 'redux/actions/app'; import { doUpdateBlockListForPublishedChannel } from 'redux/actions/comments'; import { doClaimInitialRewards } from 'redux/actions/rewards'; -import { selectIsClaimingInitialRewards } from 'redux/selectors/rewards'; +import { selectIsClaimingInitialRewards, selectHasClaimedInitialRewards } from 'redux/selectors/rewards'; import ChannelForm from './view'; const select = (state, props) => ({ @@ -39,6 +39,7 @@ const select = (state, props) => ({ creatingChannel: selectCreatingChannel(state), balance: selectBalance(state), isClaimingInitialRewards: selectIsClaimingInitialRewards(state), + hasClaimedInitialRewards: selectHasClaimedInitialRewards(state), }); const perform = (dispatch) => ({ diff --git a/ui/component/channelEdit/view.jsx b/ui/component/channelEdit/view.jsx index f02289a0b..61c9df69f 100644 --- a/ui/component/channelEdit/view.jsx +++ b/ui/component/channelEdit/view.jsx @@ -57,6 +57,7 @@ type Props = { uri: string, disabled: boolean, isClaimingInitialRewards: boolean, + hasClaimedInitialRewards: boolean, }; function ChannelForm(props: Props) { @@ -85,6 +86,7 @@ function ChannelForm(props: Props) { openModal, disabled, isClaimingInitialRewards, + hasClaimedInitialRewards, } = props; const [nameError, setNameError] = React.useState(undefined); const [bidError, setBidError] = React.useState(''); @@ -240,8 +242,10 @@ function ChannelForm(props: Props) { }, [clearChannelErrors]); React.useEffect(() => { - claimInitialRewards(); - }, [claimInitialRewards]); + if (!hasClaimedInitialRewards) { + claimInitialRewards(); + } + }, [hasClaimedInitialRewards, claimInitialRewards]); // TODO clear and bail after submit return ( diff --git a/ui/component/publishForm/index.js b/ui/component/publishForm/index.js index 504f2fb5b..58b24bdb5 100644 --- a/ui/component/publishForm/index.js +++ b/ui/component/publishForm/index.js @@ -19,7 +19,11 @@ import { import * as RENDER_MODES from 'constants/file_render_modes'; import { doPublishDesktop } from 'redux/actions/publish'; import { doClaimInitialRewards } from 'redux/actions/rewards'; -import { selectUnclaimedRewardValue, selectIsClaimingInitialRewards } from 'redux/selectors/rewards'; +import { + selectUnclaimedRewardValue, + selectIsClaimingInitialRewards, + selectHasClaimedInitialRewards, +} from 'redux/selectors/rewards'; import { selectModal, selectActiveChannelClaim, @@ -61,6 +65,7 @@ const select = (state) => { incognito: selectIncognito(state), activeChannelStakedLevel: selectActiveChannelStakedLevel(state), isClaimingInitialRewards: selectIsClaimingInitialRewards(state), + hasClaimedInitialRewards: selectHasClaimedInitialRewards(state), }; }; diff --git a/ui/component/publishForm/view.jsx b/ui/component/publishForm/view.jsx index f64aa3ce5..eac23885b 100644 --- a/ui/component/publishForm/view.jsx +++ b/ui/component/publishForm/view.jsx @@ -92,6 +92,7 @@ type Props = { remoteUrl: ?string, isClaimingInitialRewards: boolean, claimInitialRewards: () => void, + hasClaimedInitialRewards: boolean, }; function PublishForm(props: Props) { @@ -132,6 +133,7 @@ function PublishForm(props: Props) { remoteUrl, isClaimingInitialRewards, claimInitialRewards, + hasClaimedInitialRewards, } = props; const { replace, location } = useHistory(); @@ -268,8 +270,10 @@ function PublishForm(props: Props) { }, [activeChannelClaimStr, setSignedMessage]); useEffect(() => { - claimInitialRewards(); - }, [claimInitialRewards]); + if (!hasClaimedInitialRewards) { + claimInitialRewards(); + } + }, [hasClaimedInitialRewards, claimInitialRewards]); useEffect(() => { if (!modal) { diff --git a/ui/redux/selectors/rewards.js b/ui/redux/selectors/rewards.js index 4349021dd..00d6d390a 100644 --- a/ui/redux/selectors/rewards.js +++ b/ui/redux/selectors/rewards.js @@ -63,5 +63,12 @@ export const selectHasUnclaimedRefereeReward = createSelector(selectUnclaimedRew ); 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; });