diff --git a/src/app/wallet/page.tsx b/src/app/wallet/page.tsx index fc095d1..803de4b 100644 --- a/src/app/wallet/page.tsx +++ b/src/app/wallet/page.tsx @@ -303,7 +303,10 @@ export default function WalletPage() {

- {contribution.mainObject || 'Wildlife'} + {/* Ensure consistent capitalization */} + {(contribution.mainObject || 'Wildlife').split(' ').map( + word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() + ).join(' ')}

{contribution.description || 'No description available'} diff --git a/src/services/laconicService.ts b/src/services/laconicService.ts index a5d95ff..6559faa 100644 --- a/src/services/laconicService.ts +++ b/src/services/laconicService.ts @@ -203,18 +203,32 @@ export async function getAnimalRecordsBySeiAddress(seiAddress: string): Promise< }; }); - // Filter valid records and remove duplicates by using the record ID + // Let's analyze the records to understand potential duplicates + const validRecords = mappedRecords.filter((record: AnimalRecordResult) => + record.imageUrl && record.imageUrl.trim() !== '' + ); + + console.log('Records before deduplication:', validRecords.length); + + // Create more detailed keys to identify truly duplicate records const uniqueRecordMap = new Map(); - mappedRecords - .filter((record: AnimalRecordResult) => record.imageUrl && record.imageUrl.trim() !== '') - .forEach((record: AnimalRecordResult) => { - // Only add if this ID isn't already in our map - if (!uniqueRecordMap.has(record.id)) { - uniqueRecordMap.set(record.id, record); - } - }); + validRecords.forEach((record: AnimalRecordResult) => { + // Create a composite key using multiple fields to better identify duplicates + // This handles cases where IDs might be different but content is identical + const compositeKey = `${record.mainObject.toLowerCase()}-${record.description.toLowerCase()}-${record.imageUrl}`; + console.log(`Record: ${record.id}, Key: ${compositeKey.substring(0, 30)}...`); + + // Only add if this composite key isn't already in our map + if (!uniqueRecordMap.has(compositeKey)) { + uniqueRecordMap.set(compositeKey, record); + } else { + console.log(`Skipping duplicate record with ID ${record.id} (matches ${uniqueRecordMap.get(compositeKey).id})`); + } + }); + + console.log('Records after deduplication:', uniqueRecordMap.size); const records = Array.from(uniqueRecordMap.values()); // Sort by timestamp descending (newest first) @@ -320,18 +334,30 @@ export async function getAllAnimalRecords(): Promise { }; }); - // Filter valid records and remove duplicates by using the record ID + // Let's analyze the records to understand potential duplicates + const validRecords = mappedRecords.filter((record: AnimalRecordResult) => + record.imageUrl && record.imageUrl.trim() !== '' + ); + + console.log('All records before deduplication:', validRecords.length); + + // Create more detailed keys to identify truly duplicate records const uniqueRecordMap = new Map(); - mappedRecords - .filter((record: AnimalRecordResult) => record.imageUrl && record.imageUrl.trim() !== '') - .forEach((record: AnimalRecordResult) => { - // Only add if this ID isn't already in our map - if (!uniqueRecordMap.has(record.id)) { - uniqueRecordMap.set(record.id, record); - } - }); + validRecords.forEach((record: AnimalRecordResult) => { + // Create a composite key using multiple fields to better identify duplicates + // This handles cases where IDs might be different but content is identical + const compositeKey = `${record.mainObject.toLowerCase()}-${record.description.toLowerCase()}-${record.imageUrl}`; + // Only add if this composite key isn't already in our map + if (!uniqueRecordMap.has(compositeKey)) { + uniqueRecordMap.set(compositeKey, record); + } else { + console.log(`Skipping duplicate record with ID ${record.id}`); + } + }); + + console.log('All records after deduplication:', uniqueRecordMap.size); const records = Array.from(uniqueRecordMap.values()); // Sort by timestamp descending (newest first)