11/* eslint-disable react/prop-types */
22import React , { useEffect , useState } from 'react' ;
33import PropTypes from 'prop-types' ;
4- import { camelCaseObject , getConfig } from '@edx/frontend-platform' ;
4+ import { getConfig } from '@edx/frontend-platform' ;
55import { sendTrackEvent } from '@edx/frontend-platform/analytics' ;
6- import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
76import { FormattedMessage , useIntl } from '@edx/frontend-platform/i18n' ;
87import { Lightbulb , MoneyFilled } from '@openedx/paragon/icons' ;
98import {
@@ -16,7 +15,12 @@ import { useModel } from '../../generic/model-store';
1615import StreakMobileImage from './assets/Streak_mobile.png' ;
1716import StreakDesktopImage from './assets/Streak_desktop.png' ;
1817import messages from './messages' ;
19- import { recordModalClosing , recordStreakCelebration } from './utils' ;
18+ import {
19+ calculateVoucherDiscountPercentage ,
20+ getDiscountCodePercentage ,
21+ recordModalClosing ,
22+ recordStreakCelebration ,
23+ } from './utils' ;
2024
2125function getRandomFactoid ( intl , streakLength ) {
2226 const boldedSectionA = intl . formatMessage ( messages . streakFactoidABoldedSection ) ;
@@ -42,36 +46,6 @@ function getRandomFactoid(intl, streakLength) {
4246 return factoids [ Math . floor ( Math . random ( ) * ( factoids . length ) ) ] ;
4347}
4448
45- async function calculateVoucherDiscountPercentage ( voucher , sku , username ) {
46- const urlBase = `${ getConfig ( ) . ECOMMERCE_BASE_URL } /api/v2/baskets/calculate` ;
47- const url = `${ urlBase } /?code=${ voucher } &sku=${ sku } &username=${ username } ` ;
48-
49- const result = await getAuthenticatedHttpClient ( ) . get ( url ) ;
50- const { totalInclTax, totalInclTaxExclDiscounts } = camelCaseObject ( result ) . data ;
51-
52- if ( totalInclTaxExclDiscounts && totalInclTax !== totalInclTaxExclDiscounts ) {
53- // Just store the percent (rather than using these values directly), because ecommerce doesn't give us
54- // the currency symbol to use, so we want to use the symbol that LMS gives us. And I don't want to assume
55- // ecommerce's currency is the same as the LMS. So we'll keep using the values in verifiedMode, just
56- // multiplied by the calculated percentage.
57- return 1 - totalInclTax / totalInclTaxExclDiscounts ;
58- }
59-
60- return 0 ;
61- }
62-
63- async function getDiscountCodePercentage ( code , courseId ) {
64- const params = new URLSearchParams ( ) ;
65- params . append ( 'code' , code ) ;
66- params . append ( 'course_run_key' , courseId ) ;
67- const url = `${ getConfig ( ) . DISCOUNT_CODE_INFO_URL } ?${ params . toString ( ) } ` ;
68-
69- const result = await getAuthenticatedHttpClient ( ) . get ( url ) ;
70- const { isApplicable, discountPercentage } = camelCaseObject ( result ) . data ;
71-
72- return isApplicable ? + discountPercentage : 0 ;
73- }
74-
7549const CloseText = ( { intl } ) => (
7650 < span >
7751 { intl . formatMessage ( messages . streakButton ) }
0 commit comments