2023-09-12 19:50:06 +00:00
|
|
|
import { useState, useRef, useEffect } from 'react'
|
2023-09-12 17:19:26 +00: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 19:50:06 +00:00
|
|
|
useEffect(() => {
|
2023-09-12 17:19:26 +00:00
|
|
|
setWidth(ref.current?.offsetWidth)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
2023-09-12 19:50:06 +00:00
|
|
|
<span
|
|
|
|
ref={ref} style={{ width: fixedWidth ? width : undefined }}
|
2023-09-13 01:21:59 +00:00
|
|
|
className='d-inline-block text-monospace' align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)}
|
2023-09-12 19:50:06 +00:00
|
|
|
>
|
2023-09-18 23:09:08 +00:00
|
|
|
{hover ? (abbreviate ? abbrNum(me.sats) : numWithUnits(me.sats, { abbreviate: false, format: true })) : '******'}
|
2023-09-12 17:19:26 +00:00
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|