@@ -10,14 +10,17 @@ import {
10
10
Text ,
11
11
} from "@chakra-ui/react"
12
12
import { FaTwitter } from "react-icons/fa"
13
+ import { useI18next } from "gatsby-plugin-react-i18next"
13
14
14
15
import Button from "../Button"
15
16
import Translation from "../Translation"
16
17
import { TrophyIcon } from "../icons/quiz"
17
18
18
19
import { QuizzesHubContext } from "./context"
19
20
21
+ // Utils
20
22
import {
23
+ getFormattedStats ,
21
24
getNumberOfCompletedQuizzes ,
22
25
getTotalQuizzesPoints ,
23
26
shareOnTwitter ,
@@ -42,24 +45,26 @@ const handleShare = ({ score, total }: QuizShareStats) => {
42
45
}
43
46
44
47
const QuizzesStats : React . FC = ( ) => {
48
+ const { language } = useI18next ( )
45
49
const {
46
50
userStats : { score : userScore , completed, average } ,
47
51
} = useContext ( QuizzesHubContext )
48
52
const numberOfCompletedQuizzes = getNumberOfCompletedQuizzes (
49
53
JSON . parse ( completed )
50
54
)
51
55
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
-
58
56
// These values are not fixed but calculated each time, can't be moved to /constants
59
57
const totalQuizzesNumber =
60
58
ethereumBasicsQuizzes . length + usingEthereumQuizzes . length
61
59
const totalQuizzesPoints = getTotalQuizzesPoints ( )
62
60
61
+ const {
62
+ formattedUserAverageScore,
63
+ formattedCollectiveQuestionsAnswered,
64
+ formattedCollectiveAverageScore,
65
+ formattedCollectiveRetryRate,
66
+ } = getFormattedStats ( language , average )
67
+
63
68
return (
64
69
< Box flex = { 1 } order = { { base : 1 , lg : 2 } } w = "full" >
65
70
< Stack mt = { { base : 0 , lg : 12 } } gap = { { base : 8 , lg : 4 } } >
@@ -127,7 +132,7 @@ const QuizzesStats: React.FC = () => {
127
132
< Text mr = { 10 } mb = { 0 } mt = { { base : 2 , lg : 0 } } color = "bodyMedium" >
128
133
< Translation id = "average-score" /> { " " }
129
134
< Text as = "span" color = "body" >
130
- { parsedAverage } %
135
+ { formattedUserAverageScore }
131
136
</ Text >
132
137
</ Text >
133
138
@@ -165,7 +170,7 @@ const QuizzesStats: React.FC = () => {
165
170
< Translation id = "average-score" />
166
171
</ Text >
167
172
{ /* Data from Matomo, manually updated */ }
168
- < Text color = "body" > 67.4% </ Text >
173
+ < Text color = "body" > { formattedCollectiveAverageScore } </ Text >
169
174
</ Stack >
170
175
171
176
< Stack >
@@ -174,7 +179,10 @@ const QuizzesStats: React.FC = () => {
174
179
</ Text >
175
180
176
181
{ /* 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 >
178
186
</ Stack >
179
187
180
188
< Stack >
@@ -183,7 +191,7 @@ const QuizzesStats: React.FC = () => {
183
191
</ Text >
184
192
185
193
{ /* Data from Matomo, manually updated */ }
186
- < Text color = "body" > 15.6% </ Text >
194
+ < Text color = "body" > { formattedCollectiveRetryRate } </ Text >
187
195
</ Stack >
188
196
</ Flex >
189
197
</ Flex >
0 commit comments