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 7c521ca commit d411589
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,106 @@
<meta charset="UTF-8">
<title>CosmicCoin Mining Airdrop</title>

<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-app.js";
import { getDatabase, ref, set, get, child } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-database.js";

// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyATv7chgdEMai84XTHd8-0Fn1egfMS5544",
authDomain: "wapchat-729b9.firebaseapp.com",
projectId: "wapchat-729b9",
storageBucket: "wapchat-729b9.appspot.com",
messagingSenderId: "1093385518195",
appId: "1:1093385518195:web:8f866098ec96c9242a8b7d",
measurementId: "G-V2KBXHFY2D"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
</script>


<script type="module">
// Initialize Firebase and Database (reuse the code from above)
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-app.js";
import { getDatabase, ref, set, get, child } from "https://www.gstatic.com/firebasejs/10.12.3/firebase-database.js";

const firebaseConfig = {
apiKey: "AIzaSyATv7chgdEMai84XTHd8-0Fn1egfMS5544",
authDomain: "wapchat-729b9.firebaseapp.com",
projectId: "wapchat-729b9",
storageBucket: "wapchat-729b9.appspot.com",
messagingSenderId: "1093385518195",
appId: "1:1093385518195:web:8f866098ec96c9242a8b7d",
measurementId: "G-V2KBXHFY2D"
};

const app = initializeApp(firebaseConfig);
const database = getDatabase(app);

// Generate a Unique User ID
function generateUserId() {
return 'user_' + Math.random().toString(36).substr(2, 9);
}

// Store User Data
async function storeUserData(userId, balance) {
try {
await set(ref(database, 'users/' + userId), {
userId: userId,
balance: balance
});
console.log('User data stored successfully');
} catch (error) {
console.error('Error storing user data:', error);
}
}

// Get User Data
async function getUserData(userId) {
try {
const dbRef = ref(database);
const snapshot = await get(child(dbRef, `users/${userId}`));
if (snapshot.exists()) {
return snapshot.val();
} else {
console.log('No data available');
return null;
}
} catch (error) {
console.error('Error getting user data:', error);
return null;
}
}

// Check if userId exists in localStorage, otherwise generate and store it
let userId = localStorage.getItem('userId');
if (!userId) {
userId = generateUserId();
localStorage.setItem('userId', userId);
storeUserData(userId, 0); // Initial balance is 0
}

// Example Usage
async function exampleUsage() {
console.log('Your User ID:', userId);

// Store balance (update as needed)
await storeUserData(userId, 100); // Set balance to 100 for example

// Retrieve balance
const userData = await getUserData(userId);
if (userData) {
console.log('User Balance:', userData.balance);
}
}

exampleUsage();

</script>



Expand Down

0 comments on commit d411589

Please sign in to comment.