From 9146a69c9918f803c1cb4ea0b9978e269fcdb597 Mon Sep 17 00:00:00 2001 From: zramsay Date: Fri, 21 Mar 2025 20:31:11 -0400 Subject: [PATCH] go --- src/app/api/analyze/route.ts | 7 +++++++ src/app/points/page.tsx | 10 ++++++++++ src/components/WildlifeIdentifier.tsx | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/app/api/analyze/route.ts b/src/app/api/analyze/route.ts index 3af695d..dd33253 100644 --- a/src/app/api/analyze/route.ts +++ b/src/app/api/analyze/route.ts @@ -393,6 +393,13 @@ export async function POST(req: NextRequest): Promise { species }); + // Log wallet address for debugging token award + console.log('Starting token award with address:', { + walletAddressFromForm: walletAddress, + species: species, + hasAddress: !!walletAddress + }); + // Attempt to award tokens for this wildlife sighting const tokenResult = await awardTokensForSighting(species, undefined, walletAddress); diff --git a/src/app/points/page.tsx b/src/app/points/page.tsx index 557461e..5f2021f 100644 --- a/src/app/points/page.tsx +++ b/src/app/points/page.tsx @@ -38,6 +38,16 @@ export default function PointsPage() { if (userIdentifier) { console.log('Loading points using email identifier:', userIdentifier); loadUserPoints(userIdentifier); + + // Set up an interval to refresh points periodically + const refreshInterval = setInterval(() => { + console.log('Automatically refreshing points data...'); + loadUserPoints(userIdentifier); + }, 10000); // Refresh every 10 seconds + + return () => { + clearInterval(refreshInterval); + }; } else { // Fallback to ID if somehow email is missing const userId = session.user.id; diff --git a/src/components/WildlifeIdentifier.tsx b/src/components/WildlifeIdentifier.tsx index 1906def..3755964 100644 --- a/src/components/WildlifeIdentifier.tsx +++ b/src/components/WildlifeIdentifier.tsx @@ -66,9 +66,27 @@ const WildlifeIdentifier: React.FC = () => { formData.append('image', selectedImage); // Add wallet address to the request if connected - const userAddress = getWalletAddress(); + // Get the wallet address both from memory and localStorage as backup + let userAddress = getWalletAddress(); + + // If no in-memory address, try localStorage as fallback + if (!userAddress && typeof window !== 'undefined') { + try { + const storedAddress = localStorage.getItem('wildlife_wallet_address'); + if (storedAddress) { + console.log('Using wallet address from localStorage:', storedAddress); + userAddress = storedAddress; + } + } catch (e) { + console.warn('Error accessing localStorage:', e); + } + } + if (userAddress) { + console.log('Found wallet address to include in upload:', userAddress); formData.append('walletAddress', userAddress); + } else { + console.log('No wallet address found for upload'); } console.log('Uploading image for analysis...');