2023-09-12 14:50:06 -05:00
|
|
|
import { useState, useRef, useEffect } from 'react'
|
2023-09-12 19:19:26 +02:00
|
|
|
import { abbrNum, numWithUnits } from '../lib/format'
|
|
|
|
import { useMe } from './me'
|
|
|
|
|
|
|
|
export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) {
|
|
|
|
const me = useMe()
|
|
|
|
const [hover, setHover] = useState(false)
|
|
|
|
|
|
|
|
// prevent layout shifts when hovering by fixing width to initial rendered width
|
|
|
|
const ref = useRef()
|
|
|
|
const [width, setWidth] = useState(undefined)
|
2023-09-12 14:50:06 -05:00
|
|
|
useEffect(() => {
|
2023-09-12 19:19:26 +02:00
|
|
|
setWidth(ref.current?.offsetWidth)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
2023-09-12 14:50:06 -05:00
|
|
|
<span
|
|
|
|
ref={ref} style={{ width: fixedWidth ? width : undefined }}
|
2023-09-12 20:21:59 -05:00
|
|
|
className='d-inline-block text-monospace' align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)}
|
2023-09-12 14:50:06 -05:00
|
|
|
>
|
2023-09-18 18:09:08 -05:00
|
|
|
{hover ? (abbreviate ? abbrNum(me.sats) : numWithUnits(me.sats, { abbreviate: false, format: true })) : '******'}
|
2023-09-12 19:19:26 +02:00
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|