-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add back reverted quizzes: run-a-node, scaling, solo staking #11960
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. Marking this as blocked after testing.
While this does not crash as it did before (#10828), it does not update the stats correctly.
======
How to reproduce error:
- Go to /quizzes
- Open the devtools and manually set the following user stats in localstorage (tab Application):
This will simulate a user that has already used the quizzes.
key: quizzes-stats
value: {"score":3,"average":[60],"completed":"{\"what-is-ethereum\":[false,0],\"what-is-ether\":[false,0],\"web3\":[false,0],\"wallets\":[false,0],\"security\":[false,0],\"nfts\":[false,3],\"layer-2\":[false,0],\"merge\":[false,0]}"}
- Reload the page
- Make the "Run a node" quiz
- After you finish the quiz, notice that the stats are not updated
cc @TylerAPfledderer pinging you in case you have any idea of what might be happening
initialize "completed" to empty object, and add score fallback if not yet taken
@pettinarip I was able to get this working by setting a fallback value when setting Of note, I did have issues with the exact string you pasted for testing, as it contains escaped characters. Did you copy this directly from your ls? When I go to https://ethereum.org/quizzes with a cleared locale storage, I do not get this type of string on my end (it populates without the escapes):
If I go to https://ethereum.org/quizzes, and paste in the locale storage directly from above, I get this: |
Separately, while debugging this I ended up improving the type-safety on all of these Quiz components while trying to figure out what was going on... in the end, it was not necessary for this fix, but since the work was done I went ahead and posted this in a separate PR, #11992 |
@wackerow @pettinarip I'm seeing a completely different issue with the local storage. If I clear my local storage, and do a quiz in the quiz hub through this PR's preview deploy, I see this data structure: This happened if I did the same thing on the Run A Node page. |
@TylerAPfledderer I tested it in FF and it worked fine for me. Does the quiz still work? could it just be a devtool issue? Seems that it detects that |
@wackerow nice! tested it again and it worked fine! gj. Regarding the encoding issue, this is interesting. So, I might have some pretty old quiz data in my localstorage (must be from the first version of the quiz hub logic). I guess we encoded that part differently back then. Now we are not doing that anymore, so I guess its better now! |
*/ | ||
const INITIAL_COMPLETED_QUIZZES: CompletedQuizzes = Object.keys( | ||
allQuizzesData | ||
).reduce((object, key) => ({ ...object, [key]: [false, 0] }), {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. We don't need to initialize everything. Simpler, I like it.
const lastScore = prevStats.completed[quizKey][1] | ||
const { completed } = prevStats | ||
const hasResultsSaved = !!completed[quizKey] | ||
const lastScore = hasResultsSaved ? prevStats.completed[quizKey][1] : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
While testing it again, I was able to reproduce Tyler's bug/issue. So, the encoded data version generates the problem described by Tyler and as a result shows the wrong I'm not sure how we could elegantly fix this by supporting both versions: the encoded (old) and the decoded one (new). Perhaps we would need to add new check to detect if the previous data is encoded and decode it, and then continue with the normal flow. |
// If the user has an old version of the app, convert the | ||
// `completed` value from a string to an object. | ||
const [current, setCurrent] = data | ||
if (typeof current.completed === "string") { | ||
const newCompleted = JSON.parse(current.completed) | ||
setCurrent({ ...current, completed: newCompleted }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pettinarip @TylerAPfledderer This should fix the issues with the escaped strings for the completed
value. This was happening because the completed
object was being stringified inside a parent also being stringified.
This simply checks if .completed
is of string
type, and if it is, parses it and re-assigns as an object
to the locale storage value.
// If "current" value looks like this:
{"score":3,"average":[60],"completed":"{\"what-is-ethereum\":[false,0],\"what-is-ether\":[false,0],\"web3\":[false,0],\"wallets\":[false,0],\"security\":[false,0],\"nfts\":[false,3],\"layer-2\":[false,0],\"merge\":[false,0]}"}
// ...this code block will convert it to this:
{"score":3,"average":[60],"completed":{"what-is-ethereum":[false,0],"what-is-ether":[false,0],"web3":[false,0],"wallets":[false,0],"security":[false,0],"nfts":[false,3],"layer-2":[false,0],"merge":[false,0]}}
Just need to double check no edge cases if we have this local storage data and then take a stand-alone quiz, but hopefully this fixes the backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! yeah, I guess we will be forced to do this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's fixed on my end!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might also help with the setup with the QuizManager
waiting to come online (To have the quiz components isolated and to be supplied separate groups of quiz data) as well as that issue where adding quizzes or quiz questions to the data set compromised existing user stats and throwing id errors.
Does this help with the later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix should take care of compatibility issues when adding new quizzes to the data set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! working fine now for me with old and new data structures 💪🏼
@wackerow @pettinarip I would like to note here for future design consideration that with the standalone pages, maybe have a way to show the user they already completed the quiz with 100%? Maybe a separate visual that is similar to the summary component? |
Yeah, I like that idea... cc: @nloureiro ^ |
Do you understand the idea is to save the user's last interaction on a specific page? Regardless if he refreshes the page.
is that it? |
That's correct, instead of the quiz always starting over on refresh |
Description
Three quizzes were previously added, which surfaced some bugs requiring them to be reverted:
This PR re-adds the above quizzes now that the underlying bugs have been fixed.
Small note, renamed the
run-a-node
keys to usel
instead ofi
to prevent a future conflict with #11884Preview links