Skip to content

Commit 34d5675

Browse files
committed
fix build issue
1 parent 0e6959d commit 34d5675

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

components/CyberShop.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,8 @@ export function CyberShop({
146146
setLoadingStates((prev) => ({ ...prev, [tokenId]: false }));
147147
}
148148
};
149-
// Expose burnPowerUp function globally for game to use
150-
useEffect(() => {
151-
(window as any).burnPowerUp = burnPowerUp;
152-
return () => {
153-
delete (window as any).burnPowerUp;
154-
};
155-
}, [burnPowerUp]);
149+
// Note: burnPowerUp function is no longer exposed globally
150+
// FlappyBird component now calls the API directly
156151

157152
return (
158153
<div className="mt-12">

components/FlappyBird.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

types/window.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Extend the Window interface to include audio functions
2+
declare global {
3+
interface Window {
4+
audioOnJump?: () => void;
5+
audioOnCrash?: () => void;
6+
audioOnCoinCollect?: () => void;
7+
}
8+
}
9+
10+
export {};

0 commit comments

Comments
 (0)