@@ -156,11 +156,37 @@ export function FlappyBird({
156156
157157 // Burn the power-up on blockchain
158158 try {
159- if ( window . burnPowerUp ) {
160- const tokenId = type === "slowmo" ? 4 : 5 ;
161- await window . burnPowerUp ( tokenId , 1 ) ;
162- console . log ( "Power-up burned successfully:" , type ) ;
159+ const tokenId = type === "slowmo" ? 4 : 5 ;
160+
161+ // Get CSRF token from cookies
162+ const getCsrfToken = ( ) => {
163+ const cookies = document . cookie . split ( ";" ) ;
164+ const csrfCookie = cookies . find ( ( cookie ) =>
165+ cookie . trim ( ) . startsWith ( "csrf-token=" ) ,
166+ ) ;
167+ return csrfCookie ? csrfCookie . split ( "=" ) [ 1 ] : null ;
168+ } ;
169+
170+ const csrfToken = getCsrfToken ( ) ;
171+
172+ const response = await fetch ( "/api/burn-powerup" , {
173+ method : "POST" ,
174+ headers : {
175+ "Content-Type" : "application/json" ,
176+ "x-csrf-token" : csrfToken || "" ,
177+ } ,
178+ body : JSON . stringify ( {
179+ tokenId,
180+ quantity : 1 ,
181+ } ) ,
182+ } ) ;
183+
184+ if ( ! response . ok ) {
185+ throw new Error ( `Burn failed: ${ response . status } ` ) ;
163186 }
187+
188+ const result = await response . json ( ) ;
189+ console . log ( "Power-up burned successfully:" , type , result ) ;
164190 } catch ( error ) {
165191 console . error ( "Failed to burn power-up:" , error ) ;
166192 // Revert local count if burn failed
0 commit comments