Skip to content

Commit 6f43173

Browse files
TweyTudorEsan
andauthored
Fail submission in the UI if an error occurs (#50)
## Motivation Currently submissions seem to succeed if submission fails, but actually silently don't go through. ## Proposal Display an error in the UI if an error occurs in the code during submission. ## Test Plan Manually tested (by injecting an error into `LineraService.submitSolution`). Co-authored-by: Tudor Eșan <[email protected]>
1 parent 49ba9ce commit 6f43173

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

frontend/src/lib/game-of-life/hooks/usePuzzleGame.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@ export function usePuzzleGame() {
155155
throw new Error(validationResult.errorMessage || "Solution is not valid");
156156
}
157157

158-
return lineraService.submitSolution(currentPuzzle.id, board);
158+
const result = await lineraService.submitSolution(currentPuzzle.id, board);
159+
160+
if (!result) {
161+
setValidationResult({ isValid: false, message: "Incorrect solution, try again" });
162+
} else {
163+
setValidationResult({ isValid: true, message: "Solution submitted successfully!" });
164+
}
165+
166+
return result;
159167
},
160168
onSuccess: () => {
161-
setValidationResult({
162-
isValid: true,
163-
message: "Solution submitted successfully!",
164-
});
165169
// Invalidate queries to refresh completion status from blockchain
166170
queryClient.invalidateQueries({ queryKey: ["completedPuzzles"] });
167171
queryClient.invalidateQueries({
@@ -222,7 +226,7 @@ export function usePuzzleGame() {
222226
const loadNextPuzzle = useCallback(() => {
223227
if (!currentPuzzleId) return false;
224228

225-
const currentIndex = KNOWN_PUZZLES.findIndex(p => p.id === currentPuzzleId);
229+
const currentIndex = KNOWN_PUZZLES.findIndex((p) => p.id === currentPuzzleId);
226230
if (currentIndex === -1) return false;
227231

228232
// Get next puzzle (cycle to beginning if at end)
@@ -239,7 +243,7 @@ export function usePuzzleGame() {
239243
const loadPreviousPuzzle = useCallback(() => {
240244
if (!currentPuzzleId) return false;
241245

242-
const currentIndex = KNOWN_PUZZLES.findIndex(p => p.id === currentPuzzleId);
246+
const currentIndex = KNOWN_PUZZLES.findIndex((p) => p.id === currentPuzzleId);
243247
if (currentIndex === -1) return false;
244248

245249
// Get previous puzzle (cycle to end if at beginning)

0 commit comments

Comments
 (0)