-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathFeedList.tsx
More file actions
1780 lines (1677 loc) · 74.6 KB
/
FeedList.tsx
File metadata and controls
1780 lines (1677 loc) · 74.6 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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @jsxImportSource preact */
import { useEffect, useState, useRef, useMemo } from "preact/hooks"
import { MainnetTable, TestnetTable, StreamsNetworkAddressesTable, StreamsTHead, StreamsTr } from "./Tables.tsx"
import feedList from "./FeedList.module.css"
import tableStyles from "./Tables.module.css"
import { clsx } from "~/lib/clsx/clsx.ts"
import { Chain, CHAINS, ALL_CHAINS, ChainNetwork } from "~/features/data/chains.ts"
import { useGetChainMetadata } from "./useGetChainMetadata.ts"
import { ChainMetadata } from "~/features/data/api/index.ts"
import useQueryString from "~/hooks/useQueryString.ts"
import { RefObject } from "preact"
import { getFeedCategories } from "../../../db/feedCategories.js"
import SectionWrapper from "~/components/SectionWrapper/SectionWrapper.tsx"
import button from "@chainlink/design-system/button.module.css"
import { updateTableOfContents } from "~/components/TableOfContents/tocStore.ts"
import { ChainSelector } from "~/components/ChainSelector/ChainSelector.tsx"
import { isFeedVisible } from "../utils/feedVisibility.ts"
import { updateUrlClean, clearFilters } from "./urlStateHelpers.ts"
export type DataFeedType =
| "default"
| "smartdata"
| "rates"
| "usGovernmentMacroeconomicData"
| "streamsCrypto"
| "streamsRwa"
| "streamsNav"
| "streamsExRate"
| "streamsBacked"
type SchemaFilterValue = "all" | "v8" | "v11"
type StreamsRwaFeedTypeValue = "all" | "datalink" | "equities" | "forex"
type FilterOption<T extends string> = {
label: string
value: T
}
interface FilterDropdownProps<T extends string> {
label: string
options: FilterOption<T>[]
value: T
onSelect: (value: T) => void
isOpen: boolean
onToggle: (isOpen: boolean) => void
onClose: () => void
groupId: string
}
const schemaFilterOptions: FilterOption<SchemaFilterValue>[] = [
{ label: "All", value: "all" },
{ label: "RWA Standard (v8)", value: "v8" },
{ label: "RWA Advanced (v11)", value: "v11" },
]
const feedTypeFilterOptions: FilterOption<StreamsRwaFeedTypeValue>[] = [
{ label: "All", value: "all" },
{ label: "Datalink Streams", value: "datalink" },
{ label: "Equity Streams", value: "equities" },
{ label: "Forex Streams", value: "forex" },
]
const isSchemaFilterValue = (value: unknown): value is SchemaFilterValue =>
value === "all" || value === "v8" || value === "v11"
const isStreamsRwaFeedTypeValue = (value: unknown): value is StreamsRwaFeedTypeValue =>
value === "all" || value === "datalink" || value === "equities" || value === "forex"
const FilterDropdown = <T extends string>({
label,
options,
value,
onSelect,
isOpen,
onToggle,
onClose,
groupId,
}: FilterDropdownProps<T>) => {
const selectedOption = options.find((option) => option.value === value)
const isDefault = value === options[0]?.value
const summaryLabel = isDefault ? label : (selectedOption?.label ?? label)
return (
<details
class={feedList.filterDropdown_details}
data-hasvalue={isDefault ? "false" : "true"}
open={isOpen}
onToggle={(event) => onToggle(event.currentTarget.open)}
>
<summary class="text-200" title={summaryLabel}>
{summaryLabel}
</summary>
{isOpen && (
<nav>
<ul>
{options.map((option) => {
const isSelected = value === option.value
return (
<li key={option.value}>
<button
type="button"
onClick={() => {
onSelect(option.value)
onClose()
}}
style="user-select: none;"
>
<input type="radio" name={groupId} checked={isSelected} readOnly style="cursor:pointer;" />
<span style="user-select: none;">{option.label}</span>
</button>
</li>
)
})}
</ul>
</nav>
)}
</details>
)
}
export const FeedList = ({
initialNetwork,
dataFeedType = "default",
ecosystem = "",
initialCache,
allowNetworkTableExpansion = false,
defaultNetworkTableExpanded = false,
}: {
initialNetwork: string
dataFeedType: DataFeedType
ecosystem?: string
initialCache?: Record<string, ChainMetadata>
allowNetworkTableExpansion?: boolean
defaultNetworkTableExpanded?: boolean
}) => {
const chains = ecosystem === "deprecating" ? ALL_CHAINS : CHAINS
const isStreams =
dataFeedType === "streamsCrypto" ||
dataFeedType === "streamsRwa" ||
dataFeedType === "streamsNav" ||
dataFeedType === "streamsExRate" ||
dataFeedType === "streamsBacked"
const isSmartData = dataFeedType === "smartdata"
const isUSGovernmentMacroeconomicData = dataFeedType === "usGovernmentMacroeconomicData"
// Get network from URL parameters or fall back to initialNetwork
const getNetworkFromURL = () => {
if (typeof window === "undefined") return initialNetwork
const params = new URLSearchParams(window.location.search)
const networkParam = params.get("network")
return networkParam || initialNetwork
}
// Get network type from URL parameters (detect testnet from testnetSearch, testnetPage, or explicit networkType)
const getNetworkTypeFromURL = (): "mainnet" | "testnet" => {
if (typeof window === "undefined") return "mainnet"
const params = new URLSearchParams(window.location.search)
// Check explicit networkType parameter first
const networkType = params.get("networkType")
if (networkType === "testnet") {
return "testnet"
}
// If there's testnetSearch or testnetPage > 1, user is viewing testnet
const testnetSearch = params.get("testnetSearch")
const testnetPage = params.get("testnetPage")
if (testnetSearch || (testnetPage && testnetPage !== "1")) {
return "testnet"
}
return "mainnet"
}
// Initialize state with the URL value
const [currentNetwork, setCurrentNetwork] = useState(getNetworkFromURL())
// Sync with URL when it changes externally (browser back/forward)
useEffect(() => {
if (!isStreams && typeof window !== "undefined") {
const handleUrlChange = () => {
const networkFromURL = getNetworkFromURL()
if (networkFromURL !== currentNetwork) {
setCurrentNetwork(networkFromURL)
}
}
// Listen for popstate events (back/forward navigation)
window.addEventListener("popstate", handleUrlChange)
// Also check immediately in case URL was changed externally
handleUrlChange()
return () => {
window.removeEventListener("popstate", handleUrlChange)
}
}
}, [currentNetwork, isStreams])
// Sync with URL when it changes externally (browser back/forward)
useEffect(() => {
// Only run this effect on the client side after mount
if (typeof window !== "undefined") {
const latestNetworkFromURL = getNetworkFromURL()
if (latestNetworkFromURL !== currentNetwork) {
setCurrentNetwork(latestNetworkFromURL)
}
}
}, []) // Run only once on mount
// Additional sync for when window loads (fallback)
useEffect(() => {
if (typeof window !== "undefined") {
const handleLoad = () => {
const networkFromURL = getNetworkFromURL()
if (networkFromURL !== currentNetwork) {
setCurrentNetwork(networkFromURL)
}
}
// If window is already loaded, run immediately
if (document.readyState === "complete") {
handleLoad()
} else {
window.addEventListener("load", handleLoad)
return () => window.removeEventListener("load", handleLoad)
}
}
}, [])
// Track the selected network type (mainnet/testnet)
const [selectedNetworkType, setSelectedNetworkType] = useState<"mainnet" | "testnet">(getNetworkTypeFromURL())
// Sync network type with URL when it changes externally (browser back/forward)
useEffect(() => {
if (typeof window !== "undefined") {
const handleNetworkTypeUrlChange = () => {
const networkTypeFromURL = getNetworkTypeFromURL()
if (networkTypeFromURL !== selectedNetworkType) {
setSelectedNetworkType(networkTypeFromURL)
}
}
// Listen for popstate events (back/forward navigation)
window.addEventListener("popstate", handleNetworkTypeUrlChange)
// Also check immediately in case URL was changed externally
handleNetworkTypeUrlChange()
return () => {
window.removeEventListener("popstate", handleNetworkTypeUrlChange)
}
}
}, [selectedNetworkType])
// Track hydration state
const [isHydrated, setIsHydrated] = useState(false)
useEffect(() => {
setIsHydrated(true)
}, [])
// Regular query string states
const [searchValue, setSearchValue] = useQueryString("search")
const [testnetSearchValue, setTestnetSearchValue] = useQueryString("testnetSearch")
const [selectedFeedCategoriesRaw, setSelectedFeedCategories] = useQueryString("categories")
// Ensure categories is always an array
const selectedFeedCategories = Array.isArray(selectedFeedCategoriesRaw)
? selectedFeedCategoriesRaw
: selectedFeedCategoriesRaw
? [selectedFeedCategoriesRaw]
: []
const [currentPage, setCurrentPage] = useQueryString("page")
// Initialize all other states
const [showCategoriesDropdown, setShowCategoriesDropdown] = useState<boolean>(false)
const [streamCategoryFilterParam, setStreamCategoryFilterParam] = useQueryString("feedType")
const streamCategoryFilter =
typeof streamCategoryFilterParam === "string" && isStreamsRwaFeedTypeValue(streamCategoryFilterParam)
? streamCategoryFilterParam
: "all"
const setStreamCategoryFilter = (next: StreamsRwaFeedTypeValue) => {
setStreamCategoryFilterParam(next === "all" ? [] : next)
}
const [testnetStreamCategoryFilterParam, setTestnetStreamCategoryFilterParam] = useQueryString("testnetFeedType")
const testnetStreamCategoryFilter =
typeof testnetStreamCategoryFilterParam === "string" && isStreamsRwaFeedTypeValue(testnetStreamCategoryFilterParam)
? testnetStreamCategoryFilterParam
: "all"
const setTestnetStreamCategoryFilter = (next: StreamsRwaFeedTypeValue) => {
setTestnetStreamCategoryFilterParam(next === "all" ? [] : next)
}
// Checkbox states backed by URL params
const [showDetailsParam, setShowDetailsParam] = useQueryString("showDetails")
const showExtraDetails = showDetailsParam === "true"
const setShowExtraDetails = (value: boolean) => {
setShowDetailsParam(value ? "true" : "")
updateUrlClean({ showDetails: value || undefined })
}
const [showSvrParam, setShowSvrParam] = useQueryString("showSvr")
const showOnlySVR = showSvrParam === "true"
const setShowOnlySVR = (value: boolean) => {
setShowSvrParam(value ? "true" : "")
updateUrlClean({ showSvr: value || undefined })
if (value) paginate(1)
}
// MVR and DEX filters are not in URL (too specialized)
const [showOnlyMVRFeeds, setShowOnlyMVRFeeds] = useState(false)
const [showOnlyMVRFeedsTestnet, setShowOnlyMVRFeedsTestnet] = useState(false)
const [showOnlyDEXFeeds, setShowOnlyDEXFeeds] = useState(false)
const [showOnlyDEXFeedsTestnet, setShowOnlyDEXFeedsTestnet] = useState(false)
const [rwaSchemaFilterParam, setRwaSchemaFilterParam] = useQueryString("schema")
const rwaSchemaFilter =
typeof rwaSchemaFilterParam === "string" && isSchemaFilterValue(rwaSchemaFilterParam) ? rwaSchemaFilterParam : "all"
const setRwaSchemaFilter = (next: SchemaFilterValue) => {
setRwaSchemaFilterParam(next === "all" ? [] : next)
}
const [testnetRwaSchemaFilterParam, setTestnetRwaSchemaFilterParam] = useQueryString("testnetSchema")
const testnetRwaSchemaFilter =
typeof testnetRwaSchemaFilterParam === "string" && isSchemaFilterValue(testnetRwaSchemaFilterParam)
? testnetRwaSchemaFilterParam
: "all"
const setTestnetRwaSchemaFilter = (next: SchemaFilterValue) => {
setTestnetRwaSchemaFilterParam(next === "all" ? [] : next)
}
const [openDropdownId, setOpenDropdownId] = useState<string | null>(null)
const handleDropdownToggle = (dropdownId: string, isOpen: boolean) => {
setOpenDropdownId((current) => {
if (isOpen) {
return dropdownId
}
return current === dropdownId ? null : current
})
}
const closeAllDropdowns = () => setOpenDropdownId(null)
const paginate = (pageNumber) => {
const pageStr = String(pageNumber)
setCurrentPage(pageStr)
updateUrlClean({ page: pageNumber === 1 ? undefined : pageNumber })
}
const addrPerPage = ecosystem === "deprecating" && isStreams ? 10 : ecosystem === "deprecating" ? 10000 : 8
const currentPageNum = Number(currentPage) || 1
const lastAddr = currentPageNum * addrPerPage
const firstAddr = lastAddr - addrPerPage
// Pagination for testnet table
const [testnetCurrentPage, setTestnetCurrentPage] = useQueryString("testnetPage")
const testnetPaginate = (pageNumber) => {
const pageStr = String(pageNumber)
setTestnetCurrentPage(pageStr)
updateUrlClean({ testnetPage: pageNumber === 1 ? undefined : pageNumber })
}
const testnetAddrPerPage = ecosystem === "deprecating" && isStreams ? 10 : ecosystem === "deprecating" ? 10000 : 8
const testnetPageNum = Number(testnetCurrentPage) || 1
const testnetLastAddr = testnetPageNum * testnetAddrPerPage
const testnetFirstAddr = testnetLastAddr - testnetAddrPerPage
// Dynamic feed categories loaded from Supabase
const [dataFeedCategory, setDataFeedCategory] = useState([
{ key: "low", name: "Low Market Risk" },
{ key: "medium", name: "Medium Market Risk" },
{ key: "high", name: "High Market Risk" },
{ key: "veryhigh", name: "Very High Market Risk" },
{ key: "custom", name: "Custom" },
{ key: "new", name: "New Token" },
{ key: "deprecating", name: "Deprecating" },
])
// Load dynamic categories from Supabase on component mount
useEffect(() => {
const loadCategories = async () => {
try {
const categories = await getFeedCategories()
setDataFeedCategory(categories)
} catch (error) {}
}
loadCategories()
}, [])
const smartDataTypes = [
{ key: "Proof of Reserve", name: "Proof of Reserve" },
{ key: "NAVLink", name: "NAVLink" },
{ key: "SmartAUM", name: "SmartAUM" },
{ key: "Stablecoin Stability Assessment", name: "Stablecoin Stability Assessment" },
]
const [streamsChain] = useState(initialNetwork)
const activeChain = isStreams ? streamsChain : currentNetwork
// Find the selected chain from available chains
const selectedChain = useMemo(() => {
// During SSR, try to find the chain from URL param if activeChain is not available
if (!activeChain) {
// Check if we have a network param that we can use directly
if (typeof window !== "undefined") {
const urlParams = new URLSearchParams(window.location.search)
const networkParam = urlParams.get("network")
if (networkParam) {
const foundFromUrl = chains.find((c) => c.page === networkParam)
if (foundFromUrl) {
return foundFromUrl
}
}
}
return chains[0] // fallback only if no activeChain
}
const foundChain = chains.find((c) => c.page === activeChain)
if (!foundChain) {
return chains[0]
}
return foundChain
}, [activeChain, chains])
const chainMetadata = useGetChainMetadata(selectedChain, initialCache && initialCache[selectedChain.page])
const wrapperRef = useRef(null)
// scroll handler
useEffect(() => {
if (!chainMetadata.loading && chainMetadata.processedData) {
if (typeof window === "undefined") return
// Get the anchor from URL if present
const hash = window.location.hash.substring(1) // Remove the # character
// Force a delay to ensure DOM elements are rendered before updating
setTimeout(() => {
let hasUpdatedAnyId = false
// Find all section elements that need their IDs updated
chainMetadata.processedData?.networks.forEach((network) => {
const sectionId = network.name.toLowerCase().replace(/\s+/g, "-")
const existingSection = document.getElementById(sectionId)
// If section exists with correct ID, no need to update
if (existingSection) return
// Find section with network name title and update its ID
document.querySelectorAll("h3").forEach((heading) => {
if (heading.textContent === network.name) {
const section = heading.closest("section")
if (section) {
const oldId = section.id
section.id = sectionId
heading.id = sectionId
hasUpdatedAnyId = true
// Update anchor links inside the heading
const anchor = heading.querySelector("a")
if (anchor) {
anchor.href = `#${sectionId}`
}
// If we're updating the ID that matches our hash, we need to scroll to it
if (hash && (hash === oldId || hash === sectionId)) {
setTimeout(() => section.scrollIntoView({ behavior: "auto" }), 100)
}
}
}
})
})
// Also update testnet section if it exists
if (chainMetadata.processedData?.testnetNetwork) {
const testnetId =
chainMetadata.processedData.testnetNetwork.name.toLowerCase().replace(/\s+/g, "-") || "testnet-feeds"
document.querySelectorAll("h2").forEach((heading) => {
if (heading.textContent === "Testnet Feeds" || heading.textContent?.includes("Testnet")) {
const section = heading.closest("section")
if (section) {
const oldId = section.id
section.id = testnetId
heading.id = testnetId
hasUpdatedAnyId = true
// Update anchor links inside the heading
const anchor = heading.querySelector("a")
if (anchor) {
anchor.href = `#${testnetId}`
}
// If we're updating the ID that matches our hash, we need to scroll to it
if (hash && (hash === oldId || hash === testnetId)) {
setTimeout(() => section.scrollIntoView({ behavior: "auto" }), 100)
}
}
}
})
}
// If we have a hash but haven't scrolled yet, try to find the element with that ID
if (hash && hasUpdatedAnyId) {
const targetElement = document.getElementById(hash)
if (targetElement) {
setTimeout(() => targetElement.scrollIntoView({ behavior: "auto" }), 100)
}
} else if (hash) {
// Basic fallback if we didnt update any IDs but still have a hash
const targetElement = document.getElementById(hash)
if (targetElement) {
setTimeout(() => targetElement.scrollIntoView({ behavior: "auto" }), 200)
}
}
// Update TOC links if we made any ID changes
if (hasUpdatedAnyId) {
// Find the TOC container and update its links
const tocLinks = document.querySelectorAll(".toc-item a")
tocLinks.forEach((link) => {
const href = link.getAttribute("href")
if (href) {
const currentHash = href.split("#")[1]
if (currentHash) {
// Try to find element with this ID
const targetHeading = document.getElementById(currentHash)
if (targetHeading) {
// Update the TOC link to point to the correct ID
const updatedHref = window.location.pathname + window.location.search + "#" + currentHash
link.setAttribute("href", updatedHref)
}
}
}
})
// Trigger a TOC update
updateTableOfContents()
}
}, 300)
}
}, [chainMetadata.loading, chainMetadata.processedData, currentNetwork])
// Network selection handler
function handleNetworkSelect(chain: Chain) {
closeAllDropdowns()
if (!isStreams) {
setCurrentNetwork(chain.page)
// Clear all filters and pagination when switching networks
setSearchValue("")
setTestnetSearchValue("")
setSelectedFeedCategories([])
setCurrentPage("")
setTestnetCurrentPage("")
setShowOnlyMVRFeeds(false)
setShowOnlyMVRFeedsTestnet(false)
// Update URL with just the network (and networkType if not mainnet)
const params = new URLSearchParams(window.location.search)
const networkType = params.get("networkType")
updateUrlClean({
network: chain.page,
networkType: networkType === "testnet" ? "testnet" : undefined,
search: undefined,
testnetSearch: undefined,
page: undefined,
testnetPage: undefined,
})
}
}
// Network type change handler for testnet/mainnet switching
function handleNetworkTypeChange(networkType: "mainnet" | "testnet") {
closeAllDropdowns()
setSelectedNetworkType(networkType)
// Reset filters and pagination when switching network types
setSearchValue("")
setTestnetSearchValue("")
setSelectedFeedCategories([])
setCurrentPage("")
setTestnetCurrentPage("")
setShowOnlyMVRFeeds(false)
setShowOnlyMVRFeedsTestnet(false)
// Update URL with clean params
const params = new URLSearchParams(window.location.search)
const network = params.get("network")
updateUrlClean({
network: network || undefined,
networkType: networkType === "testnet" ? "testnet" : undefined,
search: undefined,
testnetSearch: undefined,
page: undefined,
testnetPage: undefined,
})
}
const handleCategorySelection = (category) => {
paginate(1)
if (typeof selectedFeedCategories === "string" && selectedFeedCategories !== category) {
setSelectedFeedCategories([selectedFeedCategories, category])
} else if (typeof selectedFeedCategories === "string" && selectedFeedCategories === category) {
setSelectedFeedCategories([])
}
if (Array.isArray(selectedFeedCategories) && selectedFeedCategories.includes(category)) {
setSelectedFeedCategories(selectedFeedCategories.filter((item) => item !== category))
} else if (Array.isArray(selectedFeedCategories)) {
setSelectedFeedCategories([...selectedFeedCategories, category])
}
}
useEffect(() => {
// Clean up empty search params
if (searchValue === "") {
updateUrlClean({ search: undefined })
}
if (testnetSearchValue === "") {
updateUrlClean({ testnetSearch: undefined })
}
}, [searchValue, testnetSearchValue])
const useOutsideAlerter = (ref: RefObject<HTMLDivElement>) => {
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (ref.current && event.target instanceof Node && !ref.current.contains(event.target)) {
setShowCategoriesDropdown(false)
}
}
document.addEventListener("mousedown", handleClickOutside)
return () => {
document.removeEventListener("mousedown", handleClickOutside)
}
}, [ref])
}
useOutsideAlerter(wrapperRef)
const isRates = dataFeedType === "rates"
const isDeprecating = ecosystem === "deprecating"
let netCount = 0
// Available network types for current feed type
const availableNetworkTypes = useMemo(() => {
if (!chainMetadata.processedData?.networks) return { mainnet: false, testnet: false }
const networkTypes = { mainnet: false, testnet: false }
// Filter networks by feed type
const filteredNetworks = chainMetadata.processedData.networks
.filter((network) => {
if (isDeprecating) {
let foundDeprecated = false
network.metadata?.forEach((feed: any) => {
if (feed.feedCategory === "deprecating") {
foundDeprecated = true
}
})
// A deprecating network is relevant only if it still has at least one non-hidden deprecating feed
if (!foundDeprecated) return false
const hasVisible = network.metadata?.some(
(feed: any) => feed.feedCategory === "deprecating" && !feed.docs?.hidden
)
return !!hasVisible
}
if (isStreams) return network.tags?.includes("streams")
if (isSmartData) return network.tags?.includes("smartData")
if (isRates) return network.tags?.includes("rates")
if (isUSGovernmentMacroeconomicData) return network.tags?.includes("usGovernmentMacroeconomicData")
return true
})
.filter((network) => {
// Ensure the network has at least one visible feed for the current dataFeedType
const feeds = network.metadata || []
return feeds.some((feed: any) => isFeedVisible(feed, dataFeedType, ecosystem))
})
// Check available network types
filteredNetworks.forEach((network) => {
if (network.networkType === "mainnet") {
networkTypes.mainnet = true
} else if (network.networkType === "testnet") {
networkTypes.testnet = true
}
})
return networkTypes
}, [
chainMetadata.processedData?.networks,
isDeprecating,
isStreams,
isSmartData,
isRates,
isUSGovernmentMacroeconomicData,
])
// Auto-switch network type if current selection isn't available
useEffect(() => {
if (!chainMetadata.loading && chainMetadata.processedData) {
const { mainnet, testnet } = availableNetworkTypes
if (selectedNetworkType === "mainnet" && !mainnet && testnet) {
setSelectedNetworkType("testnet")
// Update URL parameters to reflect the auto-switch
if (typeof window !== "undefined") {
const params = new URLSearchParams(window.location.search)
params.set("networkType", "testnet")
if (!params.get("testnetPage")) {
params.set("testnetPage", "1")
}
params.delete("testnetSearch") // Clear any previous testnet search
const newUrl = window.location.pathname + "?" + params.toString()
window.history.replaceState({ path: newUrl }, "", newUrl)
}
} else if (selectedNetworkType === "testnet" && !testnet && mainnet) {
setSelectedNetworkType("mainnet")
// Update URL parameters to reflect the auto-switch
if (typeof window !== "undefined") {
const params = new URLSearchParams(window.location.search)
params.delete("networkType")
params.delete("testnetSearch")
const newUrl = window.location.pathname + "?" + params.toString()
window.history.replaceState({ path: newUrl }, "", newUrl)
}
}
}
}, [
chainMetadata.loading,
chainMetadata.processedData,
availableNetworkTypes,
selectedNetworkType,
dataFeedType,
ecosystem,
])
const streamsMainnetSectionTitle =
dataFeedType === "streamsCrypto"
? "Mainnet Crypto Streams"
: dataFeedType === "streamsNav"
? "Mainnet SmartData Streams"
: dataFeedType === "streamsExRate"
? "Mainnet Exchange Rate Streams"
: dataFeedType === "streamsBacked"
? "Mainnet Tokenized Asset Streams"
: "Mainnet RWA Streams"
const streamsTestnetSectionTitle =
dataFeedType === "streamsCrypto"
? "Testnet Crypto Streams"
: dataFeedType === "streamsNav"
? "Testnet SmartData Streams"
: dataFeedType === "streamsExRate"
? "Testnet Exchange Rate Streams"
: dataFeedType === "streamsBacked"
? "Testnet Tokenized Asset Streams"
: "Testnet RWA Streams"
// Initialize search input fields with URL parameter values
useEffect(() => {
// mainnet
if (searchValue) {
const searchInputElement = document.getElementById("search") as HTMLInputElement
if (searchInputElement) {
searchInputElement.value = typeof searchValue === "string" ? searchValue : ""
}
}
// testnet
if (testnetSearchValue) {
const testnetInputElement = document.getElementById("testnetSearch") as HTMLInputElement
if (testnetInputElement) {
testnetInputElement.value = typeof testnetSearchValue === "string" ? testnetSearchValue : ""
}
}
}, [searchValue, testnetSearchValue, chainMetadata.loading])
if (
dataFeedType === "streamsCrypto" ||
dataFeedType === "streamsRwa" ||
dataFeedType === "streamsNav" ||
dataFeedType === "streamsExRate" ||
dataFeedType === "streamsBacked"
) {
// For deprecating streams, show two separate tables: mainnet and testnet
if (isDeprecating) {
const mainnetDeprecatingStreams: any[] = []
const testnetDeprecatingStreams: any[] = []
if (initialCache) {
Object.values(initialCache).forEach((chainData: any) => {
// Only check Arbitrum chains for streams
if (chainData.page === "arbitrum") {
chainData.networks?.forEach((network: any) => {
network.metadata?.forEach((item: any) => {
// Only include items that are actual streams (have verifier contract type and feedId)
// and have a shutdown date
if (item.contractType === "verifier" && item.feedId && item.docs?.shutdownDate) {
const streamWithNetwork = {
...item,
networkName: network.name,
}
if (network.networkType === "mainnet") {
mainnetDeprecatingStreams.push(streamWithNetwork)
} else if (network.networkType === "testnet") {
testnetDeprecatingStreams.push(streamWithNetwork)
}
}
})
})
}
})
}
// Sort alphabetically by asset name or product name
const sortStreams = (streams: any[]) => {
return streams.sort((a, b) => {
const nameA = (a.assetName || a.docs?.clicProductName || "").toUpperCase()
const nameB = (b.assetName || b.docs?.clicProductName || "").toUpperCase()
return nameA.localeCompare(nameB)
})
}
sortStreams(mainnetDeprecatingStreams)
sortStreams(testnetDeprecatingStreams)
// Apply search filter for mainnet
const filteredMainnetStreams = mainnetDeprecatingStreams.filter((stream) => {
if (!searchValue || typeof searchValue !== "string") return true
const searchLower = searchValue.toLowerCase()
return (
stream.feedId?.toLowerCase().includes(searchLower) ||
stream.assetName?.toLowerCase().includes(searchLower) ||
stream.feedType?.toLowerCase().includes(searchLower) ||
stream.networkName?.toLowerCase().includes(searchLower) ||
stream.docs?.clicProductName?.toLowerCase().includes(searchLower)
)
})
// Apply search filter for testnet
const filteredTestnetStreams = testnetDeprecatingStreams.filter((stream) => {
if (!testnetSearchValue || typeof testnetSearchValue !== "string") return true
const searchLower = testnetSearchValue.toLowerCase()
return (
stream.feedId?.toLowerCase().includes(searchLower) ||
stream.assetName?.toLowerCase().includes(searchLower) ||
stream.feedType?.toLowerCase().includes(searchLower) ||
stream.networkName?.toLowerCase().includes(searchLower) ||
stream.docs?.clicProductName?.toLowerCase().includes(searchLower)
)
})
// Calculate mainnet pagination
const paginatedMainnetStreams = filteredMainnetStreams.slice(firstAddr, lastAddr)
// Calculate testnet pagination
const paginatedTestnetStreams = filteredTestnetStreams.slice(testnetFirstAddr, testnetLastAddr)
return (
<>
{chainMetadata.loading && !chainMetadata.processedData && !initialCache && <p>Loading...</p>}
{chainMetadata.error && <p>There was an error loading the streams...</p>}
<SectionWrapper title="Mainnet Deprecating Streams" depth={2}>
<form class={feedList.filterDropdown_search}>
<input
id="search"
class={feedList.filterDropdown_searchInput}
placeholder="Search"
value={typeof searchValue === "string" ? searchValue : ""}
onInput={(event) => {
setSearchValue((event.target as HTMLInputElement).value)
setCurrentPage("1")
}}
/>
</form>
{filteredMainnetStreams.length > 0 ? (
<>
<div className={feedList.tableWrapper}>
<table className={clsx(tableStyles.table)}>
<StreamsTHead />
<tbody>
{paginatedMainnetStreams.map((stream, index) => (
<StreamsTr key={`${stream.feedId}-${index}`} metadata={stream} isMainnet={true} />
))}
</tbody>
</table>
</div>
{filteredMainnetStreams.length > addrPerPage && (
<div className={tableStyles.pagination} role="navigation" aria-label="Table pagination">
<button
className={button.secondary}
disabled={Number(currentPage) === 1}
onClick={() => paginate(Number(currentPage) - 1)}
>
Prev
</button>
<p aria-live="polite">
{firstAddr + 1}-
{lastAddr > filteredMainnetStreams.length ? filteredMainnetStreams.length : lastAddr} of{" "}
{filteredMainnetStreams.length}
</p>
<button
className={button.secondary}
disabled={lastAddr >= filteredMainnetStreams.length}
onClick={() => paginate(Number(currentPage) + 1)}
>
Next
</button>
</div>
)}
</>
) : (
<p>No mainnet deprecating streams found.</p>
)}
</SectionWrapper>
<SectionWrapper title="Testnet Deprecating Streams" depth={2}>
<form class={feedList.filterDropdown_search}>
<input
id="testnetSearch"
class={feedList.filterDropdown_searchInput}
placeholder="Search"
value={typeof testnetSearchValue === "string" ? testnetSearchValue : ""}
onInput={(event) => {
setTestnetSearchValue((event.target as HTMLInputElement).value)
setTestnetCurrentPage("1")
}}
/>
</form>
{filteredTestnetStreams.length > 0 ? (
<>
<div className={feedList.tableWrapper}>
<table className={clsx(tableStyles.table)}>
<StreamsTHead />
<tbody>
{paginatedTestnetStreams.map((stream, index) => (
<StreamsTr key={`${stream.feedId}-${index}`} metadata={stream} isMainnet={false} />
))}
</tbody>
</table>
</div>
{filteredTestnetStreams.length > testnetAddrPerPage && (
<div className={tableStyles.pagination} role="navigation" aria-label="Table pagination">
<button
className={button.secondary}
disabled={Number(testnetCurrentPage) === 1}
onClick={() => testnetPaginate(Number(testnetCurrentPage) - 1)}
>
Prev
</button>
<p aria-live="polite">
{testnetFirstAddr + 1}-
{testnetLastAddr > filteredTestnetStreams.length
? filteredTestnetStreams.length
: testnetLastAddr}{" "}
of {filteredTestnetStreams.length}
</p>
<button
className={button.secondary}
disabled={testnetLastAddr >= filteredTestnetStreams.length}
onClick={() => testnetPaginate(Number(testnetCurrentPage) + 1)}
>
Next
</button>
</div>
)}
</>
) : (
<p>No testnet deprecating streams found.</p>
)}
</SectionWrapper>
</>
)
}
// Regular streams view (non-deprecating)
const mainnetFeeds: ChainNetwork[] = []
const testnetFeeds: ChainNetwork[] = []
chainMetadata.processedData?.networks.forEach((network) => {
if (network.name.includes("Arbitrum")) {
if (network.networkType === "mainnet") {
mainnetFeeds.push(network)
} else if (network.networkType === "testnet") {
testnetFeeds.push(network)
}
}
})
return (
<>
{!isDeprecating && (
<>
{allowNetworkTableExpansion ? (
<div style={{ marginBottom: "var(--space-2x)" }}>
<StreamsNetworkAddressesTable
allowExpansion={allowNetworkTableExpansion}
defaultExpanded={defaultNetworkTableExpanded}
/>
</div>
) : (
<SectionWrapper title="Streams Verifier Network Addresses" depth={2}>
<StreamsNetworkAddressesTable
allowExpansion={allowNetworkTableExpansion}
defaultExpanded={defaultNetworkTableExpanded}
/>
</SectionWrapper>
)}
</>
)}