This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
256 lines (216 loc) · 9.48 KB
/
app.js
File metadata and controls
256 lines (216 loc) · 9.48 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Main entry point for the application
// This file handles ONLY the UI animations and ticker displays
// All blockchain and wallet functionality is now in src/index.js and related modules
// Add performance markers for monitoring
performance.mark('startApp');
/**
* Initialize UI animations
*/
function initializeAnimations() {
// Update instructions based on device type
const desktopInstructions = document.querySelector('.instructions.desktop');
const mobileInstructions = document.querySelector('.instructions.mobile');
const isMobile = window.innerWidth <= 768 ||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (desktopInstructions && mobileInstructions) {
desktopInstructions.style.display = isMobile ? 'none' : 'block';
mobileInstructions.style.display = isMobile ? 'block' : 'none';
}
// Set up ticker animation
const tickerContent = document.querySelector('.ticker-content');
if (tickerContent) {
const tickerItems = tickerContent.querySelectorAll('.ticker-item');
const tickerWidth = Array.from(tickerItems).reduce((sum, item) => sum + item.offsetWidth, 0);
// Clone ticker items to create infinite loop
if (tickerWidth > 0) {
tickerContent.style.animationDuration = `${tickerWidth / 50}s`;
}
}
}
/**
* Initialize random price updates for UI
*/
function initializePriceUpdates() {
// Configure initial values
let currentCultPrice = 1000;
let currentEthPrice = 13482.45;
let currentGasPrice = 0.004;
let currentOpenPrice = 120.50;
let currentHighPrice = 123.87;
let currentLowPrice = 120.15;
let currentMarketValue = 9.993;
let currentVolume = 10200000000;
/**
* Generate random fluctuation in a value
* @param {number} base - Base value
* @param {number} percentage - Percentage of maximum fluctuation
* @returns {number} - New value
*/
const randomFluctuation = (base, percentage) => {
const variance = base * (percentage / 100);
return base + (Math.random() * variance * 2 - variance);
};
/**
* Format number with fixed decimals
* @param {number} num - Number to format
* @param {number} decimals - Decimal places
* @returns {string} - Formatted number
*/
const formatNumber = (num, decimals = 2) => {
return num.toFixed(decimals);
};
/**
* Update price indicators
*/
function updatePrices() {
// Update CULT price
const priceElement = document.getElementById('currentPrice');
const changeElement = document.getElementById('priceChange');
if (priceElement && changeElement) {
const newCultPrice = randomFluctuation(currentCultPrice, 1);
const cultChange = newCultPrice - currentCultPrice;
currentCultPrice = newCultPrice;
priceElement.textContent = formatNumber(currentCultPrice);
changeElement.textContent = (cultChange >= 0 ? '+' : '') + formatNumber(cultChange);
// Update classes for color
priceElement.className = 'price ' + (cultChange >= 0 ? 'up' : 'down');
changeElement.className = 'change ' + (cultChange >= 0 ? 'up' : 'down');
}
// Update ETH price
const ethPriceElement = document.getElementById('ethPrice');
if (ethPriceElement) {
const newEthPrice = randomFluctuation(currentEthPrice, 0.1);
const ethChange = Math.abs(newEthPrice - currentEthPrice);
currentEthPrice = newEthPrice;
ethPriceElement.textContent = `${formatNumber(currentEthPrice)} +${formatNumber(ethChange)}`;
}
// Update Gas price
const gasPriceElement = document.getElementById('gasPrice');
if (gasPriceElement) {
const newGasPrice = randomFluctuation(currentGasPrice, 5);
const gasChange = newGasPrice - currentGasPrice;
currentGasPrice = newGasPrice;
gasPriceElement.textContent = `${currentGasPrice.toFixed(3)} ${gasChange >= 0 ? '+' : ''}${gasChange.toFixed(5)}`;
gasPriceElement.className = gasChange >= 0 ? 'price-up' : 'price-down';
}
// Update other price elements
const openPriceElement = document.getElementById('openPrice');
const highPriceElement = document.getElementById('highPrice');
const lowPriceElement = document.getElementById('lowPrice');
const marketValueElement = document.getElementById('marketValue');
const volumeElement = document.getElementById('cult volume');
if (openPriceElement) openPriceElement.textContent = formatNumber(randomFluctuation(currentOpenPrice, 0.1)) + 'P';
if (highPriceElement) highPriceElement.textContent = formatNumber(randomFluctuation(currentHighPrice, 0.1)) + 'Z';
if (lowPriceElement) lowPriceElement.textContent = formatNumber(randomFluctuation(currentLowPrice, 0.1)) + 'Q';
if (marketValueElement) marketValueElement.textContent = formatNumber(randomFluctuation(currentMarketValue, 0.5)) + 'B';
// Update volume
if (volumeElement) {
const newVolume = Math.round(randomFluctuation(currentVolume, 2));
currentVolume = newVolume;
volumeElement.textContent = (newVolume / 1000000000).toFixed(1) + 'B ETH';
}
// Update time
const timeElement = document.getElementById('timeStamp');
if (timeElement) {
const now = new Date();
timeElement.textContent = now.toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit'
});
}
}
// Update prices immediately and then every 1 second
updatePrices();
setInterval(updatePrices, 1000);
}
/**
* Initialize whitelist checker
*/
function initializeWhitelistChecker() {
const input = document.getElementById('walletAddress');
const button = document.getElementById('checkButton');
if (!input || !button) return;
// Format Ethereum address for display
function formatAddress(address) {
if (address.length !== 42) return address;
return `${address.substring(0, 6)}...${address.substring(38)}`;
}
// Auto-focus input on desktop
if (window.innerWidth > 768) {
input.focus();
}
// Simulate whitelist check
async function checkWhitelist(address) {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1500));
// Deterministic "random" based on address
const addressSum = address.split('')
.reduce((sum, char) => sum + char.charCodeAt(0), 0);
// 50% chance of being whitelisted for this demo
if (addressSum % 100 < 50) {
const days = ['March 14th', 'March 15th', 'March 16th', 'March 17th'];
const day = (addressSum % 4) + 1;
return {
whitelisted: true,
day: day,
date: days[day - 1]
};
}
return null;
}
// Handle address check
async function checkWhitelistStatus() {
const address = input.value;
const resultDiv = document.getElementById('result');
if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {
resultDiv.innerHTML = '<p class="error">Please enter a valid Ethereum address</p>';
return;
}
resultDiv.innerHTML = '<p class="checking">Checking...</p>';
const result = await checkWhitelist(address);
if (result) {
resultDiv.innerHTML = `
<p class="success">Congratulations! You are whitelisted!</p>
<p>Address: ${formatAddress(address)}</p>
<p>You can participate in the bonding curve presale on Day ${result.day}</p>
`;
} else {
resultDiv.innerHTML = `
<p class="error">Address not found in any whitelist</p>
<p>Address checked: ${formatAddress(address)}</p>
`;
}
}
// Handle input events
input.addEventListener('input', () => {
// Auto-format as user types (optional)
});
// Listen for Enter key
input.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
event.preventDefault();
checkWhitelistStatus();
}
});
// Button click handler
button.addEventListener('click', checkWhitelistStatus);
}
// Export functions globally so they can be called from route handlers
window.initializeAnimations = initializeAnimations;
window.initializePriceUpdates = initializePriceUpdates;
window.initializeWhitelistChecker = initializeWhitelistChecker;
// Only auto-initialize if we're on a page that needs it (not using router)
// The router will call these functions when needed
document.addEventListener('DOMContentLoaded', () => {
// Check if we're using the router (router will handle initialization)
// If router is not available, initialize directly (backward compatibility)
if (!window.router) {
initializeAnimations();
initializePriceUpdates();
initializeWhitelistChecker();
// Mark UI loaded
performance.mark('uiLoaded');
performance.measure('uiLoadTime', 'startApp', 'uiLoaded');
}
});