@@ -18,12 +18,63 @@ import {
1818 usePriceComparison ,
1919} from "../hooks/usePriceComparison" ;
2020import { SkeletonChart } from "./Skeleton" ;
21+ import type { PriceTimeframe } from "../types" ;
22+
23+ // --- local helpers ---
24+
25+ const ALL_SOURCES : PriceSourceId [ ] = [ "stellar_dex" , "circle" , "coinbase" , "stellar_amm" ] ;
26+
27+ function msForRange ( rangeId : string , customStartIso : string , customEndIso : string ) : number {
28+ if ( rangeId === "custom" && customStartIso && customEndIso ) {
29+ return Math . max ( 0 , Date . parse ( customEndIso ) - Date . parse ( customStartIso ) ) ;
30+ }
31+ const RANGE_MS : Record < string , number > = {
32+ "1h" : 60 * 60 * 1_000 ,
33+ "24h" : 24 * 60 * 60 * 1_000 ,
34+ "7d" : 7 * 24 * 60 * 60 * 1_000 ,
35+ "30d" : 30 * 24 * 60 * 60 * 1_000 ,
36+ } ;
37+ return RANGE_MS [ rangeId ] ?? RANGE_MS [ "24h" ] ;
38+ }
39+
40+ function stellarVarRgb ( varName : string , fallbackRgb : string ) : string {
41+ if ( typeof document === "undefined" ) return fallbackRgb ;
42+ const val = getComputedStyle ( document . documentElement ) . getPropertyValue ( varName ) . trim ( ) ;
43+ return val || fallbackRgb ;
44+ }
45+
46+ function formatPrice ( value : number | null | undefined ) : string {
47+ if ( value == null || ! Number . isFinite ( value ) ) return "—" ;
48+ return `$${ value . toFixed ( 4 ) } ` ;
49+ }
50+
51+ function formatPct ( value : number | null | undefined ) : string {
52+ if ( value == null || ! Number . isFinite ( value ) ) return "—" ;
53+ return `${ ( value * 100 ) . toFixed ( 2 ) } %` ;
54+ }
55+
56+ function tooltipLabelFromIso ( iso : string | undefined ) : string {
57+ if ( ! iso ) return "" ;
58+ const d = new Date ( iso ) ;
59+ return isNaN ( d . getTime ( ) ) ? iso : d . toLocaleString ( ) ;
60+ }
61+
62+ // --- end helpers ---
2163
2264interface PriceChartProps {
2365 symbol : string ;
2466}
2567
68+ interface PriceDataPoint {
69+ source : string ;
70+ price : number ;
71+ timestamp : string ;
72+ }
73+
2674interface EnhancedPriceChartProps extends PriceChartProps {
75+ data : PriceDataPoint [ ] ;
76+ isLoading : boolean ;
77+ sources ?: PriceDataPoint [ ] ;
2778 timeframe : PriceTimeframe ;
2879 onTimeframeChange : ( tf : PriceTimeframe ) => void ;
2980}
@@ -60,11 +111,13 @@ function getTimeframeTickFormatter(timeframe: PriceTimeframe) {
60111 month : "short" ,
61112 day : "numeric" ,
62113 } ) ;
114+ default :
115+ return val ;
63116 }
64117 } ;
65118}
66119
67- export default function PriceChart ( { symbol, data , isLoading } : PriceChartProps ) {
120+ export default function PriceChart ( { symbol } : PriceChartProps ) {
68121 const titleId = `price-chart-title-${ symbol } ` ;
69122 const descId = `price-chart-desc-${ symbol } ` ;
70123 const containerRef = useRef < HTMLDivElement | null > ( null ) ;
0 commit comments