Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
mirak-oracle authored Jul 16, 2024
1 parent df11d50 commit b104c70
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,52 +345,6 @@ <h2 class="text-2xl mb-4">Wallet</h2>
<button class="task-button mb-4" onclick="showSection('boosterSection')">Boosters</button>
<button class="task-button mb-4" onclick="showSection('squadsSection')">Squads</button>
</div>
<script type="module">
// Firebase initialization code (already included above)

// Function to generate unique user ID
function generateUniqueId() {
return 'xxxxxx'.replace(/[x]/g, () => (Math.random() * 36 | 0).toString(36));
}

// Function to create a new user with a unique ID and initial balance
async function createUser() {
const userId = generateUniqueId();
await setDoc(doc(db, 'users', userId), {
userId,
balance: 0
});

document.getElementById('userId').innerText = `Your User ID is: ${userId}`;
return userId;
}

// Function to get user balance by ID
async function getUserBalance(userId) {
const userRef = doc(db, 'users', userId);
const userDoc = await getDoc(userRef);
if (userDoc.exists()) {
return userDoc.data().balance;
} else {
console.log('No such document!');
return null;
}
}

// Example usage: Create a user and display their ID
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('createUserButton').addEventListener('click', async () => {
const userId = await createUser();
console.log('User created with ID:', userId);
});

document.getElementById('getBalanceButton').addEventListener('click', async () => {
const userId = document.getElementById('userIdInput').value;
const balance = await getUserBalance(userId);
document.getElementById('balance').innerText = `Balance: ${balance}`;
});
});
</script>

<script>
document.addEventListener("DOMContentLoaded", function() {
Expand Down

0 comments on commit b104c70

Please sign in to comment.