@@ -23,19 +23,28 @@ export function LavaAmount({ amount, showDenom = true }: LavaAmountProps) {
2323 const wrapperRef = useRef < HTMLSpanElement > ( null ) ;
2424 const measureRef = useRef < HTMLSpanElement > ( null ) ;
2525 const [ useCompact , setUseCompact ] = useState ( false ) ;
26+ const [ isMobile , setIsMobile ] = useState ( false ) ;
27+
28+ // Always compact on mobile — no measurement needed.
29+ useEffect ( ( ) => {
30+ if ( typeof window === "undefined" ) return ;
31+ const mq = window . matchMedia ( "(max-width: 767px)" ) ;
32+ const update = ( ) => setIsMobile ( mq . matches ) ;
33+ update ( ) ;
34+ mq . addEventListener ( "change" , update ) ;
35+ return ( ) => mq . removeEventListener ( "change" , update ) ;
36+ } , [ ] ) ;
2637
2738 useLayoutEffect ( ( ) => {
39+ if ( isMobile ) return ; // Mobile always uses compact, skip measurement.
2840 const wrapper = wrapperRef . current ;
2941 const measure = measureRef . current ;
3042 if ( ! wrapper || ! measure ) return ;
3143
3244 const check = ( ) => {
3345 const parent = wrapper . parentElement ;
3446 if ( ! parent ) return ;
35- // Available width = parent's content box, minus a small buffer so we
36- // switch to compact a few pixels early (avoids border-clip on edge cases).
3747 const available = parent . clientWidth - 6 ;
38- // Natural width of the full text (measured from a hidden duplicate).
3948 const needed = measure . scrollWidth ;
4049 if ( available > 0 && needed > 0 ) setUseCompact ( needed > available ) ;
4150 } ;
@@ -46,10 +55,11 @@ export function LavaAmount({ amount, showDenom = true }: LavaAmountProps) {
4655 const ro = new ResizeObserver ( check ) ;
4756 ro . observe ( parent ) ;
4857 return ( ) => ro . disconnect ( ) ;
49- } , [ fullText ] ) ;
58+ } , [ fullText , isMobile ] ) ;
5059
5160 // Re-measure on font load (digit widths can shift between fallback and webfont)
5261 useEffect ( ( ) => {
62+ if ( isMobile ) return ;
5363 if ( typeof document === "undefined" || ! document . fonts ) return ;
5464 const handler = ( ) => {
5565 const wrapper = wrapperRef . current ;
@@ -60,7 +70,9 @@ export function LavaAmount({ amount, showDenom = true }: LavaAmountProps) {
6070 setUseCompact ( measure . scrollWidth > parent . clientWidth - 6 ) ;
6171 } ;
6272 document . fonts . ready . then ( handler ) ;
63- } , [ ] ) ;
73+ } , [ isMobile ] ) ;
74+
75+ const useCompactFinal = isMobile || useCompact ;
6476
6577 return (
6678 < >
@@ -69,7 +81,7 @@ export function LavaAmount({ amount, showDenom = true }: LavaAmountProps) {
6981 title = { `${ formatNumber ( raw ) } ulava` }
7082 className = "cursor-help"
7183 >
72- { useCompact ? compactText : fullText }
84+ { useCompactFinal ? compactText : fullText }
7385 </ span >
7486 { /* Off-screen measurement element — has the full text so we can detect overflow without flip-flopping */ }
7587 < span
0 commit comments