Skip to content

Commit 3397a24

Browse files
committed
feat(web): LavaAmount always compact, drop ulava from tooltip
Desktop now renders K/M/B/T the same as mobile (no more adaptive measurement). Title tooltip shows the full LAVA value only; dropped the ulava suffix.
1 parent f9dd6ec commit 3397a24

1 file changed

Lines changed: 10 additions & 79 deletions

File tree

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,27 @@
11
"use client";
22

3-
import { useEffect, useLayoutEffect, useRef, useState } from "react";
4-
import { formatLava, formatLavaKMB, formatNumber } from "@/lib/format";
3+
import { formatLava, formatLavaKMB } from "@/lib/format";
54

65
interface LavaAmountProps {
76
amount: string | bigint | number;
87
showDenom?: boolean;
98
}
109

1110
/**
12-
* Displays a LAVA amount that adapts to its container width.
13-
* Shows the full formatted number when there's room; collapses to
14-
* K/M/B/T shorthand if the full string would overflow the parent.
15-
* Hover (or long-press on touch) reveals the exact ulava value.
11+
* Displays a LAVA amount in compact K/M/B/T form on both mobile and desktop.
12+
* Hover (or long-press) reveals the exact LAVA value.
1613
*/
1714
export function LavaAmount({ amount, showDenom = true }: LavaAmountProps) {
1815
const denom = showDenom ? " LAVA" : "";
19-
const fullText = `${formatLava(amount)}${denom}`;
2016
const compactText = `${formatLavaKMB(amount)}${denom}`;
21-
const raw = String(amount);
22-
23-
const wrapperRef = useRef<HTMLSpanElement>(null);
24-
const measureRef = useRef<HTMLSpanElement>(null);
25-
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-
}, []);
37-
38-
useLayoutEffect(() => {
39-
if (isMobile) return; // Mobile always uses compact, skip measurement.
40-
const wrapper = wrapperRef.current;
41-
const measure = measureRef.current;
42-
if (!wrapper || !measure) return;
43-
44-
const check = () => {
45-
const parent = wrapper.parentElement;
46-
if (!parent) return;
47-
const available = parent.clientWidth - 6;
48-
const needed = measure.scrollWidth;
49-
if (available > 0 && needed > 0) setUseCompact(needed > available);
50-
};
51-
52-
check();
53-
const parent = wrapper.parentElement;
54-
if (!parent) return;
55-
const ro = new ResizeObserver(check);
56-
ro.observe(parent);
57-
return () => ro.disconnect();
58-
}, [fullText, isMobile]);
59-
60-
// Re-measure on font load (digit widths can shift between fallback and webfont)
61-
useEffect(() => {
62-
if (isMobile) return;
63-
if (typeof document === "undefined" || !document.fonts) return;
64-
const handler = () => {
65-
const wrapper = wrapperRef.current;
66-
const measure = measureRef.current;
67-
if (!wrapper || !measure) return;
68-
const parent = wrapper.parentElement;
69-
if (!parent) return;
70-
setUseCompact(measure.scrollWidth > parent.clientWidth - 6);
71-
};
72-
document.fonts.ready.then(handler);
73-
}, [isMobile]);
74-
75-
const useCompactFinal = isMobile || useCompact;
17+
const fullText = `${formatLava(amount)}${denom}`;
7618

7719
return (
78-
<>
79-
<span
80-
ref={wrapperRef}
81-
title={`${formatNumber(raw)} ulava`}
82-
className="cursor-help"
83-
>
84-
{useCompactFinal ? compactText : fullText}
85-
</span>
86-
{/* Off-screen measurement element — has the full text so we can detect overflow without flip-flopping */}
87-
<span
88-
ref={measureRef}
89-
aria-hidden="true"
90-
className="absolute -left-[9999px] top-0 whitespace-nowrap pointer-events-none"
91-
>
92-
{fullText}
93-
</span>
94-
</>
20+
<span
21+
title={fullText}
22+
className="cursor-help"
23+
>
24+
{compactText}
25+
</span>
9526
);
9627
}

0 commit comments

Comments
 (0)