Skip to content

Instantly share code, notes, and snippets.

@nullmastermind
Last active May 21, 2024 08:58
Show Gist options
  • Save nullmastermind/ab7f246dacba19acafc1c21b7bbb9028 to your computer and use it in GitHub Desktop.
Save nullmastermind/ab7f246dacba19acafc1c21b7bbb9028 to your computer and use it in GitHub Desktop.
adnkasdnk

Showtime Watch Application

1. Purpose

The Showtime Watch application is designed to facilitate the preorder and management of a smartwatch that integrates with cryptocurrency wallets. It includes features such as a leaderboard, profile management, and wallet connection/reset functionalities.

2. Roles

  • User: Can preorder the watch, manage their profile, connect/reset their wallet, and view the leaderboard.
  • Admin: Manages user data, orders, and leaderboard entries (not explicitly mentioned but implied for backend management).

3. User Flow for Each Role

User Flow:

graph TD
    A[Home] --> B[Login]
    B --> C[Profile]
    C --> D[Connect Wallet]
    D --> E[Preorder]
    E --> F[Order Confirmation]
    F --> G[Leaderboard]
    G --> H[View Ranking]
    H --> I[Logout]

Admin Flow:

graph TD
    A[Admin Login] --> B[Dashboard]
    B --> C[Manage Users]
    B --> D[Manage Orders]
    B --> E[Manage Leaderboard]
    C --> F[View/Edit User Profiles]
    D --> G[View/Edit Orders]
    E --> H[Update Leaderboard]
    H --> I[Logout]

4. Database Schema

Users Table

  • id (UUID)
  • email (VARCHAR)
  • username (VARCHAR)
  • password (HASH)
  • wallet_address (VARCHAR)
  • created_at (TIMESTAMP)
  • updated_at (TIMESTAMP)

Orders Table

  • id (UUID)
  • user_id (UUID, FK)
  • order_id (VARCHAR)
  • watch_id (VARCHAR)
  • referral_code (VARCHAR)
  • created_at (TIMESTAMP)
  • updated_at (TIMESTAMP)

Leaderboard Table

  • id (UUID)
  • user_id (UUID, FK)
  • ranking (INT)
  • referrals (INT)
  • created_at (TIMESTAMP)
  • updated_at (TIMESTAMP)

Wallet Resets Table

  • id (UUID)
  • user_id (UUID, FK)
  • reset_code (VARCHAR)
  • created_at (TIMESTAMP)
  • expires_at (TIMESTAMP)

5. Frontend UI

List Pages

  • Home
  • Leaderboard
  • Profile
  • Preorder

CRUD Forms

  • Profile Management (Create/Update)
  • Wallet Connection/Reset
  • Preorder Form

Data Validation

  • Email validation
  • Password strength
  • Wallet address format
  • Referral code format

React Components

  • HomePage
  • LeaderboardPage
  • ProfilePage
  • PreorderPage
  • LoginForm
  • ProfileForm
  • WalletConnectForm
  • WalletResetForm
  • OrderConfirmation
  • LeaderboardEntry
  • ReferralCodeInput

6. Backend API List

User APIs

  • POST /api/login - { email, password }
  • POST /api/register - { email, username, password }
  • GET /api/profile - { user_id }
  • PUT /api/profile - { user_id, email, username, wallet_address }
  • POST /api/wallet/connect - { user_id, wallet_address }
  • POST /api/wallet/reset - { email }
  • GET /api/wallet/reset/:reset_code - { reset_code }

Order APIs

  • POST /api/preorder - { user_id, watch_id, referral_code }
  • GET /api/orders - { user_id }

Leaderboard APIs

  • GET /api/leaderboard - { }
  • GET /api/leaderboard/:user_id - { user_id }

7. Time Estimates and Quoting

Feature Breakdown

  • User Authentication: 20 hours
  • Profile Management: 30 hours
  • Wallet Connection/Reset: 25 hours
  • Preorder System: 40 hours
  • Leaderboard: 35 hours
  • Frontend Development: 60 hours
  • Backend Development: 50 hours
  • Testing and QA: 30 hours

Total Estimate: 290 hours

8. Feature Prioritization

  1. User Authentication: Essential for access control.
  2. Profile Management: Allows users to manage their information.
  3. Wallet Connection/Reset: Critical for cryptocurrency integration.
  4. Preorder System: Core functionality for sales.
  5. Leaderboard: Enhances user engagement.
  6. Frontend Development: User interface and experience.
  7. Backend Development: Server-side logic and database management.
  8. Testing and QA: Ensures reliability and performance.
@nullmastermind
Copy link
Author

Solidity Smart Contract for Showtime Watch Preorders

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ShowtimeWatchPreorder {
    // Struct to store preorder details
    struct Preorder {
        address user;
        uint256 amount;
        string referralCode;
        bool fulfilled;
    }

    // Mapping to store preorders by order ID
    mapping(uint256 => Preorder) public preorders;
    // Mapping to store referral codes and their usage count
    mapping(string => uint256) public referralUsage;

    // Counter for generating unique order IDs
    uint256 public orderCounter;

    // Event to log new preorders
    event NewPreorder(uint256 orderId, address indexed user, uint256 amount, string referralCode);

    // Event to log preorder fulfillment
    event PreorderFulfilled(uint256 orderId);

    // Function to place a preorder
    function placePreorder(string memory referralCode) public payable {
        require(msg.value > 0, "Preorder amount must be greater than zero");

        // Increment the order counter
        orderCounter++;

        // Create a new preorder
        preorders[orderCounter] = Preorder({
            user: msg.sender,
            amount: msg.value,
            referralCode: referralCode,
            fulfilled: false
        });

        // Increment the usage count of the referral code
        referralUsage[referralCode]++;

        // Emit the NewPreorder event
        emit NewPreorder(orderCounter, msg.sender, msg.value, referralCode);
    }

    // Function to fulfill a preorder
    function fulfillPreorder(uint256 orderId) public {
        Preorder storage preorder = preorders[orderId];
        require(preorder.user != address(0), "Preorder does not exist");
        require(!preorder.fulfilled, "Preorder already fulfilled");

        // Mark the preorder as fulfilled
        preorder.fulfilled = true;

        // Emit the PreorderFulfilled event
        emit PreorderFulfilled(orderId);
    }

    // Function to check the status of a preorder
    function checkPreorderStatus(uint256 orderId) public view returns (bool) {
        Preorder storage preorder = preorders[orderId];
        require(preorder.user != address(0), "Preorder does not exist");

        return preorder.fulfilled;
    }

    // Function to withdraw funds (only owner)
    address public owner;

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the owner can call this function");
        _;
    }

    constructor() {
        owner = msg.sender;
    }

    function withdrawFunds() public onlyOwner {
        payable(owner).transfer(address(this).balance);
    }
}

Explanation

  1. Structs and Mappings:

    • Preorder: A struct to store details of each preorder.
    • preorders: A mapping to store preorders by their unique order ID.
    • referralUsage: A mapping to store the usage count of each referral code.
  2. Events:

    • NewPreorder: Emitted when a new preorder is placed.
    • PreorderFulfilled: Emitted when a preorder is fulfilled.
  3. Functions:

    • placePreorder: Allows users to place a preorder by sending Ether and optionally providing a referral code.
    • fulfillPreorder: Allows the contract owner to mark a preorder as fulfilled.
    • checkPreorderStatus: Allows users to check the status of their preorder.
    • withdrawFunds: Allows the contract owner to withdraw funds from the contract.
  4. Modifiers:

    • onlyOwner: Ensures that only the contract owner can call certain functions.
  5. Constructor:

    • Sets the contract deployer as the owner.

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