Spaces:
Running
Running
Upload script.js
Browse files
script.js
CHANGED
|
@@ -48,11 +48,11 @@ function handleLogin(e) {
|
|
| 48 |
const username = document.getElementById("loginUsername").value
|
| 49 |
const password = document.getElementById("loginPassword").value
|
| 50 |
|
| 51 |
-
const users = JSON.parse(localStorage.getItem("
|
| 52 |
|
| 53 |
if (users[username] && users[username].password === password) {
|
| 54 |
currentUser = username
|
| 55 |
-
localStorage.setItem("
|
| 56 |
showNotification("Login successful!", "success")
|
| 57 |
setTimeout(() => {
|
| 58 |
window.location.href = "dashboard.html"
|
|
@@ -75,7 +75,7 @@ function handleRegister(e) {
|
|
| 75 |
return
|
| 76 |
}
|
| 77 |
|
| 78 |
-
const users = JSON.parse(localStorage.getItem("
|
| 79 |
|
| 80 |
if (users[username]) {
|
| 81 |
showNotification("Username already exists!", "error")
|
|
@@ -90,7 +90,7 @@ function handleRegister(e) {
|
|
| 90 |
createdAt: new Date().toISOString(),
|
| 91 |
}
|
| 92 |
|
| 93 |
-
localStorage.setItem("
|
| 94 |
showNotification("Account created successfully!", "success")
|
| 95 |
|
| 96 |
setTimeout(() => {
|
|
@@ -100,7 +100,7 @@ function handleRegister(e) {
|
|
| 100 |
|
| 101 |
// Dashboard functions
|
| 102 |
function initDashboard() {
|
| 103 |
-
currentUser = localStorage.getItem("
|
| 104 |
|
| 105 |
if (!currentUser) {
|
| 106 |
window.location.href = "index.html"
|
|
@@ -108,14 +108,10 @@ function initDashboard() {
|
|
| 108 |
}
|
| 109 |
|
| 110 |
updateDashboard()
|
| 111 |
-
initTradingChart()
|
| 112 |
-
|
| 113 |
-
// Update BTC price periodically
|
| 114 |
-
setInterval(updateBTCPrice, 5000)
|
| 115 |
}
|
| 116 |
|
| 117 |
function updateDashboard() {
|
| 118 |
-
const users = JSON.parse(localStorage.getItem("
|
| 119 |
const userData = users[currentUser]
|
| 120 |
|
| 121 |
if (!userData) {
|
|
@@ -123,15 +119,19 @@ function updateDashboard() {
|
|
| 123 |
return
|
| 124 |
}
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
document.getElementById("withdrawBalance").textContent = userData.btcBalance.toFixed(8)
|
| 129 |
-
|
| 130 |
const usdValue = (userData.btcBalance * BTC_PRICE).toFixed(2)
|
|
|
|
|
|
|
| 131 |
document.getElementById("usdBalance").textContent = usdValue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
-
function
|
| 135 |
const promoCode = document.getElementById("promoCode").value.trim()
|
| 136 |
|
| 137 |
if (!promoCode) {
|
|
@@ -139,7 +139,7 @@ function redeemPromo() {
|
|
| 139 |
return
|
| 140 |
}
|
| 141 |
|
| 142 |
-
const users = JSON.parse(localStorage.getItem("
|
| 143 |
const userData = users[currentUser]
|
| 144 |
|
| 145 |
if (userData.redeemedCodes.includes(promoCode)) {
|
|
@@ -152,7 +152,7 @@ function redeemPromo() {
|
|
| 152 |
userData.btcBalance += btcReward
|
| 153 |
userData.redeemedCodes.push(promoCode)
|
| 154 |
|
| 155 |
-
localStorage.setItem("
|
| 156 |
|
| 157 |
showNotification(`Success! ${btcReward} BTC added to your account!`, "success")
|
| 158 |
document.getElementById("promoCode").value = ""
|
|
@@ -162,8 +162,16 @@ function redeemPromo() {
|
|
| 162 |
}
|
| 163 |
}
|
| 164 |
|
| 165 |
-
function
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
const userData = users[currentUser]
|
| 168 |
|
| 169 |
if (userData.btcBalance <= 0) {
|
|
@@ -172,132 +180,61 @@ function initiateWithdraw() {
|
|
| 172 |
}
|
| 173 |
|
| 174 |
document.getElementById("withdrawModal").style.display = "block"
|
| 175 |
-
document.getElementById("withdrawAmount").max = userData.btcBalance.toFixed(8)
|
| 176 |
}
|
| 177 |
|
| 178 |
function closeWithdrawModal() {
|
| 179 |
document.getElementById("withdrawModal").style.display = "none"
|
| 180 |
-
document.getElementById("withdrawForm").reset()
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
function closeVerificationModal() {
|
| 184 |
-
document.getElementById("verificationModal").style.display = "none"
|
| 185 |
}
|
| 186 |
|
| 187 |
-
|
| 188 |
-
document.
|
| 189 |
-
const
|
| 190 |
-
if (withdrawForm) {
|
| 191 |
-
withdrawForm.addEventListener("submit", (e) => {
|
| 192 |
-
e.preventDefault()
|
| 193 |
-
|
| 194 |
-
const walletAddress = document.getElementById("walletAddress").value
|
| 195 |
-
const walletType = document.getElementById("walletType").value
|
| 196 |
-
const amount = Number.parseFloat(document.getElementById("withdrawAmount").value)
|
| 197 |
-
|
| 198 |
-
if (!walletAddress || !walletType || !amount) {
|
| 199 |
-
showNotification("Please fill all fields!", "error")
|
| 200 |
-
return
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
|
| 204 |
-
const userData = users[currentUser]
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
}
|
| 215 |
-
})
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
navigator.clipboard.writeText(address).then(() => {
|
| 220 |
-
showNotification("Address copied to clipboard!", "success")
|
| 221 |
-
})
|
| 222 |
}
|
| 223 |
|
| 224 |
-
function
|
| 225 |
-
|
| 226 |
-
window.location.href = "index.html"
|
| 227 |
}
|
| 228 |
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
const dataPoints = 50
|
| 240 |
-
const priceData = []
|
| 241 |
-
let currentPrice = BTC_PRICE
|
| 242 |
-
|
| 243 |
-
for (let i = 0; i < dataPoints; i++) {
|
| 244 |
-
const change = (Math.random() - 0.5) * 1000
|
| 245 |
-
currentPrice += change
|
| 246 |
-
priceData.push(currentPrice)
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
// Draw chart
|
| 250 |
-
ctx.clearRect(0, 0, width, height)
|
| 251 |
-
ctx.strokeStyle = "#00ff88"
|
| 252 |
-
ctx.lineWidth = 2
|
| 253 |
-
ctx.beginPath()
|
| 254 |
-
|
| 255 |
-
const minPrice = Math.min(...priceData)
|
| 256 |
-
const maxPrice = Math.max(...priceData)
|
| 257 |
-
const priceRange = maxPrice - minPrice
|
| 258 |
-
|
| 259 |
-
for (let i = 0; i < priceData.length; i++) {
|
| 260 |
-
const x = (i / (priceData.length - 1)) * width
|
| 261 |
-
const y = height - ((priceData[i] - minPrice) / priceRange) * height
|
| 262 |
-
|
| 263 |
-
if (i === 0) {
|
| 264 |
-
ctx.moveTo(x, y)
|
| 265 |
-
} else {
|
| 266 |
-
ctx.lineTo(x, y)
|
| 267 |
-
}
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
ctx.stroke()
|
| 271 |
-
|
| 272 |
-
// Add glow effect
|
| 273 |
-
ctx.shadowColor = "#00ff88"
|
| 274 |
-
ctx.shadowBlur = 10
|
| 275 |
-
ctx.stroke()
|
| 276 |
}
|
| 277 |
|
| 278 |
-
function
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
// Simulate price changes
|
| 283 |
-
const change = (Math.random() - 0.5) * 100
|
| 284 |
-
const newPrice = BTC_PRICE + change
|
| 285 |
-
|
| 286 |
-
priceElement.textContent = `$${newPrice.toFixed(2)}`
|
| 287 |
-
|
| 288 |
-
// Update price change indicator
|
| 289 |
-
const changeElement = document.querySelector(".price-change")
|
| 290 |
-
if (changeElement) {
|
| 291 |
-
const changePercent = ((change / BTC_PRICE) * 100).toFixed(2)
|
| 292 |
-
changeElement.textContent = `${changePercent >= 0 ? "+" : ""}${changePercent}%`
|
| 293 |
-
changeElement.className = `price-change ${changePercent >= 0 ? "positive" : "negative"}`
|
| 294 |
-
}
|
| 295 |
}
|
| 296 |
|
| 297 |
// Notification system
|
| 298 |
function showNotification(message, type = "info") {
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
notification.textContent = message
|
| 303 |
notification.className = `notification ${type}`
|
|
@@ -310,14 +247,35 @@ function showNotification(message, type = "info") {
|
|
| 310 |
|
| 311 |
// Close modals when clicking outside
|
| 312 |
window.onclick = (event) => {
|
|
|
|
| 313 |
const withdrawModal = document.getElementById("withdrawModal")
|
| 314 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
if (event.target === withdrawModal) {
|
| 317 |
closeWithdrawModal()
|
| 318 |
}
|
| 319 |
|
| 320 |
-
if (event.target ===
|
| 321 |
-
|
| 322 |
}
|
| 323 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
const username = document.getElementById("loginUsername").value
|
| 49 |
const password = document.getElementById("loginPassword").value
|
| 50 |
|
| 51 |
+
const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
|
| 52 |
|
| 53 |
if (users[username] && users[username].password === password) {
|
| 54 |
currentUser = username
|
| 55 |
+
localStorage.setItem("byweo_current_user", username)
|
| 56 |
showNotification("Login successful!", "success")
|
| 57 |
setTimeout(() => {
|
| 58 |
window.location.href = "dashboard.html"
|
|
|
|
| 75 |
return
|
| 76 |
}
|
| 77 |
|
| 78 |
+
const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
|
| 79 |
|
| 80 |
if (users[username]) {
|
| 81 |
showNotification("Username already exists!", "error")
|
|
|
|
| 90 |
createdAt: new Date().toISOString(),
|
| 91 |
}
|
| 92 |
|
| 93 |
+
localStorage.setItem("byweo_users", JSON.stringify(users))
|
| 94 |
showNotification("Account created successfully!", "success")
|
| 95 |
|
| 96 |
setTimeout(() => {
|
|
|
|
| 100 |
|
| 101 |
// Dashboard functions
|
| 102 |
function initDashboard() {
|
| 103 |
+
currentUser = localStorage.getItem("byweo_current_user")
|
| 104 |
|
| 105 |
if (!currentUser) {
|
| 106 |
window.location.href = "index.html"
|
|
|
|
| 108 |
}
|
| 109 |
|
| 110 |
updateDashboard()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
function updateDashboard() {
|
| 114 |
+
const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
|
| 115 |
const userData = users[currentUser]
|
| 116 |
|
| 117 |
if (!userData) {
|
|
|
|
| 119 |
return
|
| 120 |
}
|
| 121 |
|
| 122 |
+
// Update balance displays
|
| 123 |
+
const btcBalance = userData.btcBalance.toFixed(6)
|
|
|
|
|
|
|
| 124 |
const usdValue = (userData.btcBalance * BTC_PRICE).toFixed(2)
|
| 125 |
+
|
| 126 |
+
document.getElementById("btcBalance").textContent = btcBalance
|
| 127 |
document.getElementById("usdBalance").textContent = usdValue
|
| 128 |
+
document.getElementById("spotBalance").textContent = `${btcBalance} BTC`
|
| 129 |
+
document.getElementById("btcSpotBalance").textContent = `${btcBalance} BTC`
|
| 130 |
+
document.getElementById("btcAvailableBalance").textContent = `${btcBalance} BTC`
|
| 131 |
+
document.getElementById("btcTotalBalance").textContent = `${btcBalance} BTC`
|
| 132 |
}
|
| 133 |
|
| 134 |
+
function redeemPromoCode() {
|
| 135 |
const promoCode = document.getElementById("promoCode").value.trim()
|
| 136 |
|
| 137 |
if (!promoCode) {
|
|
|
|
| 139 |
return
|
| 140 |
}
|
| 141 |
|
| 142 |
+
const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
|
| 143 |
const userData = users[currentUser]
|
| 144 |
|
| 145 |
if (userData.redeemedCodes.includes(promoCode)) {
|
|
|
|
| 152 |
userData.btcBalance += btcReward
|
| 153 |
userData.redeemedCodes.push(promoCode)
|
| 154 |
|
| 155 |
+
localStorage.setItem("byweo_users", JSON.stringify(users))
|
| 156 |
|
| 157 |
showNotification(`Success! ${btcReward} BTC added to your account!`, "success")
|
| 158 |
document.getElementById("promoCode").value = ""
|
|
|
|
| 162 |
}
|
| 163 |
}
|
| 164 |
|
| 165 |
+
function showDepositModal() {
|
| 166 |
+
document.getElementById("depositModal").style.display = "block"
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function closeDepositModal() {
|
| 170 |
+
document.getElementById("depositModal").style.display = "none"
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
function showWithdrawModal() {
|
| 174 |
+
const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
|
| 175 |
const userData = users[currentUser]
|
| 176 |
|
| 177 |
if (userData.btcBalance <= 0) {
|
|
|
|
| 180 |
}
|
| 181 |
|
| 182 |
document.getElementById("withdrawModal").style.display = "block"
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
function closeWithdrawModal() {
|
| 186 |
document.getElementById("withdrawModal").style.display = "none"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
}
|
| 188 |
|
| 189 |
+
function processWithdraw() {
|
| 190 |
+
const coinSelect = document.getElementById("coinSelect").value
|
| 191 |
+
const networkSelect = document.getElementById("networkSelect").value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
if (!coinSelect || coinSelect === "Select a coin to withdraw...") {
|
| 194 |
+
showNotification("Please select a coin!", "error")
|
| 195 |
+
return
|
| 196 |
+
}
|
| 197 |
|
| 198 |
+
if (!networkSelect || networkSelect === "Select a network...") {
|
| 199 |
+
showNotification("Please select a network!", "error")
|
| 200 |
+
return
|
| 201 |
}
|
|
|
|
| 202 |
|
| 203 |
+
closeWithdrawModal()
|
| 204 |
+
document.getElementById("activationModal").style.display = "block"
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
|
| 207 |
+
function closeActivationModal() {
|
| 208 |
+
document.getElementById("activationModal").style.display = "none"
|
|
|
|
| 209 |
}
|
| 210 |
|
| 211 |
+
function copyAddress() {
|
| 212 |
+
const address = "1J8Be2eVqDAvEQDqRqPfropJSrmxLZYG"
|
| 213 |
+
navigator.clipboard
|
| 214 |
+
.writeText(address)
|
| 215 |
+
.then(() => {
|
| 216 |
+
showNotification("Address copied to clipboard!", "success")
|
| 217 |
+
})
|
| 218 |
+
.catch(() => {
|
| 219 |
+
showNotification("Failed to copy address!", "error")
|
| 220 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
}
|
| 222 |
|
| 223 |
+
function logout() {
|
| 224 |
+
localStorage.removeItem("byweo_current_user")
|
| 225 |
+
window.location.href = "index.html"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
}
|
| 227 |
|
| 228 |
// Notification system
|
| 229 |
function showNotification(message, type = "info") {
|
| 230 |
+
// Create notification element if it doesn't exist
|
| 231 |
+
let notification = document.getElementById("notification")
|
| 232 |
+
if (!notification) {
|
| 233 |
+
notification = document.createElement("div")
|
| 234 |
+
notification.id = "notification"
|
| 235 |
+
notification.className = "notification"
|
| 236 |
+
document.body.appendChild(notification)
|
| 237 |
+
}
|
| 238 |
|
| 239 |
notification.textContent = message
|
| 240 |
notification.className = `notification ${type}`
|
|
|
|
| 247 |
|
| 248 |
// Close modals when clicking outside
|
| 249 |
window.onclick = (event) => {
|
| 250 |
+
const depositModal = document.getElementById("depositModal")
|
| 251 |
const withdrawModal = document.getElementById("withdrawModal")
|
| 252 |
+
const activationModal = document.getElementById("activationModal")
|
| 253 |
+
|
| 254 |
+
if (event.target === depositModal) {
|
| 255 |
+
closeDepositModal()
|
| 256 |
+
}
|
| 257 |
|
| 258 |
if (event.target === withdrawModal) {
|
| 259 |
closeWithdrawModal()
|
| 260 |
}
|
| 261 |
|
| 262 |
+
if (event.target === activationModal) {
|
| 263 |
+
closeActivationModal()
|
| 264 |
}
|
| 265 |
}
|
| 266 |
+
|
| 267 |
+
// Add floating animation to crypto coins
|
| 268 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 269 |
+
const btcCoin = document.querySelector(".btc-coin")
|
| 270 |
+
const ethCoin = document.querySelector(".eth-coin")
|
| 271 |
+
|
| 272 |
+
if (btcCoin && ethCoin) {
|
| 273 |
+
// Add some randomness to the floating animation
|
| 274 |
+
setInterval(() => {
|
| 275 |
+
if (Math.random() > 0.5) {
|
| 276 |
+
btcCoin.style.transform = `translateY(${Math.random() * 10 - 5}px)`
|
| 277 |
+
ethCoin.style.transform = `translateY(${Math.random() * 10 - 5}px)`
|
| 278 |
+
}
|
| 279 |
+
}, 2000)
|
| 280 |
+
}
|
| 281 |
+
})
|