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

Code before:
export const showCertFetchStateSelector = state =>
  state[MainApp].showCertFetchState;
export const shouldRequestDonationSelector = state => {
  const completedChallengesLength = completedChallengesSelector(state).length;
  const completionCount = completionCountSelector(state);
  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;

Review comment (bug):
```suggestion
    showMultipleProgressModals &&
    progressDonationModalShown &&
    completedChallengesLength > 50 &&
    completionCount - lastCompletionCount >= 30
```
I think this reads a little better (also should be 30, not 20, right? Or the comment's wrong) 

Code after:
  userFetchStateSelector(state).pending;
export const showCertSelector = state => state[MainApp].showCert;
export const showCertFetchStateSelector = state =>
  state[MainApp].showCertFetchState;
export const shouldRequestDonationSelector = state => {
  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;
};