fix: Prevent TypeError on blockchain page from undefined blocks array
Fix remaining undefined array access error on blockchain visualization page. When blockchainData exists but blocks is undefined, accessing .length would crash: - "can't access property 'length', e is undefined" CHANGES: 1. Blockchain page (blockchain/page.tsx): - Ensure blocks array always exists when API data is fetched - Provide fallback to empty array with verification object - Add null check before accessing blocks.length in conditional render This is the final fix for all frontend undefined array access issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0dd0f100f5
commit
476355ad6d
@ -95,7 +95,16 @@ export default function BlockchainPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
setBlockchainData(data)
|
// Ensure blocks array exists
|
||||||
|
const blockchainData = {
|
||||||
|
blocks: data.blocks || [],
|
||||||
|
verification: data.verification || {
|
||||||
|
chain_valid: true,
|
||||||
|
total_blocks: 0,
|
||||||
|
total_votes: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setBlockchainData(blockchainData)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : "Erreur inconnue"
|
const errorMessage = err instanceof Error ? err.message : "Erreur inconnue"
|
||||||
setError(errorMessage)
|
setError(errorMessage)
|
||||||
@ -267,7 +276,7 @@ export default function BlockchainPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Empty State */}
|
{/* Empty State */}
|
||||||
{blockchainData && blockchainData.blocks.length === 0 && (
|
{blockchainData && blockchainData.blocks && blockchainData.blocks.length === 0 && (
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent className="pt-6 text-center py-12">
|
<CardContent className="pt-6 text-center py-12">
|
||||||
<div className="text-5xl mb-4">⛓️</div>
|
<div className="text-5xl mb-4">⛓️</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user