-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
744 lines (662 loc) · 30.7 KB
/
Copy pathscript.js
File metadata and controls
744 lines (662 loc) · 30.7 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/**
* @file script.js
* @description State-driven application logic implementing Reactive PubSub,
* Web Components, and performant DocumentFragment manipulations.
*
* Amplitude Analytics is loaded as a UMD global via amplitude.min.js,
* which sets window.amplitude before this script runs.
*/
// Collapse /index.html to / before Amplitude initializes below, so
// onchainprops.xyz/ and onchainprops.xyz/index.html aren't tracked as
// separate pages. Runs here (not an inline <script> in <head>) because
// the page's CSP script-src is locked to 'self' with no 'unsafe-inline'.
if (location.pathname.endsWith('/index.html')) {
history.replaceState(null, '', location.pathname.slice(0, -10) + location.search + location.hash);
}
// -----------------------------------------
// 1. Reactive Architecture (PubSub)
// -----------------------------------------
class PubSub {
constructor() {
/** @type {Object.<string, Function[]>} */
this.events = {};
}
/**
* @param {string} eventName
* @param {Function} callback
*/
subscribe(eventName, callback) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(callback);
}
/**
* @param {string} eventName
* @param {any} [data]
*/
publish(eventName, data) {
if (!this.events[eventName]) return;
this.events[eventName].forEach(cb => {
try {
cb(data);
} catch (error) {
console.error(`PubSub Error [${eventName}]:`, error);
}
});
}
/**
* @param {string} eventName
* @param {Function} callback
*/
unsubscribe(eventName, callback) {
if (!this.events[eventName]) return;
this.events[eventName] = this.events[eventName].filter(cb => cb !== callback);
}
}
const Store = new PubSub();
/** Safe analytics wrapper — no-ops when amplitude.min.js is blocked or fails to load */
const analytics = {
track: (...args) => { try { amplitude.track(...args); } catch (_) {} },
initAll: (...args) => { try { amplitude.initAll(...args); } catch (_) {} }
};
// -----------------------------------------
// 2. Application State (Single Source of Truth)
// -----------------------------------------
/**
* @typedef {Object} PropFirm
* @property {string} name
* @property {string} country
* @property {string} split
* @property {string} maxAccount
* @property {string} website
* @property {string} chain
* @property {boolean} isAffiliate
* @property {string} token
* @property {string} [bestSplit]
* @property {string} [payoutsVerified]
*/
const AppState = {
// GEN:BEGIN firm-data
/** @type {PropFirm[]} */
propFirms: [
{ name: "Hypernova", country: "Cayman Islands", split: "80%", maxAccount: "$200,000", profitTarget: "10%", dailyDrawdown: "3-5%", maxDrawdown: "6-8%", website: "https://hypernova.xyz/", chain: "Hyperliquid", isAffiliate: false, token: "No", payoutSpeed: "~5s", rulesOnchain: "Yes", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "Yes" },
{ name: "ProprXYZ", country: "BVI", split: "80%", maxAccount: "$200,000", profitTarget: "10%", dailyDrawdown: "3-5%", maxDrawdown: "6%", website: "https://app.propr.xyz/r/nCnJ5uZ9", chain: "Hyperliquid", isAffiliate: true, token: "Yes", payoutSpeed: "Soon", rulesOnchain: "No", aiAgents: "Yes", scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "Yes" },
{ name: "hyperpnl", country: "Cayman Islands", split: "80%", maxAccount: "$25k ($200k soon)", profitTarget: "10%/5%", dailyDrawdown: "5%", maxDrawdown: "9%", website: "https://app.hyperpnl.com/trade", chain: "Hyperliquid", isAffiliate: false, token: "No", payoutSpeed: "Soon", rulesOnchain: "No", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "Yes" },
{ name: "DojiFunded", country: "US (Delaware)", split: "Up to 90%", maxAccount: "$100,000", profitTarget: "10%", dailyDrawdown: "3-5%", maxDrawdown: "6-8%", website: "https://app.dojifunded.com/kol/onchainprops", chain: "Arbitrum", isAffiliate: false, token: "No", payoutSpeed: "TBC", rulesOnchain: "No", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: "Yes", bestSplit: undefined, payoutsVerified: "Yes" },
{ name: "Vanta Trading", country: "Cayman Islands", split: "100%", maxAccount: "$100,000", profitTarget: "8-10%", dailyDrawdown: "5%", maxDrawdown: "5%", website: "https://vantatrading.io/?ref=kamil", chain: "Bittensor / Hyperliquid", isAffiliate: true, token: "No", payoutSpeed: "Soon", rulesOnchain: "No", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: "Yes", payoutsVerified: "No" },
{ name: "Carrot Funding", country: "UAE", split: "Up to 80%", maxAccount: "$50k ($100k soon)", profitTarget: "8%", dailyDrawdown: "4-5%", maxDrawdown: "8-10%", website: "https://app.carrotfunding.io/join/2VSSOTXBQZ", chain: "gTrade, Hyperliquid (soon)", isAffiliate: true, token: "Yes", payoutSpeed: "Within 24h", rulesOnchain: "No", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "Yes" },
{ name: "HyperStack", country: "BVI", split: "Up to 90%", maxAccount: "$400,000", profitTarget: "10%", dailyDrawdown: "5%", maxDrawdown: "5%", website: "https://www.hyperstack.trade/rules", chain: "Hyperliquid", isAffiliate: false, token: "No", payoutSpeed: "TBC", rulesOnchain: "TBC", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "No" },
{ name: "FUNDED by FOXIFY", country: "BVI", split: "Up to 90%", maxAccount: "$10,000", profitTarget: "15%", dailyDrawdown: "N/A", maxDrawdown: "10-20%", website: "https://www.foxify.trade/", chain: "Hyperliquid (soon)", isAffiliate: false, token: "Yes", payoutSpeed: "Soon", rulesOnchain: "No", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: "No" }
],
/** @type {PropFirm[]} */
predictionMarketFirms: [
{ name: "Funding Predicts", country: "USA", split: "Up to 90%", maxAccount: "$150,000", profitTarget: undefined, dailyDrawdown: undefined, maxDrawdown: undefined, website: "https://fundingpredicts.com/", chain: "Polymarket", isAffiliate: false, token: "No", payoutSpeed: "Weekly", rulesOnchain: "TBC", aiAgents: undefined, scaledCapital: undefined, evalDataOnchain: undefined, bestSplit: undefined, payoutsVerified: undefined }
],
// GEN:END firm-data
/** @type {string|null} */
activeFaqId: null
};
/** Converts a firm name to a stable, URL-safe ID slug */
const toFirmId = (name) => name.toLowerCase().replace(/\s+/g, '_').replace(/[^a-z0-9_]/g, '');
/** Metadata for each page section — used for consistent event properties */
const SECTION_META = {
'firms': { name: 'Onchain Prop Firms', position: 1 },
'resources': { name: 'Resources', position: 2 },
'faq': { name: 'FAQ', position: 3 }
};
/** Section IDs whose outbound resource-item links fire Resource Link Opened */
const RESOURCE_SECTION_IDS = new Set(['resources']);
// -----------------------------------------
// 3. Web Components (Native Encapsulation)
// -----------------------------------------
const faqTemplate = document.createElement('template');
faqTemplate.innerHTML = `
<style>
:host {
display: block;
border: 1px solid var(--border-color, rgba(255,255,255,0.08));
border-radius: var(--radius-md, 14px);
background: var(--bg-card, rgba(255,255,255,0.03));
margin-bottom: 1rem;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
:host(:hover) {
border-color: rgba(255,255,255,0.15);
}
button {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.5rem 1.75rem;
background: none;
border: none;
color: var(--text-primary, #ffffff);
font-size: 1.15rem;
font-weight: 500;
font-family: inherit;
text-align: left;
cursor: pointer;
transition: all 0.3s ease;
min-height: 44px;
}
@media (max-width: 640px) {
button {
padding: 1.25rem;
font-size: 1rem;
}
.content-inner {
padding: 0 1.25rem 1.25rem;
}
}
button:hover {
color: var(--accent, #67d2b4);
}
.icon {
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
color: var(--text-secondary, #94a3b8);
}
button[aria-expanded="true"] .icon {
transform: rotate(180deg);
color: var(--accent, #67d2b4);
}
.content {
max-height: 0;
overflow: hidden;
transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.content-inner {
padding: 0 1.75rem 1.75rem;
color: var(--text-secondary, #94a3b8);
line-height: 1.7;
}
</style>
<button aria-expanded="false" id="accordion-btn">
<span id="question-text"></span>
<svg class="icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>
</button>
<div class="content" id="accordion-content" role="region" aria-labelledby="accordion-btn">
<div class="content-inner">
<slot></slot>
</div>
</div>
`;
class FaqAccordion extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(faqTemplate.content.cloneNode(true));
this.btn = this.shadowRoot.getElementById('accordion-btn');
this.content = this.shadowRoot.getElementById('accordion-content');
this.questionText = this.shadowRoot.getElementById('question-text');
this.faqId = `faq-${Math.random().toString(36).substring(2, 11)}`;
this.isOpen = false;
this.toggle = this.toggle.bind(this);
}
connectedCallback() {
// Build strictly unique ARIA mappings preventing screen-reader flattening errors
const btnId = `btn-${this.faqId}`;
const contentId = `content-${this.faqId}`;
this.btn.setAttribute('id', btnId);
this.btn.setAttribute('aria-controls', contentId);
this.content.setAttribute('id', contentId);
this.content.setAttribute('aria-labelledby', btnId);
this.questionText.textContent = this.getAttribute('question');
// Bound handler stored for unsubscription
this._onFaqToggled = (/** @type {string|null} */ activeId) => {
if (activeId !== this.faqId && this.isOpen) {
this.close();
}
};
this.btn.addEventListener('click', this.toggle);
Store.subscribe('FAQ_TOGGLED', this._onFaqToggled);
}
disconnectedCallback() {
this.btn.removeEventListener('click', this.toggle);
Store.unsubscribe('FAQ_TOGGLED', this._onFaqToggled);
}
toggle() {
if (this.isOpen) {
Store.publish('FAQ_TOGGLED', null);
this.close();
analytics.track('FAQ Collapsed', { question: this.getAttribute('question') });
} else {
Store.publish('FAQ_TOGGLED', this.faqId);
this.open();
analytics.track('FAQ Expanded', { question: this.getAttribute('question') });
}
}
open() {
this.isOpen = true;
this.btn.setAttribute('aria-expanded', 'true');
// requestAnimationFrame for smooth DOM reflow measurement
requestAnimationFrame(() => {
this.content.style.maxHeight = `${this.content.scrollHeight}px`;
});
}
close() {
this.isOpen = false;
this.btn.setAttribute('aria-expanded', 'false');
requestAnimationFrame(() => {
this.content.style.maxHeight = '0px';
});
}
}
customElements.define('faq-accordion', FaqAccordion);
// -----------------------------------------
// 3b. Performant DOM Rendering
// -----------------------------------------
/**
* Builds a single firm table row via the DOM API (prevents XSS injection).
* @param {PropFirm} firm
* @param {number} rank 1-based position within its table
* @param {{ showProfitTarget?: boolean }} [opts]
* @returns {HTMLTableRowElement}
*/
const buildFirmRow = (firm, rank, { showProfitTarget = false } = {}) => {
const row = document.createElement('tr');
row.dataset.firmName = firm.name;
row.dataset.firmRank = String(rank);
const firmSlug = firm.name.toLowerCase().replace(/[\s/]+/g, '-').replace(/[^a-z0-9-]/g, '');
const firmPageUrl = `firms/${firmSlug}`;
// The whole row hover-highlights like a card (see .prop-table tbody tr:hover),
// so make the rest of it navigate too — otherwise clicks on the split/account/
// token cells or trust chips land on plain text and register as dead clicks.
row.dataset.firmUrl = firmPageUrl;
const nameCell = document.createElement('td');
const nameLink = document.createElement('a');
nameLink.href = firmPageUrl;
nameLink.className = 'firm-name firm-name-link';
nameLink.textContent = firm.name;
const chainDiv = document.createElement('div');
chainDiv.style.cssText = 'font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px;';
chainDiv.textContent = firm.chain;
nameCell.append(nameLink, chainDiv);
// Payout-trust signal: rules enforced by smart contracts, verifiable onchain
if (firm.rulesOnchain === 'Yes') {
const trustChip = document.createElement('span');
trustChip.className = 'trust-chip';
trustChip.textContent = 'Rules onchain';
trustChip.title = 'Evaluation rules are enforced by smart contracts — verifiable on the blockchain';
nameLink.after(trustChip);
}
// Capability signal: firm supports trading by autonomous AI agents
if (firm.aiAgents === 'Yes') {
const aiChip = document.createElement('span');
aiChip.className = 'trust-chip trust-chip--ai';
aiChip.textContent = 'AI agents trading';
aiChip.title = 'Supports automated trading by AI agents';
nameLink.after(aiChip);
}
// Capability signal: account capital scales up as the trader performs
if (firm.scaledCapital === 'Yes') {
const scaleChip = document.createElement('span');
scaleChip.className = 'trust-chip trust-chip--capital';
scaleChip.textContent = 'Scaled capital';
scaleChip.title = 'Account size scales up as you hit profit targets';
nameLink.after(scaleChip);
}
// Transparency signal: evaluation trade-level data recorded onchain
if (firm.evalDataOnchain === 'Yes') {
const dataChip = document.createElement('span');
dataChip.className = 'trust-chip trust-chip--data';
dataChip.textContent = 'Eval trading data onchain';
dataChip.title = 'Every evaluation trade is recorded onchain — independently verifiable';
nameLink.after(dataChip);
}
// Standout signal: highest profit split among listed firms
if (firm.bestSplit === 'Yes') {
const splitChip = document.createElement('span');
splitChip.className = 'trust-chip trust-chip--split';
splitChip.textContent = 'Best profit split';
splitChip.title = 'Highest profit split among onchain prop firms in this directory';
nameLink.after(splitChip);
}
const splitCell = document.createElement('td');
splitCell.className = 'val-highlight';
splitCell.dataset.label = 'Profit Split';
splitCell.textContent = firm.split;
const accountCell = document.createElement('td');
accountCell.className = 'val-highlight';
accountCell.dataset.label = 'Max Account';
accountCell.textContent = firm.maxAccount;
const profitTargetCell = document.createElement('td');
profitTargetCell.dataset.label = 'Profit Target';
profitTargetCell.textContent = firm.profitTarget ?? 'TBC';
const dailyDrawdownCell = document.createElement('td');
dailyDrawdownCell.dataset.label = 'Daily Drawdown';
dailyDrawdownCell.textContent = firm.dailyDrawdown ?? 'TBC';
const maxDrawdownCell = document.createElement('td');
maxDrawdownCell.dataset.label = 'Max Drawdown';
maxDrawdownCell.textContent = firm.maxDrawdown ?? 'TBC';
const tokenCell = document.createElement('td');
tokenCell.className = 'val-highlight';
tokenCell.dataset.label = 'Token';
tokenCell.textContent = firm.token;
const payoutsVerifiedCell = document.createElement('td');
payoutsVerifiedCell.dataset.label = 'Payouts Verified';
if (firm.payoutsVerified === 'Yes') {
const check = document.createElement('span');
check.className = 'payout-verified-check';
check.setAttribute('aria-label', 'Payouts verified');
check.title = 'Payouts have been independently verified';
check.textContent = '✓';
payoutsVerifiedCell.appendChild(check);
} else {
payoutsVerifiedCell.textContent = '—';
}
const visitCell = document.createElement('td');
visitCell.dataset.label = 'Firm';
const linksDiv = document.createElement('div');
linksDiv.style.cssText = 'display: flex; gap: 0.75rem; align-items: center;';
const firmLink = document.createElement('a');
firmLink.href = firmPageUrl;
firmLink.className = 'btn btn-secondary firm-view-btn';
firmLink.setAttribute('aria-label', `View ${firm.name} details`);
firmLink.textContent = 'View →';
linksDiv.append(firmLink);
visitCell.appendChild(linksDiv);
if (showProfitTarget) {
row.append(nameCell, splitCell, accountCell, profitTargetCell, dailyDrawdownCell, maxDrawdownCell, payoutsVerifiedCell, visitCell);
} else {
row.append(nameCell, splitCell, accountCell, tokenCell, visitCell);
}
return row;
};
/**
* Renders the table using a DocumentFragment to minimize repaints.
* Attaches data attributes to each row for IntersectionObserver lookups.
*/
const renderPropFirmsTable = () => {
const tableBody = document.getElementById('firm-table-body');
if (!tableBody) return;
// Use DocumentFragment for batch insertions
const fragment = document.createDocumentFragment();
AppState.propFirms.forEach((firm, index) => {
fragment.appendChild(buildFirmRow(firm, index + 1, { showProfitTarget: true }));
});
// Single DOM insertion
tableBody.appendChild(fragment);
// Observe each row for Firm Card Viewed once rows are in the DOM
setupFirmCardObservers();
};
/**
* Renders the Prediction Markets prop firms table, mirroring the main table layout.
*/
const renderPredictionMarketsTable = () => {
const tableBody = document.getElementById('prediction-markets-table-body');
if (!tableBody) return;
const fragment = document.createDocumentFragment();
AppState.predictionMarketFirms.forEach((firm, index) => {
fragment.appendChild(buildFirmRow(firm, index + 1));
});
tableBody.appendChild(fragment);
};
// -----------------------------------------
// 5. IntersectionObserver — section and card visibility
// -----------------------------------------
/**
* Fires Firm List Viewed when the firms section enters the viewport,
* and Resources Section Viewed when the resources section enters the viewport.
* Each observer fires once then disconnects.
*/
const setupSectionObservers = () => {
const opts = { threshold: 0.1, rootMargin: '0px 0px -10% 0px' };
const firmsSection = document.getElementById('firms');
if (firmsSection) {
const firmsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
analytics.track('Firm List Viewed', {
'list name': SECTION_META['firms'].name,
'list position': SECTION_META['firms'].position
});
firmsObserver.unobserve(entry.target);
});
}, opts);
firmsObserver.observe(firmsSection);
}
const resourcesSection = document.getElementById('resources');
if (resourcesSection) {
const resourcesObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
analytics.track('Resources Section Viewed', {
'section name': SECTION_META['resources'].name,
'section position': SECTION_META['resources'].position
});
resourcesObserver.unobserve(entry.target);
});
}, opts);
resourcesObserver.observe(resourcesSection);
}
};
/**
* Fires Firm Card Viewed when at least 50% of each table row enters the viewport.
* Called after renderPropFirmsTable so the rows exist in the DOM.
*/
const setupFirmCardObservers = () => {
const rows = document.querySelectorAll('#firm-table-body tr');
if (!rows.length) return;
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const row = entry.target;
const firmName = row.dataset.firmName ?? '';
const firmRank = parseInt(row.dataset.firmRank ?? '0', 10);
analytics.track('Firm Card Viewed', {
'firm id': toFirmId(firmName),
'firm name': firmName,
'firm rank': firmRank,
'list position': firmRank
});
cardObserver.unobserve(row);
});
}, { threshold: 0.25 });
rows.forEach(row => cardObserver.observe(row));
};
/**
* Same card-viewed tracking for the prediction-markets table.
* Called after renderPredictionMarketsTable.
*/
const setupPredictionCardObservers = () => {
const rows = document.querySelectorAll('#prediction-markets-table-body tr');
if (!rows.length) return;
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const row = entry.target;
const firmName = row.dataset.firmName ?? '';
const firmRank = parseInt(row.dataset.firmRank ?? '0', 10);
analytics.track('Firm Card Viewed', {
'firm id': toFirmId(firmName),
'firm name': firmName,
'firm rank': firmRank,
'list position': firmRank
});
cardObserver.unobserve(row);
});
}, { threshold: 0.25 });
rows.forEach(row => cardObserver.observe(row));
};
// -----------------------------------------
// 6. Mobile Navigation
// -----------------------------------------
const setupMobileNav = () => {
const btn = document.getElementById('hamburger-btn');
const nav = document.getElementById('mobile-nav');
if (!btn || !nav) return;
btn.addEventListener('click', () => {
const isOpen = nav.classList.toggle('is-open');
btn.setAttribute('aria-expanded', String(isOpen));
nav.setAttribute('aria-hidden', String(!isOpen));
});
};
/**
* Resolves which AppState firms array a table row belongs to, based on its
* containing tbody — so click tracking works for both the main prop firms
* table and the prediction markets table.
* @param {Element} row
* @returns {PropFirm[] | null}
*/
const firmsArrayForRow = (row) => {
if (row.closest('#firm-table-body')) return AppState.propFirms;
if (row.closest('#prediction-markets-table-body')) return AppState.predictionMarketFirms;
return null;
};
// -----------------------------------------
// 7. Event Delegation — smooth scroll + analytics
// -----------------------------------------
const setupEventDelegation = () => {
document.body.addEventListener('click', (/** @type {MouseEvent} */ event) => {
if (!(event.target instanceof HTMLElement)) return;
/** @type {HTMLAnchorElement|null} */
const anchor = event.target.closest('a');
// Row-click fallback for the firm tables: the row already hover-highlights
// like a card, so clicking anywhere in it (not just the name/View link)
// should navigate too, instead of registering as a dead click.
if (!anchor) {
const row = event.target.closest('tr[data-firm-url]');
const hasSelection = (window.getSelection?.()?.toString() ?? '') !== '';
if (row && !hasSelection) {
const firmUrl = row.dataset.firmUrl;
const firmName = row.dataset.firmName ?? '';
const firmRank = parseInt(row.dataset.firmRank ?? '0', 10);
const firm = firmsArrayForRow(row)?.find(f => f.name === firmName);
if (firm) {
analytics.track('Firm Selected', {
'firm id': toFirmId(firm.name),
'firm name': firm.name,
'selection source': 'row_click',
'list position': firmRank
});
}
if (event.ctrlKey || event.metaKey) {
window.open(firmUrl, '_blank', 'noopener');
} else {
window.location.href = firmUrl;
}
}
return;
}
// Smooth scroll for in-page hash links
if (anchor && anchor.getAttribute('href')?.startsWith('#')) {
const hash = anchor.getAttribute('href');
if (hash === '#') return;
let targetElement = null;
try {
targetElement = document.querySelector(hash);
} catch (_) {
return;
}
if (targetElement) {
event.preventDefault();
// Close mobile nav on link click
const mobileNav = document.getElementById('mobile-nav');
const hamburgerBtn = document.getElementById('hamburger-btn');
if (mobileNav?.classList.contains('is-open')) {
mobileNav.classList.remove('is-open');
mobileNav.setAttribute('aria-hidden', 'true');
hamburgerBtn?.setAttribute('aria-expanded', 'false');
}
targetElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
return;
}
// Firm Selected — links inside either firm table (firm page or name click)
const anchorRow = anchor?.closest('tr[data-firm-url]');
const anchorFirms = anchorRow ? firmsArrayForRow(anchorRow) : null;
if (anchor && anchor.href && anchorFirms) {
const firmName = anchorRow.dataset.firmName ?? '';
const firmRank = parseInt(anchorRow.dataset.firmRank ?? '0', 10);
const firm = anchorFirms.find(f => f.name === firmName);
if (firm) {
const firmId = toFirmId(firm.name);
analytics.track('Firm Selected', {
'firm id': firmId,
'firm name': firm.name,
'selection source': anchor.classList.contains('firm-name-link') ? 'name_click' : 'firm_link',
'list position': firmRank
});
}
return;
}
// Resource Link Opened — outbound links inside the resources section
if (anchor && anchor.href) {
const section = anchor.closest('section');
const card = anchor.closest('.resource-item');
if (section && card && RESOURCE_SECTION_IDS.has(section.id)) {
const title = card.querySelector('.resource-title')?.textContent?.trim() ?? '';
const type = card.querySelector('.resource-tag')?.textContent?.trim()?.toLowerCase() ?? '';
let hostname = '';
try { hostname = new URL(anchor.href).hostname; } catch (_) {}
analytics.track('Resource Link Opened', {
'resource title': title,
'resource type': type,
'destination domain': hostname,
'section name': SECTION_META[section.id]?.name ?? section.id
});
}
}
});
};
/**
* Populate the Propr all-time revenue figure from DeFiLlama's free fees API.
* No-op on any page without the `#propr-revenue-value` element, so it's safe
* to run on every page. Errors degrade gracefully to "Unavailable".
* @returns {Promise<void>}
*/
const loadProprRevenue = async () => {
const el = document.getElementById('propr-revenue-value');
if (!el) return;
try {
const res = await fetch('https://api.llama.fi/summary/fees/propr?dataType=dailyRevenue');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
const total = data?.totalAllTime;
if (typeof total !== 'number') throw new Error('missing totalAllTime');
el.textContent = total.toLocaleString('en-US', {
style: 'currency', currency: 'USD', maximumFractionDigits: 0
});
} catch (e) {
el.textContent = 'Unavailable';
console.error('Propr revenue fetch failed:', e);
}
};
// -----------------------------------------
// Initialization
// -----------------------------------------
document.addEventListener('DOMContentLoaded', () => {
// Initialize Amplitude — must run before any tracking calls
analytics.initAll('488e252410ff9dc7ba7cfd5efac999f1', {
"analytics": {
// Hash-only navigation (#firms, #resources, #faq) scrolls within
// this single page — it isn't a real route change, so don't let
// it fire a duplicate Page View. Other autocapture categories
// (attribution, sessions, clicks, etc.) stay on by default.
"autocapture": { "pageViews": { "trackHistoryChanges": "pathOnly" } }
},
"sessionReplay": { "sampleRate": 1 }
});
// Initialize UI — errors here are reported to Amplitude
try {
renderPropFirmsTable();
renderPredictionMarketsTable();
setupPredictionCardObservers();
setupSectionObservers();
setupMobileNav();
setupEventDelegation();
loadProprRevenue();
} catch (e) {
console.error("App initialization failure:", e);
analytics.track('Error Encountered', {
'error category': 'initialization',
'error message': e?.message ?? 'Unknown error',
'error context': 'DOMContentLoaded setup',
'error code': null,
'http status code': null
});
}
});