dossinstitute / sidequest

Apache License 2.0
0 stars 0 forks source link

[Front End] QuestManager Interaction #20

Open wvwatson opened 5 months ago

wvwatson commented 5 months ago

Front End User Requirements Ticket for QuestManager Interaction

Title: Development of a Web Interface for Interacting with the QuestManager Smart Contract

Description: Create a web interface that allows users to interact with the QuestManager smart contract deployed on the Ethereum blockchain. Users should be able to view available quests, participate in quests, and receive rewards. The interface will use the Ether.js library to communicate with the smart contract.

Acceptance Criteria:

  1. Connectivity:
    • The interface must provide a mechanism for users to connect their Ethereum wallet to the dApp using MetaMask or another compatible wallet.
  2. View Available Quests:
    • Users should be able to view a list of available quests, including their IDs, start times, end times, required interactions, and reward types.
  3. Participate in Quests:
    • Users should be able to select a quest they wish to participate in and confirm their participation.
  4. Quest Status Updates:
    • The interface must display the current status of the quests a user has participated in, including whether they are pending, completed, or failed.
  5. Receive Rewards:
    • Upon successful completion of a quest, the interface should display a notification indicating the reward received, along with the amount and type of reward.
  6. Error Handling:
    • The interface must gracefully handle errors, such as network issues, wallet disconnections, and smart contract reverts, providing clear feedback to the user.
  7. Responsive Design:
    • The interface must be responsive, providing a good user experience across different devices and screen sizes.

HTML and JavaScript Code Example:

Below is a simplified example of how the HTML and JavaScript code could be structured to meet the above requirements. This example assumes familiarity with basic web development concepts and the Ether.js library.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>QuestManager DApp</title>
    <script src="https://cdn.jsdelivr.net/npm/etherjs/dist/etherjs.min.js"></script>
</head>
<body>
    <h1>Welcome to QuestManager</h1>
    <div id="availableQuests"></div>
    <button onclick="participateInQuest()">Participate in a Quest</button>

    <script>
        const provider = new ethers.providers.Web3Provider(window.ethereum);
        const signer = provider.getSigner();
        const questManagerContractAddress = "YOUR_CONTRACT_ADDRESS_HERE";
        const questManagerABI = []; // Replace with actual ABI

        const questManagerContract = new ethers.Contract(questManagerContractAddress, questManagerABI, signer);

        async function loadAvailableQuests() {
            try {
                const quests = await questManagerContract.getQuests(); // Assuming getQuests is a function in your contract
                const questsDiv = document.getElementById('availableQuests');
                quests.forEach(quest => {
                    const questElement = document.createElement('p');
                    questElement.textContent = `Quest ID: ${quest.eventId}, Start Date: ${quest.startDate}, End Date: ${quest.endDate}, Required Interactions: ${quest.requiredInteractions}, Reward Type: ${quest.rewardType}`;
                    questsDiv.appendChild(questElement);
                });
            } catch (error) {
                console.error("Failed to load quests:", error);
            }
        }

        async function participateInQuest() {
            // Implement logic to allow users to select a quest and confirm participation
            // This may involve calling a function in the smart contract to register the user for a quest
        }

        window.addEventListener('load', async () => {
            await loadAvailableQuests();
        });
    </script>
</body>
</html>

This example provides a basic structure for displaying available quests and participating in them. You'll need to replace "YOUR_CONTRACT_ADDRESS_HERE" with the actual address of your deployed QuestManager contract and fill in the questManagerABI array with the ABI of your contract. The participateInQuest function is left as an exercise, as it requires interaction design tailored to your application's needs.

Remember, this is a simplified example. A real-world application would require more robust error handling, user authentication, and a more sophisticated UI/UX design