diff --git a/frontend/src/components/PlatformStats.jsx b/frontend/src/components/PlatformStats.jsx index ff10ca52..0723fde4 100644 --- a/frontend/src/components/PlatformStats.jsx +++ b/frontend/src/components/PlatformStats.jsx @@ -29,7 +29,12 @@ export default function PlatformStats() { setLastRefresh(new Date()); } catch (error) { console.error('Failed to fetch platform stats:', error.message || error); - setError('Unable to load platform statistics. Please try again later.'); + const isNetworkError = error.message?.includes('fetch') || error.message?.includes('network') || error.name === 'TypeError'; + setError( + isNetworkError + ? 'Unable to reach the Stacks API. Check your connection and try again.' + : `Failed to load platform statistics: ${error.message || 'Unknown error'}` + ); setLoading(false); } }, []); diff --git a/frontend/src/components/RecentTips.jsx b/frontend/src/components/RecentTips.jsx index b3efbb77..d201ac5b 100644 --- a/frontend/src/components/RecentTips.jsx +++ b/frontend/src/components/RecentTips.jsx @@ -55,7 +55,12 @@ export default function RecentTips({ addToast }) { setLastRefresh(new Date()); } catch (err) { console.error('Failed to fetch recent tips:', err.message || err); - setError(err.message || 'Failed to load tips'); + const isNetworkError = err.message?.includes('fetch') || err.message?.includes('network') || err.name === 'TypeError'; + setError( + isNetworkError + ? 'Unable to reach the Stacks API. Check your connection and try again.' + : `Failed to load tips: ${err.message || 'Unknown error'}` + ); setLoading(false); } }, []); diff --git a/frontend/src/components/TipHistory.jsx b/frontend/src/components/TipHistory.jsx index f42b2a71..4a60cbbe 100644 --- a/frontend/src/components/TipHistory.jsx +++ b/frontend/src/components/TipHistory.jsx @@ -14,12 +14,14 @@ export default function TipHistory({ userAddress }) { const [stats, setStats] = useState(null); const [tips, setTips] = useState([]); const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); const [tab, setTab] = useState('all'); const [lastRefresh, setLastRefresh] = useState(null); const fetchData = useCallback(async () => { if (!userAddress) return; try { + setError(null); const [statsResult, tipsResult] = await Promise.all([ fetchCallReadOnlyFunction({ network, @@ -31,7 +33,10 @@ export default function TipHistory({ userAddress }) { }), fetch( `${API_BASE}/extended/v1/contract/${CONTRACT_ADDRESS}.${CONTRACT_NAME}/events?limit=50&offset=0` - ).then(r => r.json()) + ).then(r => { + if (!r.ok) throw new Error(`API returned ${r.status}`); + return r.json(); + }) ]); const jsonResult = cvToJSON(statsResult); @@ -50,8 +55,14 @@ export default function TipHistory({ userAddress }) { setTips(userTips); setLoading(false); setLastRefresh(new Date()); - } catch (error) { - console.error('Failed to fetch tip history:', error.message || error); + } catch (err) { + console.error('Failed to fetch tip history:', err.message || err); + const isNetworkError = err.message?.includes('fetch') || err.message?.includes('network') || err.name === 'TypeError'; + setError( + isNetworkError + ? 'Unable to reach the Stacks API. Check your connection and try again.' + : `Failed to load activity: ${err.message || 'Unknown error'}` + ); setLoading(false); } }, [userAddress]); @@ -106,6 +117,20 @@ export default function TipHistory({ userAddress }) { ); } + if (error) { + return ( +
{error}
+ +