Dont display price component until after initial render (#637)

* Dont display price component until after initial render

* change variable name and remove log

* fix linting issues

---------

Co-authored-by: stargut <stargut@starguts-MBP.fios-router.home>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
This commit is contained in:
st4rgut24 2023-11-19 13:01:12 -08:00 committed by GitHub
parent 92ec6be20a
commit d84c46df81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,8 @@ export function PriceProvider ({ price, children }) {
export default function Price ({ className }) { export default function Price ({ className }) {
const [asSats, setAsSats] = useState(undefined) const [asSats, setAsSats] = useState(undefined)
useEffect(() => { useEffect(() => {
setAsSats(window.localStorage.getItem('asSats')) const satSelection = window.localStorage.getItem('asSats')
setAsSats(satSelection ?? 'fiat')
}, []) }, [])
const { price, fiatSymbol } = usePrice() const { price, fiatSymbol } = usePrice()
const { height: blockHeight } = useBlockHeight() const { height: blockHeight } = useBlockHeight()
@ -62,7 +63,7 @@ export default function Price ({ className }) {
setAsSats('blockHeight') setAsSats('blockHeight')
} else if (asSats === 'blockHeight') { } else if (asSats === 'blockHeight') {
window.localStorage.removeItem('asSats') window.localStorage.removeItem('asSats')
setAsSats(undefined) setAsSats('fiat')
} else { } else {
window.localStorage.setItem('asSats', 'yep') window.localStorage.setItem('asSats', 'yep')
setAsSats('yep') setAsSats('yep')
@ -95,9 +96,11 @@ export default function Price ({ className }) {
) )
} }
if (asSats === 'fiat') {
return ( return (
<div className={compClassName} onClick={handleClick} variant='link'> <div className={compClassName} onClick={handleClick} variant='link'>
{fiatSymbol + fixedDecimal(price, 0)} {fiatSymbol + fixedDecimal(price, 0)}
</div> </div>
) )
} }
}