Repository: freeCodeCamp/freeCodeCamp
File: client/src/redux/selectors.js (JavaScript)

Code before:
  const sessionChallNumProgressModalShown =
    sessionChallNumProgressModalShownSelector(state);
  const isDonating = isDonatingSelector(state);
  const recentlyClaimedBlock = recentlyClaimedBlockSelector(state);
  const showMultipleProgressModals = showMultipleProgressModalsSelector(state);

  // don't request donation if already donating
  if (isDonating) return false;

  // a block has been completed
  if (recentlyClaimedBlock) return true;

  /* 
  When AB testing for showing multiple progress modals is active,
  show a donation modal every 30 challenges after the first 50
   */
  if (
    showMultipleProgressModals &&
    sessionChallNumProgressModalShown !== null &&
    completedChallengesLength > 50 &&
    sessionChallNumProgressModalShown + 20 >= completionCount
  )
    return true;

  // a donation has already been requested
  if (sessionChallNumProgressModalShown !== null) return false;

  // donations only appear after the user has completed ten challenges (i.e.
  // not before the 11th challenge has mounted)
  if (completedChallengesLength < 10) return false;

  // this will mean we have completed 3 or more challenges this browser session
  // and enough challenges overall to not be new
  return completionCount >= 3;
};

export const userTokenSelector = state => {
  return userSelector(state).userToken;
};

export const showCodeAllySelector = state => {
  return state[MainApp].showCodeAlly;
};

export const examInProgressSelector = state => {
  return state[MainApp].examInProgress;
};

export const userByNameSelector = username => state => {
  const { user } = state[MainApp];
  // return initial state empty user empty object instead of empty

Review comment (suggestion):
```suggestion
  if (progressDonationModalShown) return false;
```
This is also a little better.

Code after:
  const completedChallengesLength = completedChallengesSelector(state).length;
  const completionCount = completionCountSelector(state);
  const lastCompletionCount =
    completionCountWhenShownProgressModalSelector(state);
  const progressDonationModalShown = progressDonationModalShownSelector(state);
  const isDonating = isDonatingSelector(state);
  const recentlyClaimedBlock = recentlyClaimedBlockSelector(state);
  const showMultipleProgressModals = showMultipleProgressModalsSelector(state);

  // don't request donation if already donating
  if (isDonating) return false;

  // a block has been completed
  if (recentlyClaimedBlock) return true;

  /* 
  When AB testing for showing multiple progress modals is active,
  show a donation modal every 30 challenges after the first 50
   */
  if (
    showMultipleProgressModals &&
    progressDonationModalShown &&
    completedChallengesLength > 50 &&
    completionCount - lastCompletionCount >= 30
  )
    return true;

  // a donation has already been requested
  if (progressDonationModalShown) return false;

  // donations only appear after the user has completed ten challenges (i.e.
  // not before the 11th challenge has mounted)
  if (completedChallengesLength < 10) return false;

  // this will mean we have completed 3 or more challenges this browser session
  // and enough challenges overall to not be new
  return completionCount >= 3;
};

export const userTokenSelector = state => {
  return userSelector(state).userToken;
};

export const showCodeAllySelector = state => {
  return state[MainApp].showCodeAlly;
};

export const examInProgressSelector = state => {
  return state[MainApp].examInProgress;
};