Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website crashes on network fails #35

Open
Aswanth-c opened this issue Dec 5, 2024 · 0 comments
Open

Website crashes on network fails #35

Aswanth-c opened this issue Dec 5, 2024 · 0 comments

Comments

@Aswanth-c
Copy link
Contributor

Aswanth-c commented Dec 5, 2024

The website fails to load data and crashes when a network error occurs, displaying the following console error:
Cannot read properties of undefined (reading 'tx_count_rolling') screenshot attached below
CleanShot 2024-12-05 at 22 58 53@2x

This happens because getnetwork() in message-api.ts return an empty array on errors

`export async function getNetworkStats(): Promise<NetworkStat[]> {
try {
const result = await goldsky.query(networkStatsQuery, {}).toPromise()
if (!result.data) return []

const { edges } = result.data.transactions
const updateId = edges[0]?.node.id

const data = await fetch(`https://arweave.net/${updateId}`)
const json = await data.json()

return json as NetworkStat[]

} catch (error) {
console.error(error)
return []
}`

and in homepage
const totalMessages = useMemo( () => (stats ? stats[stats.length - 1].tx_count_rolling : 0), [stats], )

The stats ? check only verifies if stats is not null or undefined, but it doesn’t ensure the array has elements.

Create a pull request for this issue
#36

@Aswanth-c Aswanth-c changed the title Fix: Handle Empty Stats Array to Prevent Crash Handle Empty Stats Array to Prevent Crash Dec 5, 2024
@Aswanth-c Aswanth-c changed the title Handle Empty Stats Array to Prevent Crash Website crashes on network fails Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant