Data collected/recorded incorrectly (PsychoJS issue?)

URL of experiment:

Description of the problem:
I created a task using Builder where a participant is choosing between a “hard” or “easy” version of the same task (repeatedly pressing a key on the keyboard to fill up a bar on the screen before time runs out) for varying amounts of reward. For the most part, it runs smoothly online.

The issue is that for certain trials, the participant fails the trial (reach correct amount of key presses in time), but the screen still displays “You’ve won: $1.00” or whatever the reward is for that trial. This does not happen for all failed trials, sometimes it moves on to the next trial as intended. This has never occurred in the Builder version, and I failed to recreate the error when I went through the task online but it has still been occurring for participants.

I coded some of the JS myself in code components in Builder, as the translate option was not working for certain aspects of the task, and I imagine the error is somewhere in the JS code. The file is “beheefrt_online_v02.js” in the repository, and most relevant lines are 4247-4701, although the issue could be somewhere else. If anyone has any suggestions I would really appreciate it. Thank you!

Of note:
In looking at the data files, I found that “completed” was correctly collected/recorded as 0, meaning the participant failed the trial. However, a second variable, called “earnings,” is not changing to 0 as it should, which means somewhere in between the trial and feedback routines, “completed” is switching back to 1, and the reward amount is displayed when it shouldn’t be. However, I cannot figure out why hence the post

An example of this is highlighted below