@@ -10,14 +10,17 @@ import {
1010 Text ,
1111} from "@chakra-ui/react"
1212import { FaTwitter } from "react-icons/fa"
13+ import { useI18next } from "gatsby-plugin-react-i18next"
1314
1415import Button from "../Button"
1516import Translation from "../Translation"
1617import { TrophyIcon } from "../icons/quiz"
1718
1819import { QuizzesHubContext } from "./context"
1920
21+ // Utils
2022import {
23+ getFormattedStats ,
2124 getNumberOfCompletedQuizzes ,
2225 getTotalQuizzesPoints ,
2326 shareOnTwitter ,
@@ -42,24 +45,26 @@ const handleShare = ({ score, total }: QuizShareStats) => {
4245}
4346
4447const QuizzesStats : React . FC = ( ) => {
48+ const { language } = useI18next ( )
4549 const {
4650 userStats : { score : userScore , completed, average } ,
4751 } = useContext ( QuizzesHubContext )
4852 const numberOfCompletedQuizzes = getNumberOfCompletedQuizzes (
4953 JSON . parse ( completed )
5054 )
5155
52- const computedAverage =
53- average . length > 0 ? average . reduce ( ( a , b ) => a + b , 0 ) / average . length : 0
54- const parsedAverage = Number . isInteger ( computedAverage )
55- ? computedAverage
56- : computedAverage . toFixed ( 2 )
57-
5856 // These values are not fixed but calculated each time, can't be moved to /constants
5957 const totalQuizzesNumber =
6058 ethereumBasicsQuizzes . length + usingEthereumQuizzes . length
6159 const totalQuizzesPoints = getTotalQuizzesPoints ( )
6260
61+ const {
62+ formattedUserAverageScore,
63+ formattedCollectiveQuestionsAnswered,
64+ formattedCollectiveAverageScore,
65+ formattedCollectiveRetryRate,
66+ } = getFormattedStats ( language , average )
67+
6368 return (
6469 < Box flex = { 1 } order = { { base : 1 , lg : 2 } } w = "full" >
6570 < Stack mt = { { base : 0 , lg : 12 } } gap = { { base : 8 , lg : 4 } } >
@@ -127,7 +132,7 @@ const QuizzesStats: React.FC = () => {
127132 < Text mr = { 10 } mb = { 0 } mt = { { base : 2 , lg : 0 } } color = "bodyMedium" >
128133 < Translation id = "average-score" /> { " " }
129134 < Text as = "span" color = "body" >
130- { parsedAverage } %
135+ { formattedUserAverageScore }
131136 </ Text >
132137 </ Text >
133138
@@ -165,7 +170,7 @@ const QuizzesStats: React.FC = () => {
165170 < Translation id = "average-score" />
166171 </ Text >
167172 { /* Data from Matomo, manually updated */ }
168- < Text color = "body" > 67.4% </ Text >
173+ < Text color = "body" > { formattedCollectiveAverageScore } </ Text >
169174 </ Stack >
170175
171176 < Stack >
@@ -174,7 +179,10 @@ const QuizzesStats: React.FC = () => {
174179 </ Text >
175180
176181 { /* Data from Matomo, manually updated */ }
177- < Text color = "body" > 100 000+</ Text >
182+ < Text color = "body" >
183+ { formattedCollectiveQuestionsAnswered }
184+ < Text as = "span" > +</ Text >
185+ </ Text >
178186 </ Stack >
179187
180188 < Stack >
@@ -183,7 +191,7 @@ const QuizzesStats: React.FC = () => {
183191 </ Text >
184192
185193 { /* Data from Matomo, manually updated */ }
186- < Text color = "body" > 15.6% </ Text >
194+ < Text color = "body" > { formattedCollectiveRetryRate } </ Text >
187195 </ Stack >
188196 </ Flex >
189197 </ Flex >
0 commit comments