Skip to content

Refactor balance history graph to use dynamic width and daily granularity#14106

Merged
dylanjeffers merged 5 commits intomainfrom
claude/improve-balance-update-Wh8MJ
Apr 16, 2026
Merged

Refactor balance history graph to use dynamic width and daily granularity#14106
dylanjeffers merged 5 commits intomainfrom
claude/improve-balance-update-Wh8MJ

Conversation

@dylanjeffers
Copy link
Copy Markdown
Contributor

Summary

This PR refactors the UserBalanceHistoryGraph component to dynamically measure container width instead of accepting a fixed width prop, and updates balance history queries to use daily granularity across both mobile and web platforms.

Key Changes

  • Dynamic Width Measurement: Replaced the static width prop with runtime layout measurement using onLayout callback on mobile, allowing the graph to responsively adapt to its container
  • Layout State Management: Added containerWidth state and handleLayout callback to capture actual rendered dimensions before chart rendering
  • Granularity Update: Added granularity: 'daily' parameter to all useUserBalanceHistory hook calls in both mobile and web implementations
  • Tooltip Date Formatting: Simplified formatTooltipDate function to display date only (weekday short, month short, day) instead of including time information
  • Prop Removal: Removed width prop from UserBalanceHistoryGraph and AccountBalance components, simplifying the component API
  • Render Guard: Added early return to render empty Flex container while waiting for layout measurement to complete

Implementation Details

  • Mobile implementation uses React Native's LayoutChangeEvent to measure container width dynamically
  • The chart only renders once containerWidth > 0, preventing layout thrashing
  • Web implementation maintains existing behavior while adopting the daily granularity parameter
  • All balance history queries now consistently use daily data granularity for improved performance and consistency

https://claude.ai/code/session_01EP1m3UXR2bibGyXKUUUZqY

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

⚠️ No Changeset found

Latest commit: 84a2583

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

🌐 Web preview ready

Preview URL: https://audius-web-preview-pr-14106.audius.workers.dev

Unique preview for this PR (deployed from this branch).
Workflow run

claude and others added 5 commits April 16, 2026 11:55
- Change all useUserBalanceHistory calls to use daily granularity instead
  of hourly for a cleaner, less noisy chart
- Update tooltip date format to show "Mon, Apr 7" instead of
  "Monday 3pm" since hourly timestamps no longer apply
- Make mobile chart responsive by measuring container width via onLayout
  instead of using a hardcoded 350px default

https://claude.ai/code/session_01EP1m3UXR2bibGyXKUUUZqY
Daily-granularity queries were returning data far outside the expected
7-day range (causing the chart and "7D Change" calculation to show wildly
incorrect values — e.g. a 50% drop when the real 7-day change was ~0%).
Explicitly default startTime to midnight UTC 7 days ago instead of
relying on the API's own default.

The default is day-rounded so the query key stays stable within a day,
allowing react-query to share the cache between AccountBalance and
UserBalanceHistoryGraph.

https://claude.ai/code/session_01EP1m3UXR2bibGyXKUUUZqY
The backend's granularity=daily option currently sums the 24 hourly
snapshots for each day (returning ~24x the actual balance) instead of
returning the closing balance. Rather than block on the backend fix,
fetch hourly data and bucket it to one end-of-day point per UTC day in
the hook's queryFn. This gives the graph the desired "daily, week-long"
shape with correct balance values.

When the API is fixed, we can drop the downsampling and switch back to
passing granularity='daily'.

https://claude.ai/code/session_01EP1m3UXR2bibGyXKUUUZqY
The backend now returns correct closing balances for granularity='daily',
so we can pass the parameter directly and stop fetching hourly data just
to bucket it ourselves. Restores useUserBalanceHistory to its original
shape and re-points the four call sites at daily granularity.

The tooltip format and responsive mobile chart width from the earlier
commits stay in place.

https://claude.ai/code/session_01EP1m3UXR2bibGyXKUUUZqY
@dylanjeffers dylanjeffers force-pushed the claude/improve-balance-update-Wh8MJ branch from 85e313d to 84a2583 Compare April 16, 2026 18:57
@dylanjeffers dylanjeffers merged commit f5844db into main Apr 16, 2026
8 checks passed
@dylanjeffers dylanjeffers deleted the claude/improve-balance-update-Wh8MJ branch April 16, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants