Spaces:
Running
Running
File size: 5,245 Bytes
4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 3ee644d 4ed6779 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
// BitVault Pro - Main JavaScript
// Global state
let isLoggedIn = false;
let currentUser = null;
let btcPrice = 66869.57; // Price for $470,000 / 7.0246 BTC
let btcBalance = 7.0246; // BTC amount for $470,000
let charts = {};
// DOM Ready
document.addEventListener('DOMContentLoaded', function() {
// Check session
if (sessionStorage.getItem('isLoggedIn')) {
isLoggedIn = true;
currentUser = sessionStorage.getItem('currentUser');
showDashboard();
}
initializeCharts();
setupEventListeners();
feather.replace();
});
// Initialize Charts
function initializeCharts() {
// Hero chart
const heroCtx = document.getElementById('heroChart');
if (heroCtx) {
const heroGradient = heroCtx.getContext('2d').createLinearGradient(0, 0, 0, 200);
heroGradient.addColorStop(0, 'rgba(16, 185, 129, 0.3)');
heroGradient.addColorStop(1, 'rgba(16, 185, 129, 0)');
charts.hero = new Chart(heroCtx, {
type: 'line',
data: {
labels: generateTimeLabels(24),
datasets: [{
label: 'BTC/USD',
data: generatePriceData(64000, 69000, 24),
borderColor: '#10b981',
backgroundColor: heroGradient,
borderWidth: 2,
fill: true,
tension: 0.4,
pointRadius: 0,
pointHoverRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
x: { display: false },
y: { display: false }
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
}
// Generate time labels
function generateTimeLabels(count) {
const labels = [];
const now = new Date();
for (let i = count - 1; i >= 0; i--) {
const time = new Date(now - i * 60 * 60 * 1000);
labels.push(time.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }));
}
return labels;
}
// Generate price data
function generatePriceData(min, max, count) {
const data = [];
let current = 66869.57;
for (let i = 0; i < count; i++) {
const change = (Math.random() - 0.5) * 2000;
current = Math.max(min, Math.min(max, current + change));
data.push(current);
}
return data;
}
// Setup event listeners
function setupEventListeners() {
// Login form
const loginForm = document.getElementById('login-form');
if (loginForm) {
loginForm.addEventListener('submit', handleLogin);
}
// Custom events from web components
document.addEventListener('show-login', showLoginModal);
document.addEventListener('logout', logout);
}
// Handle login
function handleLogin(e) {
e.preventDefault();
const name = document.getElementById('login-name').value.trim();
const password = document.getElementById('login-password').value;
if (name === 'User' && password === 'Password') {
isLoggedIn = true;
currentUser = name;
// Store in session
sessionStorage.setItem('isLoggedIn', 'true');
sessionStorage.setItem('currentUser', name);
hideLoginModal();
showDashboard();
} else {
const errorEl = document.getElementById('login-error');
errorEl.textContent = 'Invalid credentials. Use Username: "User" and Password: "Password"';
errorEl.classList.remove('hidden');
setTimeout(() => errorEl.classList.add('hidden'), 5000);
}
}
// Modal functions
function showLoginModal() {
const modal = document.getElementById('login-modal');
if (modal) modal.classList.remove('hidden');
}
function hideLoginModal() {
const modal = document.getElementById('login-modal');
if (modal) modal.classList.add('hidden');
}
function showDashboard() {
const mainContent = document.getElementById('main-content');
const dashboard = document.getElementById('dashboard');
const userNameDisplay = document.getElementById('user-name-display');
if (mainContent) mainContent.classList.add('hidden');
if (dashboard) dashboard.classList.remove('hidden');
if (userNameDisplay) userNameDisplay.textContent = currentUser || 'User';
feather.replace();
}
// Scroll to features
function scrollToFeatures() {
const featuresSection = document.getElementById('features-section');
if (featuresSection) featuresSection.scrollIntoView({ behavior: 'smooth' });
}
// Logout
function logout() {
isLoggedIn = false;
currentUser = null;
sessionStorage.removeItem('isLoggedIn');
sessionStorage.removeItem('currentUser');
const dashboard = document.getElementById('dashboard');
const mainContent = document.getElementById('main-content');
if (dashboard) dashboard.classList.add('hidden');
if (mainContent) mainContent.classList.remove('hidden');
window.scrollTo({ top: 0, behavior: 'smooth' });
}
|