@@ -15,6 +15,7 @@ import {
1515 useRealInitializeEscrow ,
1616} from '@/lib/real-trustless-work' ;
1717import { assetConfig } from '@/lib/wallet-config' ;
18+ import { useAccount } from '@/contexts/AccountContext' ;
1819import { useToast } from '@/contexts/ToastContext' ;
1920import { useTransactionHistory } from '@/contexts/TransactionContext' ;
2021import { useDemoStats } from '@/hooks/useDemoStats' ;
@@ -50,6 +51,7 @@ export const DisputeResolutionDemo = () => {
5051 const { addToast } = useToast ( ) ;
5152 const { addTransaction, updateTransaction } = useTransactionHistory ( ) ;
5253 const { addCompletion, getDemoHistory, getTotalPointsEarned, getBestScore, getCompletionCount } = useDemoCompletionHistory ( ) ;
54+ const { completeDemo : completeDemoInAccount } = useAccount ( ) ;
5355 const [ contractId , setContractId ] = useState < string > ( '' ) ;
5456 const [ escrowData , setEscrowData ] = useState < any > ( null ) ;
5557 const [ currentRole , setCurrentRole ] = useState < 'client' | 'worker' | 'arbitrator' > ( 'client' ) ;
@@ -113,6 +115,7 @@ export const DisputeResolutionDemo = () => {
113115 client : 'client_wallet_address' ,
114116 } ,
115117 ] ) ;
118+ const [ isCompleted , setIsCompleted ] = useState ( false ) ;
116119
117120 // Trigger confetti when demo is completed
118121 useEffect ( ( ) => {
@@ -123,49 +126,29 @@ export const DisputeResolutionDemo = () => {
123126 milestones . map ( m => ( { id : m . id , status : m . status } ) )
124127 ) ;
125128
126- if ( allReleased ) {
129+ // Only complete if all milestones are released AND demo hasn't been completed yet
130+ if ( allReleased && ! isCompleted ) {
127131 console . log ( '🎉 Triggering confetti for Dispute Resolution Demo!' ) ;
128132 setShowConfetti ( true ) ;
133+ setIsCompleted ( true ) ; // Mark as completed to prevent multiple executions
129134
130- // Complete the demo in Firebase
135+ // Complete the demo using the centralized account system
131136 const completeDemo = async ( ) => {
132137 try {
133- const completionTime = 5 ; // Estimated completion time in minutes
134138 const score = 95 ; // High score for completing dispute resolution
135- const completionHistory = getDemoHistory ( 'dispute-resolution' ) ;
136- const isFirstCompletion = completionHistory . length === 0 ;
137139
138- // Calculate points earned
139- const basePoints = 150 ; // Higher base points for dispute resolution
140- const scoreMultiplier = score / 100 ;
141- let pointsEarned = Math . round ( basePoints * scoreMultiplier ) ;
142-
143- // Give reduced points for replays (25% of original)
144- if ( ! isFirstCompletion ) {
145- pointsEarned = Math . round ( pointsEarned * 0.25 ) ;
146- }
147-
148- // Add to completion history
149- addCompletion ( {
150- demoId : 'dispute-resolution' ,
151- demoName : 'Drama Queen Escrow' ,
152- score,
153- pointsEarned,
154- completionTime,
155- isFirstCompletion,
156- network : walletData ?. network || 'TESTNET' ,
157- walletAddress : walletData ?. publicKey || '' ,
158- } ) ;
159-
160- // Demo completion is handled by the account system via completeDemo
140+ // Use the centralized account system for completion
141+ await completeDemoInAccount ( 'dispute-resolution' , score ) ;
161142
143+ console . log ( '✅ Dispute Resolution Demo completed successfully' ) ;
144+ } catch ( error ) {
145+ console . error ( '❌ Failed to complete Dispute Resolution Demo:' , error ) ;
162146 addToast ( {
163- type : 'success' ,
164- title : 'Demo Completed!' ,
165- message : `Completed Drama Queen Escrow! Earned ${ pointsEarned } points! 🎉` ,
147+ type : 'error' ,
148+ title : '❌ Demo Completion Failed' ,
149+ message : 'Failed to complete demo. Please try again.' ,
150+ duration : 5000 ,
166151 } ) ;
167- } catch ( error ) {
168- console . error ( 'Failed to complete demo:' , error ) ;
169152 }
170153 } ;
171154
@@ -179,7 +162,7 @@ export const DisputeResolutionDemo = () => {
179162 } , 4000 ) ;
180163 return ( ) => clearTimeout ( timer ) ;
181164 }
182- } , [ milestones , addCompletion , getDemoHistory , walletData , addToast ] ) ;
165+ } , [ milestones , completeDemoInAccount , walletData , addToast , isCompleted ] ) ;
183166
184167 async function handleInitializeEscrow ( ) {
185168 if ( ! walletData ) {
0 commit comments