Skip to content

Conversation

@Anthonyushie
Copy link

Summary

This PR introduces two major enhancements to the Tic-Tac-Toe game:

  1. Co-operative Undo Feature: A player can now request to undo their last move. The opponent must approve this request on-chain for the move to be
    reverted.
  2. Automatic UI Refresh: The application now waits for transactions to be confirmed on the blockchain and automatically reloads the page, providing a
    much smoother user experience.

Changes Implemented

✨ Features

  • Smart Contract:
    • Added request-undo and approve-undo functions to the tic-tac-toe.clar contract.
    • Extended the game state to track undo requests and the last move position.
  • Frontend:
    • Added a "Request Undo" button that appears for the player who just moved.
    • Added a notification UI for the opponent to approve a pending undo request.
    • Implemented a waitForTransaction utility that polls the blockchain for transaction confirmation and integrated it into all game actions.
  • Tests:
    • Added a new test suite for the undo feature, covering the success path, implicit denial, and security checks.
    • Updated existing tests to align with the new contract state.

🔧 Fixes

  • Resolved a Server-Side Rendering (SSR) crash by moving client-side initializations into the useStacks hook.
  • Fixed a console warning caused by NaN values by making number-parsing utilities more robust.

How to Test

  1. Start a game between two players (using two different wallet accounts).
  2. With Player 1, make a move and confirm the transaction.
  3. The UI will show a "waiting for confirmation" message and then automatically reload the page.
  4. As Player 1, you should now see a "Request Undo" button. Click it and confirm the transaction.
  5. The page will again auto-reload.
  6. Switch to Player 2's account in your wallet. On the web page, Disconnect and Reconnect with Player 2's account.
  7. As Player 2, you will see a yellow notification box asking you to approve the undo.
  8. Click "Approve Undo" and confirm the transaction.
  9. Once the page reloads, verify that Player 1's last move was successfully removed from the board and that it is Player 1's turn again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant