@@ -5,13 +5,14 @@ import type { PriceData, PriceComponent } from "@pythnetwork/client";
55import { Skeleton } from "@pythnetwork/component-library/Skeleton" ;
66import type { ReactNode } from "react" ;
77import { useMemo } from "react" ;
8- import { useNumberFormatter , useDateFormatter } from "react-aria" ;
8+ import { useDateFormatter } from "react-aria" ;
99
1010import styles from "./index.module.scss" ;
1111import {
1212 useLivePriceComponent ,
1313 useLivePriceData ,
1414} from "../../hooks/use-live-price-data" ;
15+ import { usePriceFormatter } from "../../hooks/use-price-formatter" ;
1516import type { Cluster } from "../../services/pyth" ;
1617
1718export const SKELETON_WIDTH = 20 ;
@@ -66,20 +67,17 @@ const Price = ({
6667} : {
6768 prev ?: number | undefined ;
6869 current ?: number | undefined ;
69- } ) => {
70- const numberFormatter = useNumberFormatter ( { maximumFractionDigits : 5 } ) ;
71-
72- return current === undefined ? (
70+ } ) =>
71+ current === undefined ? (
7372 < Skeleton width = { SKELETON_WIDTH } />
7473 ) : (
7574 < span
7675 className = { styles . price }
7776 data-direction = { prev ? getChangeDirection ( prev , current ) : "flat" }
7877 >
79- { numberFormatter . format ( current ) }
78+ < FormattedPriceValue n = { current } />
8079 </ span >
8180 ) ;
82- } ;
8381
8482export const LiveConfidence = ( {
8583 publisherKey,
@@ -119,19 +117,23 @@ const LiveComponentConfidence = ({
119117 return < Confidence confidence = { current ?. latest . confidence } /> ;
120118} ;
121119
122- const Confidence = ( { confidence } : { confidence ?: number | undefined } ) => {
123- const numberFormatter = useNumberFormatter ( { maximumFractionDigits : 5 } ) ;
124-
125- return (
126- < span className = { styles . confidence } >
127- < PlusMinus className = { styles . plusMinus } />
128- { confidence === undefined ? (
129- < Skeleton width = { SKELETON_WIDTH } />
130- ) : (
131- < span > { numberFormatter . format ( confidence ) } </ span >
132- ) }
133- </ span >
134- ) ;
120+ const Confidence = ( { confidence } : { confidence ?: number | undefined } ) => (
121+ < span className = { styles . confidence } >
122+ < PlusMinus className = { styles . plusMinus } />
123+ { confidence === undefined ? (
124+ < Skeleton width = { SKELETON_WIDTH } />
125+ ) : (
126+ < span >
127+ < FormattedPriceValue n = { confidence } />
128+ </ span >
129+ ) }
130+ </ span >
131+ ) ;
132+
133+ const FormattedPriceValue = ( { n } : { n : number } ) => {
134+ const formatter = usePriceFormatter ( ) ;
135+
136+ return useMemo ( ( ) => formatter . format ( n ) , [ n , formatter ] ) ;
135137} ;
136138
137139export const LiveLastUpdated = ( {
0 commit comments