MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / shouldRequestDonationSelector

Function shouldRequestDonationSelector

client/src/redux/selectors.js:60–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58export const showCertFetchStateSelector = state =>
59 state[MainApp].showCertFetchState;
60export const shouldRequestDonationSelector = state => {
61 const completedChallengeCount = completedChallengesSelector(state).length;
62 const isDonating = isDonatingSelector(state);
63 const donatableSectionRecentlyCompleted =
64 donatableSectionRecentlyCompletedSelector(state);
65 const isRandomCompletionThreshold =
66 isRandomCompletionThresholdSelector(state);
67
68 // don't request donation if already donating
69 if (isDonating) return false;
70
71 // donations only appear after the user has completed ten challenges (i.e.
72 // not before the 11th challenge has mounted)
73 if (completedChallengeCount < 10) return false;
74
75 // a block or module has been completed
76 if (donatableSectionRecentlyCompleted) return true;
77
78 const sessionChallengeData = getSessionChallengeData();
79 /*
80 Different intervals need to be tested for optimization.
81 */
82 // the assumption is that we save the count when we request donations
83 if (sessionChallengeData.isSaved) {
84 // only request if sufficient challenges have been completed since last
85 // request
86 return sessionChallengeData.countSinceSave >= 20;
87 }
88
89 /*
90 Show modal if user has completed 10 challanged in total
91 and 3 or more in this session.
92 The isRandomCompletionThreshold flag is used to AB test interval randomness
93 */
94 if (isRandomCompletionThreshold) {
95 return sessionChallengeData.currentCount >= randomBetween(3, 7);
96 } else {
97 return sessionChallengeData.currentCount >= 3;
98 }
99};
100
101export const userTokenSelector = state => userSelector(state)?.userToken;
102

Callers

nothing calls this directly

Tested by

no test coverage detected