mirror of
https://github.com/mito-systems/ranger-app.git
synced 2026-03-18 16:34:10 +00:00
wallet fixes
This commit is contained in:
parent
9146a69c99
commit
70ee3ca6a6
@ -148,11 +148,17 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
|
||||
// Check for wallet address in form data
|
||||
const walletAddress = formData.get('walletAddress');
|
||||
|
||||
// Log more detailed data about the wallet address
|
||||
console.log('Form data received:', {
|
||||
hasImage: !!imageFile,
|
||||
imageType: imageFile ? typeof imageFile : 'undefined',
|
||||
hasWalletAddress: !!walletAddress,
|
||||
walletAddressType: typeof walletAddress,
|
||||
walletAddress: walletAddress || 'Not provided',
|
||||
formDataKeys: Array.from(formData.keys())
|
||||
formDataKeys: Array.from(formData.keys()),
|
||||
// Log all form data for debugging
|
||||
formData: Object.fromEntries(formData.entries())
|
||||
});
|
||||
|
||||
// For server-side, check if we have a valid Blob-like object
|
||||
@ -375,10 +381,16 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
// This is separate so issues with token rewards don't affect points
|
||||
try {
|
||||
// Check if wallet address was provided in the form data
|
||||
const walletAddress = formData.get('walletAddress') as string;
|
||||
const walletAddressRaw = formData.get('walletAddress');
|
||||
// Ensure we get a string value - formData can have different types
|
||||
const walletAddress = walletAddressRaw ? String(walletAddressRaw) : null;
|
||||
|
||||
// Log the wallet address for debugging
|
||||
console.log('Wallet address for token award:', walletAddress || 'Not provided');
|
||||
console.log('Wallet address for token award:', {
|
||||
rawValue: walletAddressRaw,
|
||||
processedValue: walletAddress || 'Not provided',
|
||||
valueType: typeof walletAddressRaw
|
||||
});
|
||||
|
||||
// Import dynamically to avoid server-side issues with window object
|
||||
const { awardTokensForSighting } = await import('../../../services/blockchain/tokenRewardService');
|
||||
@ -386,37 +398,39 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
// Get species from vision result for token amount calculation
|
||||
const species = visionResult.mainObject || 'animal';
|
||||
|
||||
// Log wallet information
|
||||
console.log('Token award attempt:', {
|
||||
walletAddressProvided: !!walletAddress,
|
||||
walletAddress: walletAddress || 'Not provided',
|
||||
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);
|
||||
|
||||
// Add token reward info to response if successful
|
||||
if (tokenResult.success) {
|
||||
responseData.tokenReward = {
|
||||
amount: tokenResult.tokenAmount,
|
||||
txHash: tokenResult.txHash
|
||||
};
|
||||
|
||||
console.log('Token reward successful:', tokenResult);
|
||||
} else if (tokenResult.walletConnected) {
|
||||
// Wallet was connected but award failed
|
||||
console.error('Token reward failed:', tokenResult.error);
|
||||
// Skip token award if no wallet address is provided
|
||||
if (!walletAddress) {
|
||||
console.log('No wallet address provided, skipping token award');
|
||||
// Continue with other operations without token reward
|
||||
} else {
|
||||
// No wallet connected - this is not an error, just informational
|
||||
console.log('No wallet connected, skipping token reward');
|
||||
// Log wallet information
|
||||
console.log('Token award attempt:', {
|
||||
walletAddressProvided: true,
|
||||
walletAddress: walletAddress,
|
||||
species
|
||||
});
|
||||
|
||||
// Log detailed information for debugging
|
||||
console.log('Starting token award with explicit address:', walletAddress);
|
||||
|
||||
// Attempt to award tokens for this wildlife sighting
|
||||
const tokenResult = await awardTokensForSighting(species, undefined, walletAddress);
|
||||
|
||||
// Add token reward info to response if successful
|
||||
if (tokenResult.success) {
|
||||
responseData.tokenReward = {
|
||||
amount: tokenResult.tokenAmount,
|
||||
txHash: tokenResult.txHash
|
||||
};
|
||||
|
||||
console.log('Token reward successful:', tokenResult);
|
||||
} else if (tokenResult.walletConnected) {
|
||||
// Wallet was connected but award failed
|
||||
console.error('Token reward failed:', tokenResult.error);
|
||||
} else {
|
||||
// No wallet connected - this is not an error, just informational
|
||||
console.log('No wallet connected, skipping token reward');
|
||||
}
|
||||
}
|
||||
} catch (tokenError) {
|
||||
console.error('Error processing token reward:', tokenError);
|
||||
|
||||
@ -57,10 +57,34 @@ export const awardTokensForSighting = async (
|
||||
// Determine wallet address - either from parameter or connected wallet
|
||||
let walletAddress = explicitWalletAddress;
|
||||
|
||||
// If no explicit address was provided, check if wallet is connected
|
||||
if (!walletAddress) {
|
||||
// If explicit address was provided, use it directly (server-side case)
|
||||
if (walletAddress) {
|
||||
console.log('Using explicitly provided wallet address:', walletAddress);
|
||||
} else {
|
||||
// Client-side case - check if wallet is connected
|
||||
console.log('No explicit wallet address provided, checking wallet connection state...');
|
||||
if (!isWalletConnected()) {
|
||||
|
||||
// Try to get from memory first
|
||||
if (isWalletConnected()) {
|
||||
walletAddress = getWalletAddress();
|
||||
console.log('Found connected wallet in memory:', walletAddress);
|
||||
}
|
||||
|
||||
// Try localStorage as a fallback (client-side only)
|
||||
if (!walletAddress && typeof window !== 'undefined') {
|
||||
try {
|
||||
const storedAddress = localStorage.getItem('wildlife_wallet_address');
|
||||
if (storedAddress) {
|
||||
console.log('Using wallet address from localStorage:', storedAddress);
|
||||
walletAddress = storedAddress;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Error accessing localStorage:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// If we still don't have an address, return no wallet connected
|
||||
if (!walletAddress) {
|
||||
console.log('No wallet connected, skipping token award.');
|
||||
return {
|
||||
success: false,
|
||||
@ -68,7 +92,6 @@ export const awardTokensForSighting = async (
|
||||
walletConnected: false
|
||||
};
|
||||
}
|
||||
walletAddress = getWalletAddress();
|
||||
}
|
||||
|
||||
// Validate we have a wallet address by this point
|
||||
|
||||
Loading…
Reference in New Issue
Block a user