Skip to content

feat: add loading state to useOHLCVRealtime hook - #38863

Merged
GeorgeGkas merged 5 commits into
mainfrom
add-ohlcv-state
Nov 4, 2026
Merged

GeorgeGkas merged 5 commits into
mainfrom
add-ohlcv-state

Conversation

@GeorgeGkas

@GeorgeGkas GeorgeGkas commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Downstream bridge/limit-order flows need to distinguish “still waiting for the first OHLCV price lookup” from “lookup finished with no bar.” useOHLCVRealtime previously exposed only latestBar, so both cases looked like null.

This PR adds an isLoading flag on the hook result. It is true for the current channel until the first bar arrives (WebSocket or settled /latest poll) or the first non-aborted poll completes without data. It resets when the asset/channel changes, stays false when the hook is disabled or misconfigured, and settles when subscribe fails without a follow-up poll. Unit tests cover the loading lifecycle. No UI callers consume isLoading yet (follow-up for SWAPS-5274).

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/SWAPS-5274

Manual testing steps

N/A — hook-only change with unit test coverage; no product surface uses isLoading in this PR.

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Additive hook API with unit tests only; no UI or bridge behavior changes until a follow-up wires in isLoading.

Overview
useOHLCVRealtime now returns isLoading, so callers can tell “still waiting for the first price for this asset/channel” apart from “lookup finished with no bar” (both were latestBar: null before).

Loading stays true until the first bar arrives over the WebSocket or the first non-aborted /latest poll completes (with or without data). It goes true again when the asset/channel changes, stays false when the hook is disabled or misconfigured, and settles when subscribe fails with no follow-up poll. Implementation tracks a settledChannel alongside existing latestBar logic.

Unit tests cover the full isLoading lifecycle; Bridge useLiveTokenFiatRate tests only update mocks to include the new field—no product code reads isLoading yet (planned follow-up for SWAPS-5274).

Reviewed by Cursor Bugbot for commit 5b5a18e. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@github-actions github-actions Bot added size-M pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels Nov 4, 2026
@metamask-ci metamask-ci Bot added the team-swaps-and-bridge Swaps and Bridge team label Nov 4, 2026
@GeorgeGkas GeorgeGkas removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Nov 4, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0562975. Configure here.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Smart E2E Test Selection

Selected E2E tags: No E2E tests selected

AI Confidence: 95

E2E reasoning

Expand to read

All three changed files are unit-test level changes with no E2E smoke test impact:

  1. useOHLCVRealtime.ts — Additive change: adds a new isLoading: boolean field to the hook's return value. The existing latestBar behavior is unchanged. The hook is consumed by usePriceChartState (AssetOverview) and useLiveTokenFiatRate (Bridge), but the new field is purely additive and does not alter any existing behavior or UI flows that E2E smoke tests exercise.

  2. useOHLCVRealtime.test.ts — Pure unit test additions (131 new lines, 0 deletions) covering the new isLoading state transitions. No E2E smoke spec files are modified.

  3. useLiveTokenFiatRate/index.test.ts — Minor test helper update: mockLatestBar now passes isLoading in the mock return value to align with the updated interface. This is a test-only change with no functional impact.

No E2E smoke spec files, page objects, selectors, flows, or shared test infrastructure are modified. The changes are confined to a React hook implementation and its unit tests. The isLoading addition is backward-compatible (consumers that don't use the new field are unaffected). No critical paths (authentication, navigation, state management, transactions) are touched. Running zero E2E smoke tags is appropriate.

View run

bfullam
bfullam previously approved these changes Nov 4, 2026
@GeorgeGkas
GeorgeGkas enabled auto-merge November 4, 2026 17:55
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@GeorgeGkas
GeorgeGkas added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit a3bdbb6 Nov 4, 2026
163 of 167 checks passed
@GeorgeGkas
GeorgeGkas deleted the add-ohlcv-state branch November 4, 2026 20:40
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2026
@metamask-ci metamask-ci Bot added the release-8.20.0 Issue or pull request that will be included in release 8.20.0 label Nov 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.20.0 Issue or pull request that will be included in release 8.20.0 size-M team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants