@@ -14,6 +14,18 @@ import {
1414 PREDEFINED_BADGES ,
1515 getBadgeById
1616} from '../../lib/firebase/firebase-types' ;
17+
18+ // DemoCard interface
19+ interface DemoCard {
20+ id : string ;
21+ title : string ;
22+ subtitle : string ;
23+ description : string ;
24+ icon : string ;
25+ color : string ;
26+ isReady : boolean ;
27+ multiStakeholderRequired : boolean ;
28+ }
1729import { useBadgeAnimation } from '../ui/BadgeAnimationContext' ;
1830import { useToast } from '../ui/ToastContext' ;
1931import { useTransactionHistory } from './TransactionContext' ;
@@ -23,7 +35,7 @@ interface FirebaseContextType {
2335 account : Account | null ;
2436
2537 // Static data
26- demos : typeof PREDEFINED_DEMOS ;
38+ demos : DemoCard [ ] ;
2739 badges : typeof PREDEFINED_BADGES ;
2840 demoStats : DemoStats [ ] ;
2941
@@ -71,7 +83,17 @@ export const FirebaseProvider: React.FC<FirebaseProviderProps> = ({ children })
7183 // Initialize account data when wallet connects
7284 useEffect ( ( ) => {
7385 const initializeFirebase = async ( ) => {
74- if ( ! walletData ?. publicKey ) return ;
86+ // Always load demo stats (public data)
87+ try {
88+ await loadDemoStats ( ) ;
89+ } catch ( error ) {
90+ console . error ( 'Error loading demo stats:' , error ) ;
91+ }
92+
93+ if ( ! walletData ?. publicKey ) {
94+ setIsInitialized ( true ) ;
95+ return ;
96+ }
7597
7698 setIsLoading ( true ) ;
7799 try {
@@ -110,8 +132,8 @@ export const FirebaseProvider: React.FC<FirebaseProviderProps> = ({ children })
110132 } ) ;
111133 }
112134
113- // Load account data and demo stats
114- await Promise . all ( [ loadAccountData ( ) , loadDemoStats ( ) ] ) ;
135+ // Load account data ( demo stats already loaded above)
136+ await loadAccountData ( ) ;
115137 setIsInitialized ( true ) ;
116138 } catch ( error ) {
117139 addToast ( {
@@ -147,7 +169,31 @@ export const FirebaseProvider: React.FC<FirebaseProviderProps> = ({ children })
147169 // Load demo stats
148170 const loadDemoStats = async ( ) => {
149171 try {
150- const stats = await demoStatsService . getAllDemoStats ( ) ;
172+ let stats = await demoStatsService . getAllDemoStats ( ) ;
173+
174+ // If no stats exist, initialize them for all demos
175+ if ( stats . length === 0 ) {
176+ console . log ( 'No demo stats found, initializing...' ) ;
177+ const demos = [
178+ { id : 'hello-milestone' , name : 'Baby Steps to Riches' } ,
179+ { id : 'dispute-resolution' , name : 'Drama Queen Escrow' } ,
180+ { id : 'micro-marketplace' , name : 'Gig Economy Madness' } ,
181+ { id : 'nexus-master' , name : 'Nexus Master Achievement' } ,
182+ ] ;
183+
184+ for ( const demo of demos ) {
185+ try {
186+ await demoStatsService . initializeDemoStats ( demo . id , demo . name ) ;
187+ console . log ( `✅ Initialized stats for ${ demo . name } (${ demo . id } )` ) ;
188+ } catch ( error ) {
189+ console . error ( `❌ Failed to initialize stats for ${ demo . name } (${ demo . id } ):` , error ) ;
190+ }
191+ }
192+
193+ // Reload stats after initialization
194+ stats = await demoStatsService . getAllDemoStats ( ) ;
195+ }
196+
151197 setDemoStats ( stats ) ;
152198 } catch ( error ) {
153199 console . error ( 'Error loading demo stats:' , error ) ;
@@ -261,7 +307,6 @@ export const FirebaseProvider: React.FC<FirebaseProviderProps> = ({ children })
261307
262308 // Update demo stats for global tracking
263309 try {
264- console . log ( 'FirebaseContext: Updating demo stats for:' , demoId ) ;
265310 await demoStatsService . incrementCompletion ( demoId , completionTimeMinutes , finalScore ) ;
266311 } catch ( statsError ) {
267312 console . error ( 'FirebaseContext: Failed to update demo stats:' , statsError ) ;
@@ -430,9 +475,53 @@ export const FirebaseProvider: React.FC<FirebaseProviderProps> = ({ children })
430475 }
431476 } ;
432477
478+ // Convert PREDEFINED_DEMOS to DemoCard format
479+ const demos : DemoCard [ ] = [
480+ {
481+ id : 'hello-milestone' ,
482+ title : '1. Baby Steps to Riches' ,
483+ subtitle : 'Basic Escrow Flow Demo' ,
484+ description : PREDEFINED_DEMOS [ 0 ] . description ,
485+ icon : '🎮' ,
486+ color : 'from-brand-500 to-brand-400' ,
487+ isReady : true ,
488+ multiStakeholderRequired : false ,
489+ } ,
490+ {
491+ id : 'dispute-resolution' ,
492+ title : '2. Drama Queen Escrow' ,
493+ subtitle : 'Dispute Resolution & Arbitration' ,
494+ description : PREDEFINED_DEMOS [ 1 ] . description ,
495+ icon : '🎮' ,
496+ color : 'from-warning-500 to-warning-400' ,
497+ isReady : true ,
498+ multiStakeholderRequired : false ,
499+ } ,
500+ {
501+ id : 'micro-marketplace' ,
502+ title : '3. Gig Economy Madness' ,
503+ subtitle : 'Micro-Task Marketplace' ,
504+ description : PREDEFINED_DEMOS [ 2 ] . description ,
505+ icon : '🎮' ,
506+ color : 'from-accent-500 to-accent-400' ,
507+ isReady : true ,
508+ multiStakeholderRequired : false ,
509+ } ,
510+ {
511+ id : 'nexus-master' ,
512+ title : 'Nexus Master Achievement' ,
513+ subtitle : 'Complete All Main Badges' ,
514+ description : 'The ultimate achievement! Complete all three main demos to unlock the legendary Nexus Master badge and claim your place among the elite.' ,
515+ icon : '/images/demos/economy.png' ,
516+ color : 'from-gray-500 to-gray-400' ,
517+ isReady : false ,
518+ multiStakeholderRequired : false ,
519+ } ,
520+ ] ;
521+
433522 const value : FirebaseContextType = {
434523 account,
435- demos : PREDEFINED_DEMOS ,
524+ demos,
436525 badges : PREDEFINED_BADGES ,
437526 demoStats,
438527 isLoading,
0 commit comments