Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/crates/atlas-server/src/api/handlers/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct DailyTxPoint {
#[derive(Serialize)]
pub struct GasPricePoint {
pub bucket: String,
pub avg_gas_price: f64,
pub avg_gas_price: Option<f64>,
}

/// GET /api/stats/blocks-chart?window=1h|6h|24h|7d
Expand Down Expand Up @@ -221,7 +221,7 @@ pub async fn get_gas_price_chart(
.into_iter()
.map(|(bucket, avg_gas_price)| GasPricePoint {
bucket: bucket.to_rfc3339(),
avg_gas_price: avg_gas_price.unwrap_or(0.0),
avg_gas_price,
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/chartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface DailyTxPoint {

export interface GasPricePoint {
bucket: string; // ISO timestamp
avg_gas_price: number; // wei
avg_gas_price: number | null; // wei
}

export function getBlocksChart(window: ChartWindow): Promise<BlockChartPoint[]> {
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/hooks/useChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ interface ChartData {
gasPriceError: string | null;
}

function fillMissingGasPriceBuckets(points: GasPricePoint[]): GasPricePoint[] {
let lastObservedPrice: number | null = null;

return points.map((point) => {
if (point.avg_gas_price !== null) {
lastObservedPrice = point.avg_gas_price;
return point;
}

return {
...point,
avg_gas_price: lastObservedPrice,
};
});
}

function getChartErrorMessage(err: unknown, fallback: string): string {
if (err && typeof err === 'object' && 'error' in err && typeof (err as { error: unknown }).error === 'string') {
return (err as { error: string }).error;
Expand Down Expand Up @@ -124,7 +140,7 @@ export function useChartData(window: ChartWindow): ChartData {
try {
setGasPriceError(null);
const gasPrice = await getGasPriceChart(window);
if (mounted) setGasPriceChart(gasPrice);
if (mounted) setGasPriceChart(fillMissingGasPriceBuckets(gasPrice));
} catch (err) {
if (mounted) {
setGasPriceError(getChartErrorMessage(err, 'Failed to load gas price chart'));
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/pages/StatusPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default function StatusPage() {
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
formatter={(v: unknown) => [formatGwei(v as number), 'Avg Gas Price']}
formatter={(v: unknown) => [formatGwei(v as number | null), 'Avg Gas Price']}
labelFormatter={(v) => formatBucketTooltip(v, window)}
/>
<Line
Expand Down Expand Up @@ -329,7 +329,11 @@ function formatCompact(n: number): string {
return String(n);
}

function formatGwei(wei: number): string {
function formatGwei(wei: number | null | undefined): string {
if (wei === null || wei === undefined || Number.isNaN(wei)) {
return '—';
}

const gwei = wei / 1e9;
if (gwei >= 1_000) return `${(gwei / 1_000).toFixed(1)}K gwei`;
if (gwei >= 1) return `${gwei.toFixed(2)} gwei`;
Expand Down
Loading