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]
Loading

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]
Loading

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

nullmastermind commented May 21, 2024

Role of Blockchain Developer in Showtime Watch Application

A blockchain developer will play a crucial role in integrating cryptocurrency functionalities into the Showtime Watch application. Below are the specific tasks and responsibilities that a blockchain developer will undertake:

1. Wallet Integration

Tasks:

  • Connect Wallet: Implement functionality to connect users' cryptocurrency wallets (e.g., MetaMask for Ethereum, Phantom for Solana).
  • Wallet Address Validation: Ensure that the wallet addresses provided by users are valid and correctly formatted.
  • Wallet Connection UI: Develop user interfaces for connecting and displaying wallet information.

Technologies:

  • Web3.js or Ethers.js for Ethereum
  • Solana Web3.js for Solana
  • React for UI components

2. Wallet Reset Functionality

Tasks:

  • Generate Reset Codes: Create secure reset codes for users who need to reset their wallet connections.
  • Email Integration: Implement email functionality to send reset codes to users.
  • Reset Code Validation: Validate reset codes and allow users to securely reset their wallet connections.

Technologies:

  • Node.js for backend logic
  • Nodemailer for sending emails
  • Next.js API Routes for handling reset requests

3. Transaction Management

Tasks:

  • Initiate Transactions: Develop functionality to initiate and manage cryptocurrency transactions for preorders.
  • Transaction Status: Implement features to check and display the status of transactions.
  • Security: Ensure that all transactions are secure and verifiable.

Technologies:

  • Web3.js or Ethers.js for Ethereum transactions
  • Solana Web3.js for Solana transactions
  • Next.js API Routes for transaction management

4. Smart Contract Interaction

Tasks:

  • Deploy Smart Contracts: If required, deploy smart contracts for handling specific functionalities like preorder deposits or referral rewards.
  • Interact with Smart Contracts: Implement functionality to interact with deployed smart contracts.

Technologies:

  • Solidity for Ethereum smart contracts
  • Rust for Solana smart contracts
  • Truffle or Hardhat for Ethereum development
  • Anchor for Solana development

5. Security and Best Practices

Tasks:

  • Secure Storage: Ensure that sensitive information like private keys and reset codes are securely stored.
  • Data Encryption: Implement encryption for sensitive data.
  • Audit: Conduct security audits to identify and fix vulnerabilities.

Technologies:

  • bcrypt for hashing passwords
  • AES for data encryption
  • OpenZeppelin for security best practices in smart contracts

6. Testing and QA

Tasks:

  • Unit Testing: Write unit tests for blockchain-related functionalities.
  • Integration Testing: Ensure that the blockchain features integrate seamlessly with the rest of the application.
  • End-to-End Testing: Conduct end-to-end tests to ensure the entire user flow works as expected.

Technologies:

  • Jest for unit testing
  • Cypress for end-to-end testing

7. Documentation

Tasks:

  • API Documentation: Document all API endpoints related to blockchain functionalities.
  • User Guides: Create user guides for connecting wallets, resetting wallets, and managing transactions.
  • Developer Documentation: Provide detailed documentation for other developers to understand and contribute to the blockchain features.

Technologies:

  • Swagger for API documentation
  • Markdown for user and developer guides

Development Plan for Blockchain Developer

Week 1-2:

  • Set up development environment.
  • Implement wallet connection functionality.
  • Develop UI components for wallet connection.

Week 3-4:

  • Implement wallet reset functionality.
  • Integrate email service for sending reset codes.
  • Develop UI components for wallet reset.

Week 5-6:

  • Implement transaction management.
  • Develop API routes for initiating and checking transactions.
  • Ensure security best practices are followed.

Week 7-8:

  • Deploy and interact with smart contracts (if required).
  • Conduct unit and integration testing.
  • Fix any identified issues.

Week 9:

  • Finalize documentation.
  • Conduct end-to-end testing.
  • Prepare for deployment.

Week 10:

  • Assist in deployment.
  • Monitor and fix any post-deployment issues.

@nullmastermind
Copy link
Author

Potential Issues During Development and Mitigation Strategies

1. Wallet Integration Issues

Potential Issues:

  • Compatibility: Different wallets (e.g., MetaMask, Phantom) may have different APIs and integration methods.
  • User Experience: Users may find it difficult to connect their wallets due to complex steps or unclear instructions.
  • Security: Ensuring secure wallet connections and preventing unauthorized access.

Mitigation Strategies:

  • Thorough Documentation: Follow the official documentation of each wallet provider.
  • User Guides: Provide clear and concise user guides and tooltips within the application.
  • Security Audits: Regularly conduct security audits and use well-established libraries like Web3.js or Ethers.js.

2. Wallet Reset Functionality

Potential Issues:

  • Email Delivery: Emails containing reset codes may end up in spam folders or may not be delivered at all.
  • Code Expiry: Users may not use the reset code within the stipulated time, leading to expired codes.
  • Security: Ensuring that reset codes are not easily guessable and are securely stored.

Mitigation Strategies:

  • Reliable Email Service: Use a reliable email service provider like SendGrid or AWS SES.
  • User Notifications: Notify users about the expiry time of reset codes and provide an easy way to request a new code.
  • Secure Code Generation: Use secure random number generators and store reset codes in an encrypted format.

3. Transaction Management

Potential Issues:

  • Network Congestion: High network congestion can lead to delayed or failed transactions.
  • Transaction Fees: Users may be unaware of transaction fees, leading to failed transactions due to insufficient funds.
  • Transaction Status: Difficulty in tracking and displaying the real-time status of transactions.

Mitigation Strategies:

  • User Notifications: Inform users about potential delays and transaction fees upfront.
  • Retry Mechanism: Implement a retry mechanism for failed transactions.
  • Real-time Updates: Use WebSocket or polling to provide real-time updates on transaction status.

4. Smart Contract Interaction

Potential Issues:

  • Deployment Errors: Errors during the deployment of smart contracts.
  • Contract Bugs: Bugs in smart contracts can lead to loss of funds or incorrect behavior.
  • Upgradability: Difficulty in upgrading smart contracts once deployed.

Mitigation Strategies:

  • Testing: Thoroughly test smart contracts using frameworks like Truffle or Hardhat.
  • Audits: Conduct security audits using tools like MythX or engage third-party auditors.
  • Proxy Contracts: Use proxy contracts to enable upgradability.

5. Security Concerns

Potential Issues:

  • Data Breaches: Unauthorized access to sensitive user data.
  • Phishing Attacks: Users may fall victim to phishing attacks targeting their wallet credentials.
  • Code Vulnerabilities: Vulnerabilities in the codebase that can be exploited.

Mitigation Strategies:

  • Encryption: Encrypt sensitive data both at rest and in transit.
  • User Education: Educate users about phishing attacks and how to recognize them.
  • Code Reviews: Conduct regular code reviews and use static analysis tools to identify vulnerabilities.

6. Performance and Scalability

Potential Issues:

  • Load Handling: The application may struggle to handle a large number of concurrent users.
  • Database Performance: Slow database queries can lead to poor user experience.
  • API Rate Limits: Hitting API rate limits of third-party services.

Mitigation Strategies:

  • Load Testing: Conduct load testing to identify and address performance bottlenecks.
  • Database Optimization: Optimize database queries and use indexing where necessary.
  • Caching: Implement caching strategies to reduce load on the database and third-party APIs.

7. Integration and Deployment

Potential Issues:

  • Environment Differences: Differences between development, staging, and production environments can lead to unexpected issues.
  • Deployment Failures: Failures during the deployment process can lead to downtime.
  • Rollback: Difficulty in rolling back to a previous stable state in case of issues.

Mitigation Strategies:

  • CI/CD Pipeline: Set up a robust CI/CD pipeline to automate testing and deployment.
  • Environment Parity: Ensure that development, staging, and production environments are as similar as possible.
  • Backup and Rollback: Implement backup and rollback strategies to quickly revert to a stable state if needed.

8. User Experience

Potential Issues:

  • Complexity: Users may find the process of connecting wallets and managing transactions too complex.
  • Accessibility: The application may not be accessible to users with disabilities.
  • Localization: Users from different regions may face language barriers.

Mitigation Strategies:

  • Simplified UI: Design a user-friendly and intuitive interface.
  • Accessibility Testing: Conduct accessibility testing and follow best practices for accessibility.
  • Localization: Implement localization to support multiple languages.

@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