Skip to content

Commit 01b376c

Browse files
Merge pull request #94 from StabilityNexus/Frontend
FIx of myCats not showing.
2 parents 2e811c7 + 9f6a683 commit 01b376c

File tree

1 file changed

+63
-16
lines changed

1 file changed

+63
-16
lines changed

web/src/app/my-cats/page.tsx

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ export default function MyCATsPage() {
187187
for (const [chainId, factoryAddress] of Object.entries(ClowderVaultFactories)) {
188188
if (!isValidChainId(chainId)) continue;
189189

190-
const publicClient = getPublicClient(config, { chainId });
190+
const numericChainId = Number(chainId) as SupportedChainId;
191+
const publicClient = getPublicClient(config, { chainId: numericChainId });
191192
if (!publicClient) continue;
192193

193194
try {
195+
console.log(`Checking chain ${numericChainId} (${CHAIN_NAMES[numericChainId]}) for CATs...`);
196+
194197
// Get creator CATs
195198
const creatorCount = await publicClient.readContract({
196199
address: factoryAddress as `0x${string}`,
@@ -199,6 +202,8 @@ export default function MyCATsPage() {
199202
args: [address as `0x${string}`],
200203
}) as bigint;
201204

205+
console.log(`Chain ${numericChainId}: Found ${Number(creatorCount)} creator CATs`);
206+
202207
if (Number(creatorCount) > 0) {
203208
const creatorAddresses = await publicClient.readContract({
204209
address: factoryAddress as `0x${string}`,
@@ -207,7 +212,8 @@ export default function MyCATsPage() {
207212
args: [address as `0x${string}`, BigInt(0), creatorCount],
208213
}) as `0x${string}`[];
209214

210-
const creatorCATs = await fetchCATDetails(creatorAddresses, Number(chainId) as SupportedChainId, 'admin');
215+
console.log(`Chain ${numericChainId}: Creator CAT addresses:`, creatorAddresses);
216+
const creatorCATs = await fetchCATDetails(creatorAddresses, numericChainId, 'admin');
211217
allCATs.push(...creatorCATs);
212218
}
213219

@@ -219,6 +225,8 @@ export default function MyCATsPage() {
219225
args: [address as `0x${string}`],
220226
}) as bigint;
221227

228+
console.log(`Chain ${numericChainId}: Found ${Number(minterCount)} minter CATs`);
229+
222230
if (Number(minterCount) > 0) {
223231
const minterAddresses = await publicClient.readContract({
224232
address: factoryAddress as `0x${string}`,
@@ -227,7 +235,8 @@ export default function MyCATsPage() {
227235
args: [address as `0x${string}`, BigInt(0), minterCount],
228236
}) as `0x${string}`[];
229237

230-
const minterCATs = await fetchCATDetails(minterAddresses, Number(chainId) as SupportedChainId, 'minter');
238+
console.log(`Chain ${numericChainId}: Minter CAT addresses:`, minterAddresses);
239+
const minterCATs = await fetchCATDetails(minterAddresses, numericChainId, 'minter');
231240
allCATs.push(...minterCATs);
232241
}
233242
} catch (error) {
@@ -239,6 +248,7 @@ export default function MyCATsPage() {
239248
console.error('Error fetching all CATs from blockchain:', error);
240249
}
241250

251+
console.log(`Total CATs found across all chains: ${allCATs.length}`, allCATs);
242252
return allCATs;
243253
}, [address]);
244254

@@ -538,6 +548,20 @@ export default function MyCATsPage() {
538548

539549
for (let attempt = 0; attempt < maxRetries; attempt++) {
540550
try {
551+
console.log(`Attempting to fetch details for CAT ${catAddress} on chain ${chainId} (attempt ${attempt + 1})`);
552+
553+
// First, check if the address is a contract by trying to get bytecode
554+
try {
555+
const bytecode = await publicClient.getBytecode({ address: catAddress });
556+
if (!bytecode || bytecode === '0x') {
557+
console.warn(`Address ${catAddress} is not a contract or has no bytecode`);
558+
return null; // Skip this address
559+
}
560+
} catch (bytecodeError) {
561+
console.warn(`Could not verify bytecode for ${catAddress}:`, bytecodeError);
562+
// Continue anyway, as some RPCs might not support getBytecode
563+
}
564+
541565
const [tokenName, tokenSymbol] = await Promise.all([
542566
publicClient.readContract({
543567
address: catAddress,
@@ -551,11 +575,19 @@ export default function MyCATsPage() {
551575
}) as Promise<string>,
552576
]);
553577

578+
// Validate that we got meaningful data
579+
if (!tokenName && !tokenSymbol) {
580+
console.warn(`Contract ${catAddress} returned empty name and symbol`);
581+
return null;
582+
}
583+
584+
console.log(`Successfully fetched CAT details: ${tokenName} (${tokenSymbol}) at ${catAddress}`);
585+
554586
return {
555587
chainId,
556588
address: catAddress,
557-
tokenName: tokenName || "",
558-
tokenSymbol: tokenSymbol || "",
589+
tokenName: tokenName || `CAT ${catAddress.slice(0, 6)}...${catAddress.slice(-4)}`,
590+
tokenSymbol: tokenSymbol || "CAT",
559591
userRole: defaultRole,
560592
};
561593
} catch (error: unknown) {
@@ -564,25 +596,40 @@ export default function MyCATsPage() {
564596
errorObj?.status === 429 ||
565597
errorObj?.code === -32016;
566598

599+
const isContractError = errorObj?.message?.includes('returned no data') ||
600+
errorObj?.message?.includes('does not have the function') ||
601+
errorObj?.message?.includes('address is not a contract');
602+
603+
console.warn(`Error fetching CAT ${catAddress} (attempt ${attempt + 1}):`, error);
604+
605+
if (isContractError) {
606+
// This is likely an invalid contract, skip it
607+
console.warn(`Skipping invalid contract ${catAddress}`);
608+
return null;
609+
}
610+
567611
if (attempt === maxRetries - 1) {
568-
// Final attempt failed - return fallback
569-
console.error(`Failed to fetch CAT ${catAddress} after ${maxRetries} attempts:`, error);
570-
return {
571-
chainId,
572-
address: catAddress,
573-
tokenName: `CAT ${catAddress.slice(0, 6)}...${catAddress.slice(-4)}`,
574-
tokenSymbol: "CAT",
575-
userRole: defaultRole,
576-
};
612+
// Final attempt failed - return fallback only for non-contract errors
613+
if (!isContractError) {
614+
console.error(`Failed to fetch CAT ${catAddress} after ${maxRetries} attempts, using fallback:`, error);
615+
return {
616+
chainId,
617+
address: catAddress,
618+
tokenName: `CAT ${catAddress.slice(0, 6)}...${catAddress.slice(-4)}`,
619+
tokenSymbol: "CAT",
620+
userRole: defaultRole,
621+
};
622+
}
623+
return null;
577624
}
578625

579626
if (isRateLimit) {
580627
// Rate limit hit - wait before retry
581628
const delayMs = 1000 * Math.pow(2, attempt); // 1s, 2s, 4s
582629
console.log(`Rate limit hit for ${catAddress}, retrying in ${delayMs}ms... (attempt ${attempt + 1})`);
583630
await delay(delayMs);
584-
} else {
585-
// Non-rate-limit error - don't retry
631+
} else if (!isContractError) {
632+
// Non-rate-limit, non-contract error - don't retry
586633
throw error;
587634
}
588635
}

0 commit comments

Comments
 (0)