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
1 changed files with 10 additions and 7 deletions

View File

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