-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
373 lines (352 loc) · 12 KB
/
dashboard.html
File metadata and controls
373 lines (352 loc) · 12 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crypto Tracker Settings</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 500px;
width: 100%;
padding: 30px;
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #666;
margin-bottom: 25px;
font-size: 14px;
}
.section {
margin-bottom: 25px;
}
.section-title {
color: #667eea;
font-weight: 600;
margin-bottom: 15px;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.coin-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
background: #f5f5f5;
border-radius: 8px;
margin-bottom: 8px;
transition: background 0.2s;
}
.coin-item:hover {
background: #e8e8e8;
}
.coin-symbol {
font-weight: 600;
color: #333;
}
.coin-id {
color: #999;
font-size: 12px;
}
.remove-btn {
background: #ff6b6b;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
font-weight: 600;
transition: background 0.2s;
}
.remove-btn:hover {
background: #ee5a5a;
}
.add-coin-form {
display: flex;
gap: 8px;
margin-bottom: 15px;
flex-wrap: wrap;
}
input[type="text"] {
flex: 1;
min-width: 120px;
padding: 10px 12px;
border: 2px solid #e0e0e0;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.2s;
}
input[type="text"]:focus {
outline: none;
border-color: #667eea;
}
.add-btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
transition: background 0.2s;
flex: 0 0 auto;
}
.add-btn:hover {
background: #5568d3;
}
.current-prices {
padding: 15px;
background: #f9f9f9;
border-radius: 8px;
}
.price-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
padding: 10px;
background: white;
border-radius: 6px;
border-left: 4px solid #667eea;
}
.price-symbol {
font-weight: 600;
color: #333;
font-size: 16px;
}
.price-value {
color: #667eea;
font-weight: 600;
}
.price-change {
font-size: 12px;
margin-top: 2px;
}
.price-change.positive {
color: #00dd00;
font-weight: 600;
}
.price-change.negative {
color: #ff6b6b;
font-weight: 600;
}
.status {
padding: 12px;
border-radius: 6px;
margin-bottom: 15px;
text-align: center;
font-weight: 500;
}
.status.success {
background: #d4edda;
color: #155724;
}
.status.error {
background: #f8d7da;
color: #721c24;
}
.status.loading {
background: #d1ecf1;
color: #0c5460;
}
.refresh-btn {
width: 100%;
background: #28a745;
color: white;
border: none;
padding: 12px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
font-size: 14px;
transition: background 0.2s;
}
.refresh-btn:hover {
background: #218838;
}
.help-text {
color: #999;
font-size: 12px;
margin-top: 8px;
}
</style>
</head>
<body>
<div class="container">
<h1>📊 Crypto Tracker</h1>
<p class="subtitle">Matrix Portal S3 Settings</p>
<div id="status-message"></div>
<div class="section">
<div class="section-title">Add New Coin</div>
<div class="add-coin-form">
<input type="text" id="symbol-input" placeholder="Symbol (e.g., BTC)" maxlength="10">
<input type="text" id="coin-id-input" placeholder="ID (e.g., bitcoin)" maxlength="30">
<button class="add-btn" onclick="addCoin()">Add</button>
</div>
<p class="help-text">Use official CoinGecko IDs. Example: bitcoin, ethereum, ripple, dogecoin</p>
</div>
<div class="section">
<div class="section-title">Tracked Coins</div>
<div id="coins-list"></div>
</div>
<div class="section">
<button class="refresh-btn" onclick="refreshData()">🔄 Refresh Prices</button>
</div>
<div class="section">
<div class="section-title">Current Prices</div>
<div id="prices-list" class="current-prices">
<p style="color: #999; text-align: center;">Loading prices...</p>
</div>
</div>
</div>
<script>
const API_BASE = window.location.origin;
async function loadCoins() {
try {
const response = await fetch(`${API_BASE}/api/coins`);
const data = await response.json();
displayCoins(data.coins);
} catch (error) {
console.error('Error loading coins:', error);
showStatus('Error loading coins', 'error');
}
}
async function loadPrices() {
try {
const response = await fetch(`${API_BASE}/api/prices`);
const data = await response.json();
displayPrices(data.prices);
} catch (error) {
console.error('Error loading prices:', error);
}
}
function displayCoins(coins) {
const list = document.getElementById('coins-list');
if (coins.length === 0) {
list.innerHTML = '<p style="color: #999; text-align: center;">No coins tracked</p>';
return;
}
list.innerHTML = coins.map(coin => `
<div class="coin-item">
<div>
<div class="coin-symbol">${coin.symbol}</div>
<div class="coin-id">${coin.id}</div>
</div>
<button class="remove-btn" onclick="removeCoin('${coin.symbol}')">Remove</button>
</div>
`).join('');
}
function displayPrices(prices) {
const list = document.getElementById('prices-list');
if (Object.keys(prices).length === 0) {
list.innerHTML = '<p style="color: #999; text-align: center;">No price data</p>';
return;
}
list.innerHTML = Object.entries(prices).map(([symbol, data]) => {
const change = data.change || 0;
const changeClass = change >= 0 ? 'positive' : 'negative';
return `
<div class="price-item">
<div>
<div class="price-symbol">${symbol}</div>
<div class="price-change ${changeClass}">${change >= 0 ? '📈 +' : '📉 '}${change.toFixed(2)}% (24h)</div>
</div>
<div class="price-value">$${data.price.toFixed(2)}</div>
</div>
`;
}).join('');
}
async function addCoin() {
const symbol = document.getElementById('symbol-input').value.trim().toUpperCase();
const id = document.getElementById('coin-id-input').value.trim().toLowerCase();
if (!symbol || !id) {
showStatus('Please fill in both fields', 'error');
return;
}
try {
showStatus('Adding coin...', 'loading');
const response = await fetch(`${API_BASE}/api/coins`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ symbol, id })
});
if (response.ok) {
document.getElementById('symbol-input').value = '';
document.getElementById('coin-id-input').value = '';
showStatus('Coin added successfully!', 'success');
await loadCoins();
await loadPrices();
} else {
showStatus('Error adding coin', 'error');
}
} catch (error) {
console.error('Error:', error);
showStatus('Error adding coin', 'error');
}
}
async function removeCoin(symbol) {
if (!confirm(`Remove ${symbol}?`)) return;
try {
showStatus('Removing coin...', 'loading');
const response = await fetch(`${API_BASE}/api/coins/${symbol}`, {
method: 'DELETE'
});
if (response.ok) {
showStatus('Coin removed successfully!', 'success');
await loadCoins();
await loadPrices();
} else {
showStatus('Error removing coin', 'error');
}
} catch (error) {
console.error('Error:', error);
showStatus('Error removing coin', 'error');
}
}
async function refreshData() {
try {
showStatus('Refreshing prices...', 'loading');
await loadPrices();
showStatus('Prices refreshed!', 'success');
} catch (error) {
console.error('Error:', error);
showStatus('Error refreshing prices', 'error');
}
}
function showStatus(message, type) {
const statusDiv = document.getElementById('status-message');
statusDiv.textContent = message;
statusDiv.className = `status ${type}`;
if (type === 'success') {
setTimeout(() => statusDiv.textContent = '', 3000);
}
}
// Initial load
loadCoins();
loadPrices();
// Refresh prices every 30 seconds
setInterval(loadPrices, 30000);
</script>
</body>
</html>