1- import React from 'react' ;
2- import { downloadCSV } from '../utils/csvExport' ;
1+ import { ActivityHistory } from './dashboard/ActivityHistory' ;
2+ import { fetchUserEvents } from '@/lib/dashboard' ;
3+ import { useWallet } from '@/context/wallet-context' ;
4+ import { BackendStreamEvent } from '@/lib/api-types' ;
35
46interface StreamData extends Record < string , unknown > {
57 id : string ;
@@ -21,6 +23,30 @@ const mockStreams: StreamData[] = [
2123] ;
2224
2325const Dashboard : React . FC = ( ) => {
26+ const { session } = useWallet ( ) ;
27+ const [ activeTab , setActiveTab ] = React . useState < 'streams' | 'activity' > ( 'streams' ) ;
28+ const [ events , setEvents ] = React . useState < BackendStreamEvent [ ] > ( [ ] ) ;
29+ const [ isLoadingEvents , setIsLoadingEvents ] = React . useState ( false ) ;
30+
31+ React . useEffect ( ( ) => {
32+ if ( activeTab === 'activity' && session ?. publicKey ) {
33+ loadEvents ( ) ;
34+ }
35+ } , [ activeTab , session ?. publicKey ] ) ;
36+
37+ const loadEvents = async ( ) => {
38+ if ( ! session ?. publicKey ) return ;
39+ setIsLoadingEvents ( true ) ;
40+ try {
41+ const data = await fetchUserEvents ( session . publicKey ) ;
42+ setEvents ( data ) ;
43+ } catch ( error ) {
44+ console . error ( error ) ;
45+ } finally {
46+ setIsLoadingEvents ( false ) ;
47+ }
48+ } ;
49+
2450 const handleExport = ( ) => {
2551 downloadCSV ( mockStreams , 'flowfi-stream-history.csv' ) ;
2652 } ;
@@ -37,59 +63,78 @@ const Dashboard: React.FC = () => {
3763 return (
3864 < div className = "p-8" >
3965 < div className = "flex justify-between items-center mb-6" >
40- < h1 className = "text-2xl font-bold text-gray-800 dark:text-white" > Stream History</ h1 >
41- < button
42- onClick = { handleExport }
43- className = "bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded shadow transition-colors"
44- >
45- Export CSV
46- </ button >
66+ < div className = "flex items-center gap-6" >
67+ < button
68+ onClick = { ( ) => setActiveTab ( 'streams' ) }
69+ className = { `text-2xl font-bold transition-colors ${ activeTab === 'streams' ? 'text-gray-800 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-200' } ` }
70+ >
71+ Stream History
72+ </ button >
73+ < button
74+ onClick = { ( ) => setActiveTab ( 'activity' ) }
75+ className = { `text-2xl font-bold transition-colors ${ activeTab === 'activity' ? 'text-gray-800 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-200' } ` }
76+ >
77+ Activity
78+ </ button >
79+ </ div >
80+ { activeTab === 'streams' && (
81+ < button
82+ onClick = { handleExport }
83+ className = "bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded shadow transition-colors"
84+ >
85+ Export CSV
86+ </ button >
87+ ) }
4788 </ div >
4889
49- < div className = "overflow-x-auto bg-white dark:bg-gray-800 shadow rounded-lg" >
50- < table className = "min-w-full divide-y divide-gray-200 dark:divide-gray-700" >
51- < thead className = "bg-gray-50 dark:bg-gray-900" >
52- < tr >
53- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Date</ th >
54- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Recipient</ th >
55- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Deposited</ th >
56- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Withdrawn</ th >
57- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Token</ th >
58- < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Status</ th >
59- < th className = "px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Actions</ th >
60- </ tr >
61- </ thead >
62- < tbody className = "bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700" >
63- { mockStreams . map ( ( stream ) => (
64- < tr key = { stream . id } className = "hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors" >
65- < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100" > { stream . date } </ td >
66- < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 font-mono" > { stream . recipient } </ td >
67- < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100 font-semibold" > { stream . deposited } { stream . token } </ td >
68- < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400" > { stream . withdrawn } { stream . token } </ td >
69- < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400" > { stream . token } </ td >
70- < td className = "px-6 py-4 whitespace-nowrap text-sm" >
71- < span className = { `px-2 inline-flex text-xs leading-5 font-semibold rounded-full
72- ${ stream . status === 'Active' ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' :
73- stream . status === 'Completed' ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200' :
74- 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200' } `} >
75- { stream . status }
76- </ span >
77- </ td >
78- < td className = "px-6 py-4 whitespace-nowrap text-right text-sm font-medium" >
79- { stream . status === 'Active' && (
80- < button
81- onClick = { ( ) => handleTopUp ( stream . id ) }
82- className = "text-green-600 hover:text-green-900 dark:text-green-400 dark:hover:text-green-300 bg-green-50 dark:bg-green-900/20 px-3 py-1 rounded-md transition-colors font-semibold"
83- >
84- Add Funds
85- </ button >
86- ) }
87- </ td >
90+ { activeTab === 'streams' ? (
91+ < div className = "overflow-x-auto bg-white dark:bg-gray-800 shadow rounded-lg" >
92+ < table className = "min-w-full divide-y divide-gray-200 dark:divide-gray-700" >
93+ < thead className = "bg-gray-50 dark:bg-gray-900" >
94+ < tr >
95+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Date</ th >
96+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Recipient</ th >
97+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Deposited</ th >
98+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Withdrawn</ th >
99+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Token</ th >
100+ < th className = "px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Status</ th >
101+ < th className = "px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider" > Actions</ th >
88102 </ tr >
89- ) ) }
90- </ tbody >
91- </ table >
92- </ div >
103+ </ thead >
104+ < tbody className = "bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700" >
105+ { mockStreams . map ( ( stream ) => (
106+ < tr key = { stream . id } className = "hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors" >
107+ < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100" > { stream . date } </ td >
108+ < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 font-mono" > { stream . recipient } </ td >
109+ < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100 font-semibold" > { stream . deposited } { stream . token } </ td >
110+ < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400" > { stream . withdrawn } { stream . token } </ td >
111+ < td className = "px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400" > { stream . token } </ td >
112+ < td className = "px-6 py-4 whitespace-nowrap text-sm" >
113+ < span className = { `px-2 inline-flex text-xs leading-5 font-semibold rounded-full
114+ ${ stream . status === 'Active' ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' :
115+ stream . status === 'Completed' ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200' :
116+ 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200' } `} >
117+ { stream . status }
118+ </ span >
119+ </ td >
120+ < td className = "px-6 py-4 whitespace-nowrap text-right text-sm font-medium" >
121+ { stream . status === 'Active' && (
122+ < button
123+ onClick = { ( ) => handleTopUp ( stream . id ) }
124+ className = "text-green-600 hover:text-green-900 dark:text-green-400 dark:hover:text-green-300 bg-green-50 dark:bg-green-900/20 px-3 py-1 rounded-md transition-colors font-semibold"
125+ >
126+ Add Funds
127+ </ button >
128+ ) }
129+ </ td >
130+ </ tr >
131+ ) ) }
132+ </ tbody >
133+ </ table >
134+ </ div >
135+ ) : (
136+ < ActivityHistory events = { events } isLoading = { isLoadingEvents } />
137+ ) }
93138 </ div >
94139 ) ;
95140} ;
0 commit comments