Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 8 additions & 50 deletions wallet-ui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,56 +143,14 @@ async function getWalletCollectibles(walletAddress, limit = 50) {
const data = await response.json();
const collectibles = data.entries || [];

// Enrich collectibles with OpenSea image data
const enrichedCollectibles = await Promise.all(
collectibles.map(async (collectible) => {
try {
// Use the chain value directly from Sim APIs
if (collectible.chain) {
const openSeaUrl = `https://api.opensea.io/api/v2/chain/${collectible.chain}/contract/${collectible.contract_address}/nfts/${collectible.token_id}`;

const openSeaResponse = await fetch(openSeaUrl, {
headers: {
'Accept': 'application/json',
'x-api-key': process.env.OPENSEA_API_KEY
}
});

if (openSeaResponse.ok) {
const openSeaData = await openSeaResponse.json();
return {
...collectible,
image_url: openSeaData.nft?.image_url || null,
opensea_url: openSeaData.nft?.opensea_url || null,
description: openSeaData.nft?.description || null,
collection_name: openSeaData.nft?.collection || collectible.name
};
}
}

// Return original collectible if OpenSea fetch fails or no chain info
return {
...collectible,
image_url: null,
opensea_url: null,
description: null,
collection_name: collectible.name
};
} catch (error) {
console.error(`Error fetching OpenSea data for ${collectible.chain}:${collectible.contract_address}:${collectible.token_id}:`, error.message);
return {
...collectible,
image_url: null,
opensea_url: null,
description: null,
collection_name: collectible.name
};
}
})
);

// Filter out collectibles without images
return enrichedCollectibles.filter(collectible => collectible.image_url !== null);
// Use Sim APIs data directly - no need for external API calls
return collectibles.map(collectible => {
return {
...collectible,
// Use collection_name field, fallback to name if not available
collection_name: collectible.name || `Token #${collectible.token_id}`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API collection_name field overwritten by name fallback

Medium Severity

The comment on line 150 says "Use collection_name field, fallback to name if not available," but the code sets collection_name to collectible.name instead of collectible.collection_name. Although ...collectible spreads any existing collection_name from the API response, the explicit assignment on this line immediately overwrites it with collectible.name. The intended fallback chain is likely collectible.collection_name || collectible.name || ....

Fix in Cursor Fix in Web

};
}).filter(collectible => collectible.image_url); // Only show collectibles with images

} catch (error) {
console.error("Error fetching wallet collectibles:", error.message);
Expand Down
12 changes: 2 additions & 10 deletions wallet-ui/views/wallet.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@
<% if (collectibles && collectibles.length > 0) { %>
<div class="collectibles-grid">
<% collectibles.forEach(collectible => { %>
<% if (collectible.opensea_url) { %>
<a href="<%= collectible.opensea_url %>" target="_blank" class="collectible-item-link">
<% } else { %>
<div class="collectible-item-link">
<% } %>
<div class="collectible-item-link">
<div class="collectible-item">
<div class="collectible-image-container">
<% if (collectible.image_url) { %>
Expand All @@ -228,11 +224,7 @@
</div>
</div>
</div>
<% if (collectible.opensea_url) { %>
</a>
<% } else { %>
</div>
<% } %>
</div>
<% }); %>
</div>
<% } else if (walletAddress) { %>
Expand Down