Service-Xi commited on
Commit
4f5ece9
·
verified ·
1 Parent(s): 958b048

Upload 4 files

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. script.js +159 -99
index.html CHANGED
@@ -454,4 +454,4 @@ loginFormElement.addEventListener('submit', function(e) {
454
  switchToRegister();
455
  </script>
456
  </body>
457
- </html>
 
454
  switchToRegister();
455
  </script>
456
  </body>
457
+ </html>
script.js CHANGED
@@ -20,15 +20,15 @@ document.addEventListener("DOMContentLoaded", () => {
20
 
21
  // Authentication functions
22
  function initAuth() {
23
- const loginForm = document.getElementById("loginFormElement")
24
- const registerForm = document.getElementById("registerFormElement")
25
 
26
- if (loginForm) {
27
- loginForm.addEventListener("submit", handleLogin)
28
  }
29
 
30
- if (registerForm) {
31
- registerForm.addEventListener("submit", handleRegister)
32
  }
33
  }
34
 
@@ -45,27 +45,32 @@ function switchToLogin() {
45
  function handleLogin(e) {
46
  e.preventDefault()
47
 
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"
59
  }, 1000)
60
  } else {
61
- showNotification("Invalid username or password!", "error")
62
  }
63
  }
64
 
65
  function handleRegister(e) {
66
  e.preventDefault()
67
 
68
- const username = document.getElementById("registerUsername").value
69
  const email = document.getElementById("registerEmail").value
70
  const password = document.getElementById("registerPassword").value
71
  const confirmPassword = document.getElementById("confirmPassword").value
@@ -75,14 +80,27 @@ function handleRegister(e) {
75
  return
76
  }
77
 
78
- const users = JSON.parse(localStorage.getItem("byweo_users") || "{}")
79
 
80
- if (users[username]) {
81
- showNotification("Username already exists!", "error")
 
 
82
  return
83
  }
84
 
85
- users[username] = {
 
 
 
 
 
 
 
 
 
 
 
86
  email: email,
87
  password: password,
88
  btcBalance: 0.0,
@@ -90,7 +108,7 @@ function handleRegister(e) {
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,7 +118,7 @@ function handleRegister(e) {
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,10 +126,14 @@ function initDashboard() {
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,19 +141,15 @@ function updateDashboard() {
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,7 +157,7 @@ function redeemPromoCode() {
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,7 +170,7 @@ function redeemPromoCode() {
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,16 +180,8 @@ function redeemPromoCode() {
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,61 +190,132 @@ function showWithdrawModal() {
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,35 +328,14 @@ function showNotification(message, type = "info") {
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
- })
 
20
 
21
  // Authentication functions
22
  function initAuth() {
23
+ const loginFormElement = document.getElementById("loginFormElement")
24
+ const registerFormElement = document.getElementById("registerFormElement")
25
 
26
+ if (loginFormElement) {
27
+ loginFormElement.addEventListener("submit", handleLogin)
28
  }
29
 
30
+ if (registerFormElement) {
31
+ registerFormElement.addEventListener("submit", handleRegister)
32
  }
33
  }
34
 
 
45
  function handleLogin(e) {
46
  e.preventDefault()
47
 
48
+ const email = document.getElementById("loginEmail").value
49
  const password = document.getElementById("loginPassword").value
50
 
51
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
52
 
53
+ // Find user by email instead of username
54
+ const userEntry = Object.entries(users).find(
55
+ ([username, userData]) => userData.email === email && userData.password === password,
56
+ )
57
+
58
+ if (userEntry) {
59
+ const [username] = userEntry
60
  currentUser = username
61
+ localStorage.setItem("cryptovault_current_user", username)
62
  showNotification("Login successful!", "success")
63
  setTimeout(() => {
64
  window.location.href = "dashboard.html"
65
  }, 1000)
66
  } else {
67
+ showNotification("Invalid email or password!", "error")
68
  }
69
  }
70
 
71
  function handleRegister(e) {
72
  e.preventDefault()
73
 
 
74
  const email = document.getElementById("registerEmail").value
75
  const password = document.getElementById("registerPassword").value
76
  const confirmPassword = document.getElementById("confirmPassword").value
 
80
  return
81
  }
82
 
83
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
84
 
85
+ // Check if email already exists
86
+ const emailExists = Object.values(users).some((userData) => userData.email === email)
87
+ if (emailExists) {
88
+ showNotification("Email already exists!", "error")
89
  return
90
  }
91
 
92
+ // Create username from email (before @ symbol)
93
+ const username = email.split("@")[0]
94
+ let finalUsername = username
95
+ let counter = 1
96
+
97
+ // Make sure username is unique
98
+ while (users[finalUsername]) {
99
+ finalUsername = `${username}${counter}`
100
+ counter++
101
+ }
102
+
103
+ users[finalUsername] = {
104
  email: email,
105
  password: password,
106
  btcBalance: 0.0,
 
108
  createdAt: new Date().toISOString(),
109
  }
110
 
111
+ localStorage.setItem("cryptovault_users", JSON.stringify(users))
112
  showNotification("Account created successfully!", "success")
113
 
114
  setTimeout(() => {
 
118
 
119
  // Dashboard functions
120
  function initDashboard() {
121
+ currentUser = localStorage.getItem("cryptovault_current_user")
122
 
123
  if (!currentUser) {
124
  window.location.href = "index.html"
 
126
  }
127
 
128
  updateDashboard()
129
+ initTradingChart()
130
+
131
+ // Update BTC price periodically
132
+ setInterval(updateBTCPrice, 5000)
133
  }
134
 
135
  function updateDashboard() {
136
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
137
  const userData = users[currentUser]
138
 
139
  if (!userData) {
 
141
  return
142
  }
143
 
144
+ document.getElementById("welcomeMessage").textContent = `Welcome, ${currentUser}`
145
+ document.getElementById("btcBalance").textContent = userData.btcBalance.toFixed(8)
146
+ document.getElementById("withdrawBalance").textContent = userData.btcBalance.toFixed(8)
147
 
148
+ const usdValue = (userData.btcBalance * BTC_PRICE).toFixed(2)
149
  document.getElementById("usdBalance").textContent = usdValue
 
 
 
 
150
  }
151
 
152
+ function redeemPromo() {
153
  const promoCode = document.getElementById("promoCode").value.trim()
154
 
155
  if (!promoCode) {
 
157
  return
158
  }
159
 
160
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
161
  const userData = users[currentUser]
162
 
163
  if (userData.redeemedCodes.includes(promoCode)) {
 
170
  userData.btcBalance += btcReward
171
  userData.redeemedCodes.push(promoCode)
172
 
173
+ localStorage.setItem("cryptovault_users", JSON.stringify(users))
174
 
175
  showNotification(`Success! ${btcReward} BTC added to your account!`, "success")
176
  document.getElementById("promoCode").value = ""
 
180
  }
181
  }
182
 
183
+ function initiateWithdraw() {
184
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
 
 
 
 
 
 
 
 
185
  const userData = users[currentUser]
186
 
187
  if (userData.btcBalance <= 0) {
 
190
  }
191
 
192
  document.getElementById("withdrawModal").style.display = "block"
193
+ document.getElementById("withdrawAmount").max = userData.btcBalance.toFixed(8)
194
  }
195
 
196
  function closeWithdrawModal() {
197
  document.getElementById("withdrawModal").style.display = "none"
198
+ document.getElementById("withdrawForm").reset()
199
  }
200
 
201
+ function closeVerificationModal() {
202
+ document.getElementById("verificationModal").style.display = "none"
203
+ }
204
 
205
+ // Handle withdraw form submission
206
+ document.addEventListener("DOMContentLoaded", () => {
207
+ const withdrawForm = document.getElementById("withdrawForm")
208
+ if (withdrawForm) {
209
+ withdrawForm.addEventListener("submit", (e) => {
210
+ e.preventDefault()
211
+
212
+ const walletAddress = document.getElementById("walletAddress").value
213
+ const walletType = document.getElementById("walletType").value
214
+ const amount = Number.parseFloat(document.getElementById("withdrawAmount").value)
215
+
216
+ if (!walletAddress || !walletType || !amount) {
217
+ showNotification("Please fill all fields!", "error")
218
+ return
219
+ }
220
 
221
+ const users = JSON.parse(localStorage.getItem("cryptovault_users") || "{}")
222
+ const userData = users[currentUser]
 
 
223
 
224
+ if (amount > userData.btcBalance) {
225
+ showNotification("Insufficient balance!", "error")
226
+ return
227
+ }
228
 
229
+ closeWithdrawModal()
230
+ document.getElementById("verificationModal").style.display = "block"
231
+ })
232
+ }
233
+ })
234
 
235
  function copyAddress() {
236
+ const address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
237
+ navigator.clipboard.writeText(address).then(() => {
238
+ showNotification("Address copied to clipboard!", "success")
239
+ })
 
 
 
 
 
240
  }
241
 
242
  function logout() {
243
+ localStorage.removeItem("cryptovault_current_user")
244
  window.location.href = "index.html"
245
  }
246
 
247
+ // Trading chart functions
248
+ function initTradingChart() {
249
+ const canvas = document.getElementById("tradingChart")
250
+ if (!canvas) return
251
+
252
+ const ctx = canvas.getContext("2d")
253
+ const width = canvas.width
254
+ const height = canvas.height
255
+
256
+ // Generate fake price data
257
+ const dataPoints = 50
258
+ const priceData = []
259
+ let currentPrice = BTC_PRICE
260
+
261
+ for (let i = 0; i < dataPoints; i++) {
262
+ const change = (Math.random() - 0.5) * 1000
263
+ currentPrice += change
264
+ priceData.push(currentPrice)
265
+ }
266
+
267
+ // Draw chart
268
+ ctx.clearRect(0, 0, width, height)
269
+ ctx.strokeStyle = "#00ff88"
270
+ ctx.lineWidth = 2
271
+ ctx.beginPath()
272
+
273
+ const minPrice = Math.min(...priceData)
274
+ const maxPrice = Math.max(...priceData)
275
+ const priceRange = maxPrice - minPrice
276
+
277
+ for (let i = 0; i < priceData.length; i++) {
278
+ const x = (i / (priceData.length - 1)) * width
279
+ const y = height - ((priceData[i] - minPrice) / priceRange) * height
280
+
281
+ if (i === 0) {
282
+ ctx.moveTo(x, y)
283
+ } else {
284
+ ctx.lineTo(x, y)
285
+ }
286
+ }
287
+
288
+ ctx.stroke()
289
+
290
+ // Add glow effect
291
+ ctx.shadowColor = "#00ff88"
292
+ ctx.shadowBlur = 10
293
+ ctx.stroke()
294
+ }
295
+
296
+ function updateBTCPrice() {
297
+ const priceElement = document.getElementById("btcPrice")
298
+ if (!priceElement) return
299
+
300
+ // Simulate price changes
301
+ const change = (Math.random() - 0.5) * 100
302
+ const newPrice = BTC_PRICE + change
303
+
304
+ priceElement.textContent = `$${newPrice.toFixed(2)}`
305
+
306
+ // Update price change indicator
307
+ const changeElement = document.querySelector(".price-change")
308
+ if (changeElement) {
309
+ const changePercent = ((change / BTC_PRICE) * 100).toFixed(2)
310
+ changeElement.textContent = `${changePercent >= 0 ? "+" : ""}${changePercent}%`
311
+ changeElement.className = `price-change ${changePercent >= 0 ? "positive" : "negative"}`
312
+ }
313
+ }
314
+
315
  // Notification system
316
  function showNotification(message, type = "info") {
317
+ const notification = document.getElementById("notification")
318
+ if (!notification) return
 
 
 
 
 
 
319
 
320
  notification.textContent = message
321
  notification.className = `notification ${type}`
 
328
 
329
  // Close modals when clicking outside
330
  window.onclick = (event) => {
 
331
  const withdrawModal = document.getElementById("withdrawModal")
332
+ const verificationModal = document.getElementById("verificationModal")
 
 
 
 
333
 
334
  if (event.target === withdrawModal) {
335
  closeWithdrawModal()
336
  }
337
 
338
+ if (event.target === verificationModal) {
339
+ closeVerificationModal()
340
  }
341
  }