@@ -5,13 +5,14 @@ import type { PriceData, PriceComponent } from "@pythnetwork/client";
5
5
import { Skeleton } from "@pythnetwork/component-library/Skeleton" ;
6
6
import type { ReactNode } from "react" ;
7
7
import { useMemo } from "react" ;
8
- import { useNumberFormatter , useDateFormatter } from "react-aria" ;
8
+ import { useDateFormatter } from "react-aria" ;
9
9
10
10
import styles from "./index.module.scss" ;
11
11
import {
12
12
useLivePriceComponent ,
13
13
useLivePriceData ,
14
14
} from "../../hooks/use-live-price-data" ;
15
+ import { usePriceFormatter } from "../../hooks/use-price-formatter" ;
15
16
import type { Cluster } from "../../services/pyth" ;
16
17
17
18
export const SKELETON_WIDTH = 20 ;
@@ -66,20 +67,17 @@ const Price = ({
66
67
} : {
67
68
prev ?: number | undefined ;
68
69
current ?: number | undefined ;
69
- } ) => {
70
- const numberFormatter = useNumberFormatter ( { maximumFractionDigits : 5 } ) ;
71
-
72
- return current === undefined ? (
70
+ } ) =>
71
+ current === undefined ? (
73
72
< Skeleton width = { SKELETON_WIDTH } />
74
73
) : (
75
74
< span
76
75
className = { styles . price }
77
76
data-direction = { prev ? getChangeDirection ( prev , current ) : "flat" }
78
77
>
79
- { numberFormatter . format ( current ) }
78
+ < FormattedPriceValue n = { current } />
80
79
</ span >
81
80
) ;
82
- } ;
83
81
84
82
export const LiveConfidence = ( {
85
83
publisherKey,
@@ -119,19 +117,23 @@ const LiveComponentConfidence = ({
119
117
return < Confidence confidence = { current ?. latest . confidence } /> ;
120
118
} ;
121
119
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 ] ) ;
135
137
} ;
136
138
137
139
export const LiveLastUpdated = ( {
0 commit comments