Skip to content

fix: Preserve gas price chart across empty buckets#44

Open
pthmas wants to merge 1 commit intomainfrom
pthmas/fix-zero-gas-chart
Open

fix: Preserve gas price chart across empty buckets#44
pthmas wants to merge 1 commit intomainfrom
pthmas/fix-zero-gas-chart

Conversation

@pthmas
Copy link
Copy Markdown
Collaborator

@pthmas pthmas commented Mar 31, 2026

Avoid plotting a zero gas price when a bucket has no transactions.
Carry the last observed gas price forward in the status chart instead.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed gas price chart data handling—missing values now intelligently filled with the most recent known price instead of displaying as zeros
    • Enhanced tooltips to display a dash when gas price information is unavailable

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The backend now returns null for gas price data buckets with no qualifying entries instead of defaulting to zero. Corresponding frontend type definitions were updated to accept nullable values, with new logic to fill gaps using the most recently observed price before rendering charts.

Changes

Cohort / File(s) Summary
Type Definition Updates
backend/crates/atlas-server/src/api/handlers/stats.rs, frontend/src/api/chartData.ts
Made GasPricePoint.avg_gas_price nullable (Option<f64> / number | null) to represent missing gas price data instead of defaulting to zero.
Frontend Data Processing
frontend/src/hooks/useChartData.ts
Added fillMissingGasPriceBuckets helper to forward-fill null gas prices with the most recent non-null value, applied during chart data fetching.
Tooltip Formatting
frontend/src/pages/StatusPage.tsx
Updated formatGwei to handle nullable/undefined values, returning an em dash () for missing prices instead of requiring numeric input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: status page charts #40: Directly related as the primary PR that introduced the nullable GasPricePoint.avg_gas_price changes across backend and frontend type definitions and handling.

Poem

🐰 Nulls hop through the data chain,
Where gaps once filled with zeros plain,
Now forward-filled with prices fair,
And dashes show when none are there! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: preserving gas price data across empty time buckets instead of using zero values.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pthmas/fix-zero-gas-chart

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/crates/atlas-server/src/api/handlers/stats.rs (1)

231-266: Consider adding a unit test for nullable serialization.

The existing tests cover Window enum methods but don't validate the new nullable avg_gas_price behavior. A simple serialization test would help ensure Option<f64> serializes correctly to JSON null.

📝 Example test to add
+    #[test]
+    fn gas_price_point_serializes_null() {
+        let point = GasPricePoint {
+            bucket: "2024-01-01T00:00:00Z".to_string(),
+            avg_gas_price: None,
+        };
+        let json = serde_json::to_string(&point).unwrap();
+        assert!(json.contains(r#""avg_gas_price":null"#));
+    }

As per coding guidelines: "Add unit tests for new logic in a #[cfg(test)] mod tests block in the same file".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/crates/atlas-server/src/api/handlers/stats.rs` around lines 231 -
266, Add a unit test in the existing #[cfg(test)] mod tests that verifies
nullable avg_gas_price serializes to JSON null and Some(f64) serializes to a
numeric value: create a small #[derive(Serialize, Deserialize, PartialEq,
Debug)] temp struct with an avg_gas_price: Option<f64> field inside the tests
module, use serde_json::to_string (and optionally from_str) to assert that None
-> "null" for that field in the JSON and Some(1.23) -> numeric 1.23, and place
the test alongside the existing Window tests so it runs with cargo test;
reference avg_gas_price, serde_json::to_string, and the tests module when
locating where to add it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@backend/crates/atlas-server/src/api/handlers/stats.rs`:
- Around line 231-266: Add a unit test in the existing #[cfg(test)] mod tests
that verifies nullable avg_gas_price serializes to JSON null and Some(f64)
serializes to a numeric value: create a small #[derive(Serialize, Deserialize,
PartialEq, Debug)] temp struct with an avg_gas_price: Option<f64> field inside
the tests module, use serde_json::to_string (and optionally from_str) to assert
that None -> "null" for that field in the JSON and Some(1.23) -> numeric 1.23,
and place the test alongside the existing Window tests so it runs with cargo
test; reference avg_gas_price, serde_json::to_string, and the tests module when
locating where to add it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b221d7f7-91af-4127-820a-abd7cf2f17e0

📥 Commits

Reviewing files that changed from the base of the PR and between 1f86eb2 and 6ee6edb.

📒 Files selected for processing (4)
  • backend/crates/atlas-server/src/api/handlers/stats.rs
  • frontend/src/api/chartData.ts
  • frontend/src/hooks/useChartData.ts
  • frontend/src/pages/StatusPage.tsx

@pthmas pthmas changed the title Preserve gas price chart across empty buckets fix: Preserve gas price chart across empty buckets Mar 31, 2026
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

Successfully merging this pull request may close these issues.

1 participant