11import { useAlert } from "@pythnetwork/component-library/useAlert" ;
22import type { Nullish } from "@pythnetwork/shared-lib/types" ;
33import { wait } from "@pythnetwork/shared-lib/util" ;
4- import qs from "query-string" ;
54import { useEffect , useRef , useState } from "react" ;
65
76import type {
@@ -46,15 +45,14 @@ function getFetchHistoricalUrl(
4645 return "" ;
4746 }
4847
49- const query = qs . stringify (
50- {
51- datasources,
52- startAt : startAtValidation . data . toISOString ( ) ,
53- } ,
54- { arrayFormat : "bracket" } ,
55- ) ;
48+ const queryParams = new URLSearchParams ( ) ;
49+ queryParams . set ( "startAt" , startAtValidation . data . toISOString ( ) ) ;
50+
51+ for ( const datasource of datasources ) {
52+ queryParams . append ( "datasources[]" , datasource ) ;
53+ }
5654
57- return `/api/pyth/get-pyth-feeds-demo-data/${ removeReplaySymbolSuffix ( symbol ) } ?${ query } ` ;
55+ return `/api/pyth/get-pyth-feeds-demo-data/${ removeReplaySymbolSuffix ( symbol ) } ?${ queryParams . toString ( ) } ` ;
5856}
5957
6058export async function fetchHistoricalData (
@@ -124,10 +122,16 @@ export function useHttpDataStream({
124122 } ) ;
125123
126124 useEffect ( ( ) => {
127- if ( ! enabled || ! isReplaySymbol ( symbol ) ) return ;
125+ if ( ! enabled || ! isReplaySymbol ( symbol ) ) {
126+ setStatus ( "closed" ) ;
127+ return ;
128+ }
128129
129130 const url = getFetchHistoricalUrl ( dataSources , symbol , startAtToFetch ) ;
130- if ( ! url ) return ;
131+ if ( ! url ) {
132+ setStatus ( "closed" ) ;
133+ return ;
134+ }
131135
132136 setStatus ( "connected" ) ;
133137
@@ -138,7 +142,7 @@ export function useHttpDataStream({
138142 // this may mean that one data source runs further ahead than another for a bit,
139143 // if there is no data for a certain time interval
140144
141- for ( let i = 0 ; i < data . length - 1 ; i ++ ) {
145+ for ( let i = 0 ; i < data . length ; i ++ ) {
142146 const currPoint = data [ i ] ;
143147 const nextPoint = data [ i + 1 ] ;
144148
0 commit comments