Cache last known BTC price and show stale warning in UI

When the CoinGecko API fails, fall back to the last successful price
instead of 0.0, and surface a warning indicator on the price card.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-06 20:01:30 +02:00
parent 5bb67d6663
commit a2ca82062e
3 changed files with 27 additions and 7 deletions
+15 -3
View File
@@ -28,11 +28,19 @@ const styles = {
tabActive: { padding: '0.45rem 1.1rem', borderRadius: '8px', border: '1px solid #f7931a', background: 'rgba(247,147,26,0.1)', color: '#f7931a', cursor: 'pointer', fontSize: '0.9rem', fontWeight: 700 },
};
function StatCard({ label, value, highlight }) {
function StatCard({ label, value, highlight, warning }) {
return (
<div style={styles.statCard}>
<div style={styles.statLabel}>{label}</div>
<div style={{ ...styles.statLabel, display: 'flex', alignItems: 'center', gap: '0.3rem' }}>
{label}
{warning && (
<span title={warning} style={{ color: '#f7931a', cursor: 'default', fontSize: '0.85rem' }}></span>
)}
</div>
<div style={{ ...styles.statValue, ...(highlight ? styles[highlight] : {}) }}>{value}</div>
{warning && (
<div style={{ color: '#888', fontSize: '0.7rem', marginTop: '0.25rem' }}>{warning}</div>
)}
</div>
);
}
@@ -121,7 +129,11 @@ export default function Dashboard() {
<StatCard label="Total Invested" value={`${stats.total_invested.toLocaleString()}`} />
<StatCard label="Avg Buy Price" value={`${stats.average_price.toLocaleString()}`} />
<StatCard label="Total BTC" value={`${stats.total_btc}`} highlight="neutral" />
<StatCard label="Current BTC Price" value={`${stats.current_price.toLocaleString()}`} />
<StatCard
label="Current BTC Price"
value={`${stats.current_price.toLocaleString()}`}
warning={stats.price_is_cached ? 'Price may be outdated — live fetch failed' : undefined}
/>
<StatCard label="Portfolio Value" value={`${stats.portfolio_value.toLocaleString()}`} />
<StatCard
label="Profit / Loss"