Repository: freeCodeCamp/freeCodeCamp
File: client/src/redux/donation-saga.js (JavaScript)

Code before:
  postChargeProcessing,
  postChargeError,
  preventBlockDonationRequests,
  setSessionChallNumProgressModalShown,
  executeGA
} from './actions';
import {
  isDonatingSelector,
  recentlyClaimedBlockSelector,
  shouldRequestDonationSelector,
  isSignedInSelector
} from './selectors';

const defaultDonationErrorMessage = i18next.t('donate.error-2');

function* showDonateModalSaga() {
  let shouldRequestDonation = yield select(shouldRequestDonationSelector);
  if (shouldRequestDonation) {
    yield delay(200);
    const recentlyClaimedBlock = yield select(recentlyClaimedBlockSelector);
    yield put(openDonationModal());
    yield take(appTypes.closeDonationModal);
    if (recentlyClaimedBlock) {
      yield put(preventBlockDonationRequests());
    } else {
      yield put(setSessionChallNumProgressModalShown());
    }
  }
}

export function* postChargeSaga({
  payload,
  payload: {
    paymentProvider,
    paymentContext,
    amount,
    duration,
    handleAuthentication,
    paymentMethodId
  }
}) {
  try {
    if (paymentProvider !== PaymentProvider.Patreon) {
      yield put(postChargeProcessing());
    }

    if (paymentProvider === PaymentProvider.Stripe) {
      yield call(postChargeStripe, payload);
    } else if (paymentProvider === PaymentProvider.StripeCard) {
      const optimizedPayload = { paymentMethodId, amount, duration };
      const response = yield call(postChargeStripeCard, optimizedPayload);

Review comment (suggestion):
This variable is a little confusing to me. 

My first thought is that it should just be "progressDonationModalShown". I think that's clear enough.

Also, I think it would be clearer if the reducer set two properties in the store: `progressDonationModalShown` and `completionCountWhenShownProgressModal`. They're a bit wordier than I'd like, but there we are.

If we use these two, it should make it a little clearer what's going on. I'll update the selector logic with an example of what I mean.

Code after:
  postChargeProcessing,
  postChargeError,
  preventBlockDonationRequests,
  setCompletionCountWhenShownProgressModal,
  executeGA
} from './actions';
import {
  isDonatingSelector,
  recentlyClaimedBlockSelector,
  shouldRequestDonationSelector,
  isSignedInSelector
} from './selectors';

const defaultDonationErrorMessage = i18next.t('donate.error-2');

function* showDonateModalSaga() {
  let shouldRequestDonation = yield select(shouldRequestDonationSelector);
  if (shouldRequestDonation) {
    yield delay(200);
    const recentlyClaimedBlock = yield select(recentlyClaimedBlockSelector);
    yield put(openDonationModal());
    yield take(appTypes.closeDonationModal);
    if (recentlyClaimedBlock) {
      yield put(preventBlockDonationRequests());
    } else {
      yield put(setCompletionCountWhenShownProgressModal());
    }
  }
}

export function* postChargeSaga({
  payload,
  payload: {
    paymentProvider,
    paymentContext,
    amount,
    duration,
    handleAuthentication,
    paymentMethodId
  }
}) {
  try {
    if (paymentProvider !== PaymentProvider.Patreon) {
      yield put(postChargeProcessing());
    }

    if (paymentProvider === PaymentProvider.Stripe) {
      yield call(postChargeStripe, payload);
    } else if (paymentProvider === PaymentProvider.StripeCard) {
      const optimizedPayload = { paymentMethodId, amount, duration };
      const response = yield call(postChargeStripeCard, optimizedPayload);