@@ -5,78 +5,125 @@ import { useEffect, useState } from "react";
55import type { Bundle } from "@/app/api/bundles/route" ;
66
77export default function BundlesPage ( ) {
8- const [ bundles , setBundles ] = useState < Bundle [ ] > ( [ ] ) ;
8+ const [ liveBundles , setLiveBundles ] = useState < Bundle [ ] > ( [ ] ) ;
9+ const [ allBundles , setAllBundles ] = useState < string [ ] > ( [ ] ) ;
910 const [ loading , setLoading ] = useState ( true ) ;
1011 const [ error , setError ] = useState < string | null > ( null ) ;
1112
1213 useEffect ( ( ) => {
13- const fetchBundles = async ( ) => {
14+ const fetchLiveBundles = async ( ) => {
1415 try {
1516 const response = await fetch ( "/api/bundles" ) ;
1617 if ( ! response . ok ) {
17- setError ( "Failed to fetch bundles" ) ;
18- setBundles ( [ ] ) ;
18+ setError ( "Failed to fetch live bundles" ) ;
19+ setLiveBundles ( [ ] ) ;
1920 return ;
2021 }
2122 const result = await response . json ( ) ;
22- setBundles ( result ) ;
23+ setLiveBundles ( result ) ;
2324 setError ( null ) ;
2425 } catch ( _err ) {
25- setError ( "Failed to fetch bundles" ) ;
26- setBundles ( [ ] ) ;
27- } finally {
28- setLoading ( false ) ;
26+ setError ( "Failed to fetch live bundles" ) ;
27+ setLiveBundles ( [ ] ) ;
2928 }
3029 } ;
3130
32- fetchBundles ( ) ;
31+ const fetchAllBundles = async ( ) => {
32+ try {
33+ const response = await fetch ( "/api/bundles/all" ) ;
34+ if ( ! response . ok ) {
35+ console . error ( "Failed to fetch all bundles from S3" ) ;
36+ setAllBundles ( [ ] ) ;
37+ return ;
38+ }
39+ const result = await response . json ( ) ;
40+ setAllBundles ( result ) ;
41+ } catch ( _err ) {
42+ console . error ( "Failed to fetch all bundles from S3" ) ;
43+ setAllBundles ( [ ] ) ;
44+ }
45+ } ;
46+
47+ const fetchData = async ( ) => {
48+ await Promise . all ( [ fetchLiveBundles ( ) , fetchAllBundles ( ) ] ) ;
49+ setLoading ( false ) ;
50+ } ;
3351
34- const interval = setInterval ( fetchBundles , 400 ) ;
52+ fetchData ( ) ;
53+
54+ const interval = setInterval ( fetchLiveBundles , 400 ) ;
3555
3656 return ( ) => clearInterval ( interval ) ;
3757 } , [ ] ) ;
3858
3959 if ( loading ) {
4060 return (
4161 < div className = "flex flex-col gap-4 p-8" >
42- < h1 className = "text-2xl font-bold" > Bundles </ h1 >
62+ < h1 className = "text-2xl font-bold" > BundleStore (fka Mempool) </ h1 >
4363 < div className = "animate-pulse" > Loading bundles...</ div >
4464 </ div >
4565 ) ;
4666 }
4767
4868 return (
49- < div className = "flex flex-col gap-6 p-8" >
69+ < div className = "flex flex-col gap-8 p-8" >
5070 < div className = "flex flex-col gap-2" >
51- < h1 className = "text-2xl font-bold" > Bundles </ h1 >
71+ < h1 className = "text-2xl font-bold" > BundleStore (fka Mempool) </ h1 >
5272 { error && (
5373 < div className = "text-sm text-red-600 dark:text-red-400" > { error } </ div >
5474 ) }
5575 </ div >
5676
57- { bundles . length > 0 ? (
58- < ul className = "space-y-2" >
59- { bundles . map ( ( bundle ) => (
60- < li key = { bundle . id } >
61- < Link
62- href = { `/bundle/${ bundle . id } ` }
63- className = "block p-3 border rounded-lg bg-white/5 hover:bg-white/10 transition-colors"
64- >
65- < span className = "font-mono text-sm" >
66- { bundle . id }
67- { " (" }
68- { bundle . txnHashes ?. join ( ", " ) || "No transactions" }
69- { ")" }
70- </ span >
71- </ Link >
72- </ li >
73- ) ) }
74- </ ul >
75- ) : (
76- < p className = "text-gray-600 dark:text-gray-400" >
77- { loading ? "Loading bundles..." : "No bundles found." }
78- </ p >
79- ) }
77+ < div className = "flex flex-col gap-6" >
78+ < section >
79+ < h2 className = "text-xl font-semibold mb-4" > Live Bundles</ h2 >
80+ { liveBundles . length > 0 ? (
81+ < ul className = "space-y-2" >
82+ { liveBundles . map ( ( bundle ) => (
83+ < li key = { bundle . id } >
84+ < Link
85+ href = { `/bundles/${ bundle . id } ` }
86+ className = "block p-3 border rounded-lg bg-white/5 hover:bg-white/10 transition-colors"
87+ >
88+ < span className = "font-mono text-sm" >
89+ { bundle . id }
90+ { " (" }
91+ { bundle . txnHashes ?. join ( ", " ) || "No transactions" }
92+ { ")" }
93+ </ span >
94+ </ Link >
95+ </ li >
96+ ) ) }
97+ </ ul >
98+ ) : (
99+ < p className = "text-gray-600 dark:text-gray-400" >
100+ No live bundles found.
101+ </ p >
102+ ) }
103+ </ section >
104+
105+ < section >
106+ < h2 className = "text-xl font-semibold mb-4" > All Bundles</ h2 >
107+ { allBundles . length > 0 ? (
108+ < ul className = "space-y-2" >
109+ { allBundles . map ( ( bundleId ) => (
110+ < li key = { bundleId } >
111+ < Link
112+ href = { `/bundles/${ bundleId } ` }
113+ className = "block p-3 border rounded-lg bg-white/5 hover:bg-white/10 transition-colors"
114+ >
115+ < span className = "font-mono text-sm" > { bundleId } </ span >
116+ </ Link >
117+ </ li >
118+ ) ) }
119+ </ ul >
120+ ) : (
121+ < p className = "text-gray-600 dark:text-gray-400" >
122+ No bundles found in S3.
123+ </ p >
124+ ) }
125+ </ section >
126+ </ div >
80127 </ div >
81128 ) ;
82129}
0 commit comments